-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First working version of flatten command.
Signed-off-by: Lukasz Soszynski <lukasz.soszynski@eliatra.com>
- Loading branch information
1 parent
9e9fbd3
commit d566d3f
Showing
3 changed files
with
37 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
ppl-spark-integration/src/main/scala/org/opensearch/flint/spark/FlattenGenerator.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.opensearch.flint.spark | ||
|
||
import org.apache.spark.sql.catalyst.analysis.TypeCheckResult | ||
import org.apache.spark.sql.catalyst.expressions.{CollectionGenerator, CreateArray, Expression, GenericInternalRow, Inline, UnaryExpression} | ||
import org.apache.spark.sql.types.{ArrayType, StructType} | ||
|
||
class FlattenGenerator(override val child: Expression) | ||
extends Inline(child) | ||
with CollectionGenerator { | ||
|
||
override def checkInputDataTypes(): TypeCheckResult = child.dataType match { | ||
case st: StructType => TypeCheckResult.TypeCheckSuccess | ||
case _ => super.checkInputDataTypes() | ||
} | ||
|
||
override def elementSchema: StructType = child.dataType match { | ||
case st: StructType => st | ||
case _ => super.elementSchema | ||
} | ||
|
||
override protected def withNewChildInternal(newChild: Expression): FlattenGenerator = { | ||
newChild.dataType match { | ||
case ArrayType(st: StructType, _) => new FlattenGenerator(newChild) | ||
case st: StructType => withNewChildInternal(CreateArray(Seq(newChild), false)) | ||
case _ => | ||
throw new IllegalArgumentException(s"Unexpected input type ${newChild.dataType}") | ||
} | ||
} | ||
} |