Uh oh!
There was an error while loading. Please reload this page.
[SPARK-32002][SQL]Support ExtractValue from nested ArrayStruct - #28860
[SPARK-32002][SQL]Support ExtractValue from nested ArrayStruct#28860AngersZhuuuu wants to merge 5 commits into
Conversation
SparkQA
commented
Jun 18, 2020
Test build #124217 has finished for PR 28860 at commit
|
SparkQA
commented
Jun 18, 2020
Test build #124220 has finished for PR 28860 at commit
|
SparkQA
commented
Jun 19, 2020
Test build #124252 has finished for PR 28860 at commit
|
AngersZhuuuu
commented
Jun 19, 2020
retest this please |
SparkQA
commented
Jun 19, 2020
Test build #124268 has finished for PR 28860 at commit
|
Uh oh!
There was an error while loading. Please reload this page.
gatorsmile
commented
Jun 20, 2020
AngersZhuuuu
commented
Jun 20, 2020
Seems this way will change the schema, maybe we should add a new class to get multidimensional array form GetArrayStruct |
Co-authored-by: Ruslan Dautkhanov <Tagar@users.noreply.github.com>
SparkQA
commented
Jun 20, 2020
Test build #124314 has finished for PR 28860 at commit
|
HyukjinKwon
commented
Jun 26, 2020
retest this please |
HyukjinKwon
commented
Jun 26, 2020
cc @viirya too FYI |
| ordinal, fields.length, containsNull) | ||
| case (ExtractNestedArray(StructType(fields), containsNull, containsNullSeq), | ||
| NonNullLiteral(v, StringType)) => |
There was a problem hiding this comment.
nit:
case (ExtractNestedArray(
StructType(fields), containsNull, containsNullSeq), NonNullLiteral(v, StringType)) =>
There was a problem hiding this comment.
Let's also update the documentation and table above.
| trait ExtractValue extends Expression | ||
| object ExtractNestedArray { |
| object ExtractNestedArray { | ||
| type ReturnType = Option[(DataType, Boolean, Seq[Boolean])] |
There was a problem hiding this comment.
Let's also add some comments for what this type means.
| def extractArrayStruct(expr: Expression): ReturnType = { | ||
| expr match { | ||
| case gas @ GetArrayStructFields(child, _, _, _, _) => |
There was a problem hiding this comment.
Let's avoid arguments matching. This is actually an anti pattern - https://github.com/databricks/scala-style-guide#pattern-matching
| expr match { | ||
| case gas @ GetArrayStructFields(child, _, _, _, _) => | ||
| extractArrayStruct(child) match { | ||
| case Some((e, deep)) => Some(e, deep + 1) |
| extractArrayType(dataType) | ||
| } | ||
| def extractArrayType(dataType: DataType): ReturnType = { |
There was a problem hiding this comment.
Can we combine this and unapply?
| checkAnswer(sql( | ||
| """ | ||
| |SELECT a.b.c FROM nest |
There was a problem hiding this comment.
Can we add deeper cases? Also, you can simplify the test cases, for example, as below:
valdf= spark.range(10).select(array(struct(array(struct("id")).alias("col1"))).alias("col0"))
df.selectExpr("col0.col1.id")| trait ExtractValue extends Expression | ||
| object ExtractNestedArray { |
There was a problem hiding this comment.
Let's also name it something like ExtractNestedArrayType
SparkQA
commented
Jun 26, 2020
Test build #124544 has finished for PR 28860 at commit
|
guiyanakuang
commented
Jul 3, 2020
org.apache.spark.sql.execution.ProjectionOverSchema.scala. A Scala extractor that projects an expression over a given schema. I think this code also needs to have matching rules added to it. To support nested ArrayStruct. Otherwise, ParquetSchemaPruning won't work either. |
AngersZhuuuu
commented
Jul 4, 2020
Yea, right, current way change the schema and won't work well for all case, I am thinking about add a new class to handle nested ArrayStruct type |
We're closing this PR because it hasn't been updated in a while. This isn't a judgement on the merit of the PR in any way. It's just a way of keeping the PR queue manageable. |
What changes were proposed in this pull request?
For data
nest.json{"a": [{"b": [{"c": [1,2]}]}]} {"a": [{"b": [{"c": [1]}, {"c": [2]}]}]}run with
will got error
This is because after resolve
a.b, it constructGetArrayStructFieldfroma#result with type
ArrayType(ArrayType(StructType)), then it can't be extract through currentExtractValuemethod.Support extract
StructFieldform nested Array-Struct combinationWhy are the changes needed?
Support more use case
Does this PR introduce any user-facing change?
Yes, users will be able to select from nested array and structs.
How was this patch tested?
Added UT