[GitHub] spark pull request #13496: [SPARK-15753][SQL] Move Analyzer stuff to Analyze...
Github user viirya commented on a diff in the pull request: https://github.com/apache/spark/pull/13496#discussion_r66731642 --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala --- @@ -452,6 +452,17 @@ class Analyzer( def apply(plan: LogicalPlan): LogicalPlan = plan resolveOperators { case i @ InsertIntoTable(u: UnresolvedRelation, parts, child, _, _) if child.resolved => +// A partitioned relation's schema can be different from the input logicalPlan, since +// partition columns are all moved after data columns. We Project to adjust the ordering. +val input = if (parts.nonEmpty) { + val (inputPartCols, inputDataCols) = child.output.partition { attr => +parts.contains(attr.name) + } + Project(inputDataCols ++ inputPartCols, child) +} else { + child +} --- End diff -- @cloud-fan ok. I will do it. --- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. --- - To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org
[GitHub] spark pull request #13496: [SPARK-15753][SQL] Move Analyzer stuff to Analyze...
Github user cloud-fan commented on a diff in the pull request: https://github.com/apache/spark/pull/13496#discussion_r66730126 --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala --- @@ -452,6 +452,17 @@ class Analyzer( def apply(plan: LogicalPlan): LogicalPlan = plan resolveOperators { case i @ InsertIntoTable(u: UnresolvedRelation, parts, child, _, _) if child.resolved => +// A partitioned relation's schema can be different from the input logicalPlan, since +// partition columns are all moved after data columns. We Project to adjust the ordering. +val input = if (parts.nonEmpty) { + val (inputPartCols, inputDataCols) = child.output.partition { attr => +parts.contains(attr.name) + } + Project(inputDataCols ++ inputPartCols, child) +} else { + child +} --- End diff -- @gatorsmile good catch! The reason we have `insertInto` is to have a SQL INSERT INTO version in `DataFrameWriter`. We should use `saveAsTable` if we need by-name resolution. I have reverted this PR, @viirya do you mind open a new PR to also remove this logic in `insertInto` to make it consistent with SQL version? thanks! --- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. --- - To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org
[GitHub] spark pull request #13496: [SPARK-15753][SQL] Move Analyzer stuff to Analyze...
Github user gatorsmile commented on a diff in the pull request: https://github.com/apache/spark/pull/13496#discussion_r66729871 --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala --- @@ -452,6 +452,17 @@ class Analyzer( def apply(plan: LogicalPlan): LogicalPlan = plan resolveOperators { case i @ InsertIntoTable(u: UnresolvedRelation, parts, child, _, _) if child.resolved => +// A partitioned relation's schema can be different from the input logicalPlan, since +// partition columns are all moved after data columns. We Project to adjust the ordering. +val input = if (parts.nonEmpty) { + val (inputPartCols, inputDataCols) = child.output.partition { attr => +parts.contains(attr.name) + } + Project(inputDataCols ++ inputPartCols, child) +} else { + child +} --- End diff -- If we use the name based resolution, we also need to check if the all the input columns have the expected partitioning names; Otherwise, the result will be not predictable. --- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. --- - To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org
[GitHub] spark pull request #13496: [SPARK-15753][SQL] Move Analyzer stuff to Analyze...
Github user viirya commented on a diff in the pull request: https://github.com/apache/spark/pull/13496#discussion_r66729833 --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala --- @@ -452,6 +452,17 @@ class Analyzer( def apply(plan: LogicalPlan): LogicalPlan = plan resolveOperators { case i @ InsertIntoTable(u: UnresolvedRelation, parts, child, _, _) if child.resolved => +// A partitioned relation's schema can be different from the input logicalPlan, since +// partition columns are all moved after data columns. We Project to adjust the ordering. +val input = if (parts.nonEmpty) { + val (inputPartCols, inputDataCols) = child.output.partition { attr => +parts.contains(attr.name) + } + Project(inputDataCols ++ inputPartCols, child) +} else { + child +} --- End diff -- Looks like Hive uses ordering not name to take dynamic partition columns. I am not sure if we want to completely follow this Hive behavior. DataFrameWriter's insertInto doesn't follow this. Besides, the rule in Analyzer is not completely follow this too. @liancheng @rxin @cloud-fan What do you think? Do you think we should change current behavior to follow Hive? --- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. --- - To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org
[GitHub] spark pull request #13496: [SPARK-15753][SQL] Move Analyzer stuff to Analyze...
Github user gatorsmile commented on a diff in the pull request: https://github.com/apache/spark/pull/13496#discussion_r66729456 --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala --- @@ -452,6 +452,17 @@ class Analyzer( def apply(plan: LogicalPlan): LogicalPlan = plan resolveOperators { case i @ InsertIntoTable(u: UnresolvedRelation, parts, child, _, _) if child.resolved => +// A partitioned relation's schema can be different from the input logicalPlan, since +// partition columns are all moved after data columns. We Project to adjust the ordering. +val input = if (parts.nonEmpty) { + val (inputPartCols, inputDataCols) = child.output.partition { attr => +parts.contains(attr.name) + } + Project(inputDataCols ++ inputPartCols, child) +} else { + child +} --- End diff -- If the dynamic partitioning columns have multiple columns, the name-based reordering becomes risky. Some partitioning columns might not have names/alias. Right? --- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. --- - To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org
[GitHub] spark pull request #13496: [SPARK-15753][SQL] Move Analyzer stuff to Analyze...
Github user gatorsmile commented on a diff in the pull request: https://github.com/apache/spark/pull/13496#discussion_r66729419 --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala --- @@ -452,6 +452,17 @@ class Analyzer( def apply(plan: LogicalPlan): LogicalPlan = plan resolveOperators { case i @ InsertIntoTable(u: UnresolvedRelation, parts, child, _, _) if child.resolved => +// A partitioned relation's schema can be different from the input logicalPlan, since +// partition columns are all moved after data columns. We Project to adjust the ordering. +val input = if (parts.nonEmpty) { + val (inputPartCols, inputDataCols) = child.output.partition { attr => +parts.contains(attr.name) + } + Project(inputDataCols ++ inputPartCols, child) +} else { + child +} --- End diff -- The names/alias of input columns are not used to determine whether they are the partitioning columns or data columns. --- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. --- - To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org
[GitHub] spark pull request #13496: [SPARK-15753][SQL] Move Analyzer stuff to Analyze...
Github user viirya commented on a diff in the pull request: https://github.com/apache/spark/pull/13496#discussion_r66729375 --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala --- @@ -452,6 +452,17 @@ class Analyzer( def apply(plan: LogicalPlan): LogicalPlan = plan resolveOperators { case i @ InsertIntoTable(u: UnresolvedRelation, parts, child, _, _) if child.resolved => +// A partitioned relation's schema can be different from the input logicalPlan, since +// partition columns are all moved after data columns. We Project to adjust the ordering. +val input = if (parts.nonEmpty) { + val (inputPartCols, inputDataCols) = child.output.partition { attr => +parts.contains(attr.name) + } + Project(inputDataCols ++ inputPartCols, child) +} else { + child +} --- End diff -- @gatorsmile Your example confuses me. As the spec you cited, the dynamic partition columns should be last but you put it in the first? --- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. --- - To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org
[GitHub] spark pull request #13496: [SPARK-15753][SQL] Move Analyzer stuff to Analyze...
Github user gatorsmile commented on a diff in the pull request: https://github.com/apache/spark/pull/13496#discussion_r66725456 --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala --- @@ -452,6 +452,17 @@ class Analyzer( def apply(plan: LogicalPlan): LogicalPlan = plan resolveOperators { case i @ InsertIntoTable(u: UnresolvedRelation, parts, child, _, _) if child.resolved => +// A partitioned relation's schema can be different from the input logicalPlan, since +// partition columns are all moved after data columns. We Project to adjust the ordering. +val input = if (parts.nonEmpty) { + val (inputPartCols, inputDataCols) = child.output.partition { attr => +parts.contains(attr.name) + } + Project(inputDataCols ++ inputPartCols, child) +} else { + child +} --- End diff -- Let me show an example, ```SQL INSERT OVERWRITE TABLE $table partition (p1='a',p2) SELECT 'blarr3' as p2, 'blarr1' ``` Without this change, the output is like ``` +--+---+--+ |c1| p1|p2| +--+---+--+ |blarr3| a|blarr1| +--+---+--+ ``` After this change, the output becomes ``` +--+---+--+ |c1| p1|p2| +--+---+--+ |blarr1| a|blarr3| +--+---+--+ ``` Based on the [Hive specification](https://cwiki.apache.org/confluence/display/Hive/DynamicPartitions), >>In INSERT ... SELECT ... queries, the dynamic partition columns must be specified last among the columns in the SELECT statement and in the same order in which they appear in the PARTITION() clause. Now, the new behavior does not follow the Hive spec. I think we should not do this. --- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. --- - To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org
[GitHub] spark pull request #13496: [SPARK-15753][SQL] Move Analyzer stuff to Analyze...
Github user rxin commented on a diff in the pull request: https://github.com/apache/spark/pull/13496#discussion_r66725290 --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala --- @@ -452,6 +452,17 @@ class Analyzer( def apply(plan: LogicalPlan): LogicalPlan = plan resolveOperators { case i @ InsertIntoTable(u: UnresolvedRelation, parts, child, _, _) if child.resolved => +// A partitioned relation's schema can be different from the input logicalPlan, since +// partition columns are all moved after data columns. We Project to adjust the ordering. +val input = if (parts.nonEmpty) { + val (inputPartCols, inputDataCols) = child.output.partition { attr => +parts.contains(attr.name) + } + Project(inputDataCols ++ inputPartCols, child) +} else { + child +} --- End diff -- do you mean we should not do this? --- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. --- - To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org
[GitHub] spark pull request #13496: [SPARK-15753][SQL] Move Analyzer stuff to Analyze...
Github user gatorsmile commented on a diff in the pull request: https://github.com/apache/spark/pull/13496#discussion_r66724862 --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala --- @@ -452,6 +452,17 @@ class Analyzer( def apply(plan: LogicalPlan): LogicalPlan = plan resolveOperators { case i @ InsertIntoTable(u: UnresolvedRelation, parts, child, _, _) if child.resolved => +// A partitioned relation's schema can be different from the input logicalPlan, since +// partition columns are all moved after data columns. We Project to adjust the ordering. +val input = if (parts.nonEmpty) { + val (inputPartCols, inputDataCols) = child.output.partition { attr => +parts.contains(attr.name) + } + Project(inputDataCols ++ inputPartCols, child) +} else { + child +} --- End diff -- After this movement, this will change the output of another code path, i.e., using SQL statements. For example, ```SQL insert overwrite table tab1 partition(p1='a', p2) select 'blarr3' as p2, 'blarr1'; ``` --- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. --- - To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org
[GitHub] spark pull request #13496: [SPARK-15753][SQL] Move Analyzer stuff to Analyze...
Github user asfgit closed the pull request at: https://github.com/apache/spark/pull/13496 --- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. --- - To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org
[GitHub] spark pull request #13496: [SPARK-15753][SQL] Move Analyzer stuff to Analyze...
Github user viirya commented on a diff in the pull request: https://github.com/apache/spark/pull/13496#discussion_r66354281 --- Diff: sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveQuerySuite.scala --- @@ -1042,7 +1042,7 @@ class HiveQuerySuite extends HiveComparisonTest with BeforeAndAfter { .queryExecution.analyzed } -assertResult(1, "Duplicated project detected\n" + analyzedPlan) { +assertResult(2, "Duplicated project detected\n" + analyzedPlan) { --- End diff -- I tried. The optimized plan has zero projection. Which one you prefer? --- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. --- - To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org
[GitHub] spark pull request #13496: [SPARK-15753][SQL] Move Analyzer stuff to Analyze...
Github user cloud-fan commented on a diff in the pull request: https://github.com/apache/spark/pull/13496#discussion_r66345073 --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala --- @@ -452,6 +452,17 @@ class Analyzer( def apply(plan: LogicalPlan): LogicalPlan = plan resolveOperators { case i @ InsertIntoTable(u: UnresolvedRelation, parts, child, _, _) if child.resolved => +// A partitioned relation's schema can be different from the input logicalPlan, since +// partition columns are all moved after data columns. We Project to adjust the ordering. +val inputWhenPartsNonEmpty = if (parts.nonEmpty) { --- End diff -- maybe just `input`? The else branch doesn't return a `inputWhenPartsNonEmpty` --- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. --- - To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org
[GitHub] spark pull request #13496: [SPARK-15753][SQL] Move Analyzer stuff to Analyze...
Github user cloud-fan commented on a diff in the pull request: https://github.com/apache/spark/pull/13496#discussion_r66344535 --- Diff: sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveQuerySuite.scala --- @@ -1042,7 +1042,7 @@ class HiveQuerySuite extends HiveComparisonTest with BeforeAndAfter { .queryExecution.analyzed } -assertResult(1, "Duplicated project detected\n" + analyzedPlan) { +assertResult(2, "Duplicated project detected\n" + analyzedPlan) { --- End diff -- can we test optimized plan here? --- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. --- - To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org
[GitHub] spark pull request #13496: [SPARK-15753][SQL] Move Analyzer stuff to Analyze...
Github user viirya commented on a diff in the pull request: https://github.com/apache/spark/pull/13496#discussion_r66261309 --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala --- @@ -452,6 +452,21 @@ class Analyzer( def apply(plan: LogicalPlan): LogicalPlan = plan resolveOperators { case i @ InsertIntoTable(u: UnresolvedRelation, parts, child, _, _) if child.resolved => +// A partitioned relation's schema can be different from the input logicalPlan, since +// partition columns are all moved after data columns. We Project to adjust the ordering. +val inputWhenPartsNonEmpty = if (parts.nonEmpty) { + val (inputPartCols, inputDataCols) = child.output.partition { attr => +parts.contains(attr.name) + } + if (child.output == (inputDataCols ++ inputPartCols)) { +child + } else { +Project(inputDataCols ++ inputPartCols, child) --- End diff -- Yea, I see. I did this before but two tests in `HiveQuerySuite` will be failed due to this because it tests against the analyzed logical plan... If we always do project here, we may need to modify `HiveQuerySuite`. Let me do this and then you see if it works for you. Thanks! --- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. --- - To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org
[GitHub] spark pull request #13496: [SPARK-15753][SQL] Move Analyzer stuff to Analyze...
Github user cloud-fan commented on a diff in the pull request: https://github.com/apache/spark/pull/13496#discussion_r66198253 --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala --- @@ -452,6 +452,21 @@ class Analyzer( def apply(plan: LogicalPlan): LogicalPlan = plan resolveOperators { case i @ InsertIntoTable(u: UnresolvedRelation, parts, child, _, _) if child.resolved => +// A partitioned relation's schema can be different from the input logicalPlan, since +// partition columns are all moved after data columns. We Project to adjust the ordering. +val inputWhenPartsNonEmpty = if (parts.nonEmpty) { + val (inputPartCols, inputDataCols) = child.output.partition { attr => +parts.contains(attr.name) + } + if (child.output == (inputDataCols ++ inputPartCols)) { +child + } else { +Project(inputDataCols ++ inputPartCols, child) --- End diff -- We can always do project, and let optimizer eliminate it for us. --- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. --- - To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org
[GitHub] spark pull request #13496: [SPARK-15753][SQL] Move Analyzer stuff to Analyze...
GitHub user viirya opened a pull request: https://github.com/apache/spark/pull/13496 [SPARK-15753][SQL] Move Analyzer stuff to Analyzer from DataFrameWriter ## What changes were proposed in this pull request? This patch moves some codes in `DataFrameWriter.insertInto` that belongs to `Analyzer`. ## How was this patch tested? Existing tests. You can merge this pull request into a Git repository by running: $ git pull https://github.com/viirya/spark-1 move-analyzer-stuff Alternatively you can review and apply these changes as the patch at: https://github.com/apache/spark/pull/13496.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #13496 commit 83b2e6e066611b972e1dddb0b3eb1ae3f8389753 Author: Liang-Chi HsiehDate: 2016-06-03T08:20:44Z Move Analyzer stuff to Analyzer from DataFrameWriter. --- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. --- - To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org