Github user chenghao-intel commented on a diff in the pull request:

    https://github.com/apache/spark/pull/1567#discussion_r25317186
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/Expand.scala ---
    @@ -0,0 +1,79 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.sql.execution
    +
    +import org.apache.spark.annotation.DeveloperApi
    +import org.apache.spark.sql.SQLContext
    +import org.apache.spark.sql.catalyst.errors._
    +import org.apache.spark.sql.catalyst.expressions._
    +import org.apache.spark.sql.catalyst.plans.physical.{UnknownPartitioning, 
Partitioning}
    +
    +/**
    + * Apply the all of the GroupExpressions to every input row, hence we will 
get
    + * multiple output rows for a input row.
    + * @param projections The group of expressions, all of the group 
expressions should
    + *                    output the same schema specified bye the parameter 
`output`
    + * @param output      The output Schema
    + * @param child       Child operator
    + */
    +@DeveloperApi
    +case class Expand(
    +    projections: Seq[GroupExpression],
    +    output: Seq[Attribute],
    +    child: SparkPlan)
    +  extends UnaryNode {
    +
    +  // The GroupExpressions can output data with arbitrary partitioning, so 
set it
    +  // as UNKNOWN partitioning
    +  override def outputPartitioning: Partitioning = UnknownPartitioning(0)
    +
    +  override def execute() = attachTree(this, "execute") {
    +    child.execute().mapPartitions { iter =>
    +      // TODO Move out projection objects creation and transfer to
    +      // workers via closure. However we can't assume the Projection
    +      // is serializable because of the code gen, so we have to
    +      // create the projections within each of the partition processing.
    +      val groups = projections.map(ee => newProjection(ee.children, 
child.output)).toArray
    +
    +      new Iterator[Row] {
    +        private[this] var result: Row = _
    +        private[this] var idx = -1  // -1 means the initial state
    +        private[this] var input: Row = _
    +
    +        override final def hasNext = (-1 < idx && idx < groups.length) || 
iter.hasNext
    --- End diff --
    
    @rxin, the `groups` is in the type of `Array`, not `Seq`, probably it does 
not impact the performance a lot. Anyway, thank you for pointing this out, I 
can update that along with some other PR.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to