Uh oh!
There was an error while loading. Please reload this page.
[SPARK-8407][SQL]complex type constructors: struct and named_struct - #6874
[SPARK-8407][SQL]complex type constructors: struct and named_struct#6874yjshen wants to merge 16 commits into
Conversation
yjshen
commented
Jun 18, 2015
It's ready to be reviewed now. |
There was a problem hiding this comment.
We'd better remove this, as it's covered by its parent class.
yjshen
commented
Jun 19, 2015
@chenghao-intel, I've fixed |
yjshen
commented
Jun 19, 2015
I find it hard to make a column names version of API: defnamedStruct(fieldName: String, col: String, fieldAndCols: String*):Column=???It would limit creation of Literal fields. However, when we change the API to this one: defnamedStruct(fieldName: String, col: Any, fieldAndCols: Any*):Column=???When we have String in even positions, it's impossible to tell if the user want to create a String Literal or refer to a col |
chenghao-intel
commented
Jun 19, 2015
The Dataframe API does not like the normal function, the string arguments actually represent the associated columns, not the value it's represented. @rxin I think that's a common problem if we want to passed a string literal for DataFrame functions, do you have any suggestion for that? |
rxin
commented
Jun 19, 2015
we can document that string literals should be set using lit("...") |
yjshen
commented
Jun 19, 2015
@rxin, what do you think of the column names version API? |
rxin
commented
Jun 19, 2015
I don't think we need named_struct in DataFrame, since struct itself is powerful enough already. Just have it for SQL. |
yjshen
commented
Jun 19, 2015
OK, I would remove it from DataFrame. |
There was a problem hiding this comment.
shouldn't use assert here
assert is for internal errors. maybe it's best to use checkInputTypes to do this: https://github.com/apache/spark/blob/master/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala#L169
There was a problem hiding this comment.
yes, please use checkInputTypes here to check children.size % 2 == 0 and all name expressions are non-null literal string.
rxin
commented
Jun 19, 2015
@cloud-fan can you help review this one? |
There was a problem hiding this comment.
what about
privateval (nameExprs, valExprs) = children.sliding(2, 2).collect { caseSeq(a, b) => a -> b }.toList.unzipor
privateval (nameExprs, valExprs) = children.zipWithIndex.partition(_._2 %2==0).map(_.map(_._1))yjshen
commented
Jun 19, 2015
Close by mistake. |
yjshen
commented
Jun 19, 2015
@rxin@cloud-fan , thanks for the detailed reviews. |
There was a problem hiding this comment.
Move the require out of the eval, a better place probably within the def checkInputDataTypes
There was a problem hiding this comment.
In complexTypeSuite, when I call CreateNamedStruct directly in checkEvaluation, checkInputType are not executed, so I call resolved here to utilize its default implementation to do checkInputType.
There was a problem hiding this comment.
A better way to enforce the check?
There was a problem hiding this comment.
checkEvaluation just evaluate the expression, not go through the whole analyze process. So you can write normal test at complexTypeSuite and write error test at ExpressionTypeCheckingSuite.
yjshen
commented
Jun 20, 2015
@cloud-fan@chenghao-intel, thanks for reviewing this. I've moved the incorrect input test into |
yjshen
commented
Jun 23, 2015
Jenkins, retest this please |
yjshen
commented
Jun 23, 2015
@rxin, could you please review this and also trigger the test? |
rxin
commented
Jun 23, 2015
Jenkins, ok to test. |
SparkQA
commented
Jun 23, 2015
Test build #35569 has finished for PR 6874 at commit
|
There was a problem hiding this comment.
The query is:
createQueryTest("constant object inspector for generic udf",
"""SELECT named_struct( lower("AA"), "10", repeat(lower("AA"), 3), "11", lower(repeat("AA", 3)), "12", printf("Bb%d", 12), "13", repeat(printf("s%d", 14), 2), "14") FROM src LIMIT 1""")Since printf in Hive didn't change word case in Bb%d, therefore, Bb12 is the right answer
There was a problem hiding this comment.
We shouldn't change machine generated golden answers though. If we are going to differ from hive use checkAnswer instead.
SparkQA
commented
Jun 24, 2015
Test build #35672 has finished for PR 6874 at commit
|
There was a problem hiding this comment.
use checkAnswer instead of assert, it gives better error messages when there is a failure.
yjshen
commented
Jun 26, 2015
@marmbrus , I remove the previous wrong golden answer and generate a new one during test. |
SparkQA
commented
Jun 26, 2015
Test build #35851 has finished for PR 6874 at commit
|
There was a problem hiding this comment.
The documentation above needs to be updated and should specify what happens when the columns are unnamed.
marmbrus
commented
Jun 29, 2015
Do we also need to add this to |
yjshen
commented
Jul 2, 2015
SparkQA
commented
Jul 2, 2015
Test build #36399 has finished for PR 6874 at commit
|
SparkQA
commented
Jul 2, 2015
Test build #36403 has finished for PR 6874 at commit
|
marmbrus
commented
Jul 2, 2015
I agree that struct is enough in scala/python. Thanks! Merging to master. |
This is a follow up of SPARK-8283 (PR-6828), to support both
structandnamed_structin Spark SQL.After #6725, the semantic of
CreateStructmethods have changed a little and do not limited to cols ofNamedExpressions, it will name non-NamedExpression fields following the hive convention, col1, col2 ...This PR would both loosen
structto take children ofExpressiontype and addnamed_structsupport.