-
Notifications
You must be signed in to change notification settings - Fork 29k
[WIP][SPARK-37888][SQL][TESTS] Unify v1 and v2 DESCRIBE TABLE tests #35265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8501b54
initial commit
imback82 e37232f
more changes
imback82 2c8dd54
Add missing files
imback82 f2244e1
Merge branch 'master' into describe_table_test
imback82 d7bd953
Merge remote-tracking branch 'upstream/master' into describe_table_test
imback82 2a874b5
more changes
imback82 18dffcd
Merge remote-tracking branch 'upstream/master' into describe_table_test
imback82 632b763
WIP: evaluating the differences
imback82 6241b03
Merge remote-tracking branch 'upstream/master' into describe_table_test
imback82 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -574,7 +574,7 @@ abstract class DescribeCommandBase extends LeafRunnableCommand { | |
| if (header) { | ||
| append(buffer, s"# ${output.head.name}", output(1).name, output(2).name) | ||
| } | ||
| schema.foreach { column => | ||
| schema.sortBy(_.name).foreach { column => | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm, this is weird. The column order matters and we should retain it. |
||
| append(buffer, column.name, column.dataType.simpleString, column.getComment().orNull) | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ import scala.collection.mutable.ArrayBuffer | |
| import org.apache.spark.sql.catalyst.InternalRow | ||
| import org.apache.spark.sql.catalyst.expressions.Attribute | ||
| import org.apache.spark.sql.connector.catalog.{CatalogV2Util, SupportsMetadataColumns, Table} | ||
| import org.apache.spark.sql.connector.expressions.IdentityTransform | ||
|
|
||
| case class DescribeTableExec( | ||
| output: Seq[Attribute], | ||
|
|
@@ -60,9 +61,9 @@ case class DescribeTableExec( | |
| } | ||
|
|
||
| private def addSchema(rows: ArrayBuffer[InternalRow]): Unit = { | ||
| rows ++= table.schema.map{ column => | ||
| rows ++= table.schema.sortBy(_.name).map { column => | ||
| toCatalystRow( | ||
| column.name, column.dataType.simpleString, column.getComment().getOrElse("")) | ||
| column.name, column.dataType.simpleString, column.getComment().orNull) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -80,13 +81,23 @@ case class DescribeTableExec( | |
| } | ||
|
|
||
| private def addPartitioning(rows: ArrayBuffer[InternalRow]): Unit = { | ||
| rows += emptyRow() | ||
| rows += toCatalystRow("# Partitioning", "", "") | ||
| if (table.partitioning.isEmpty) { | ||
| rows += toCatalystRow("Not partitioned", "", "") | ||
| } else { | ||
| rows ++= table.partitioning.zipWithIndex.map { | ||
| case (transform, index) => toCatalystRow(s"Part $index", transform.describe(), "") | ||
| if (table.partitioning.nonEmpty) { | ||
| val partitionColumnsOnly = table.partitioning.forall(t => t.isInstanceOf[IdentityTransform]) | ||
| if (partitionColumnsOnly) { | ||
| val nameToField = table.schema.map(f => (f.name, f)).toMap | ||
| rows += toCatalystRow("# Partition Information", "", "") | ||
| rows += toCatalystRow(s"# ${output(0).name}", output(1).name, output(2).name) | ||
| rows ++= table.partitioning.sortBy(_.describe).map { | ||
| case t => | ||
| val field = nameToField(t.describe) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should cast v2 partitioning to |
||
| toCatalystRow(t.describe, field.dataType.simpleString, field.getComment().orNull) | ||
| } | ||
| } else { | ||
| rows += emptyRow() | ||
| rows += toCatalystRow("# Partitioning", "", "") | ||
| rows ++= table.partitioning.zipWithIndex.map { | ||
| case (transform, index) => toCatalystRow(s"Part $index", transform.describe(), "") | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or 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
39 changes: 39 additions & 0 deletions
39
...e/src/test/scala/org/apache/spark/sql/execution/command/DescribeRelationParserSuite.scala
This file contains hidden or 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,39 @@ | ||
| /* | ||
| * 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.command | ||
|
|
||
| import org.apache.spark.sql.catalyst.analysis.{AnalysisTest, UnresolvedTableOrView} | ||
| import org.apache.spark.sql.catalyst.parser.CatalystSqlParser.parsePlan | ||
| import org.apache.spark.sql.catalyst.plans.logical.DescribeRelation | ||
|
|
||
| class DescribeRelationParserSuite extends AnalysisTest { | ||
| test("SPARK-17328 Fix NPE with EXPLAIN DESCRIBE TABLE") { | ||
| comparePlans(parsePlan("describe t"), | ||
| DescribeRelation( | ||
| UnresolvedTableOrView(Seq("t"), "DESCRIBE TABLE", true), Map.empty, isExtended = false)) | ||
| comparePlans(parsePlan("describe table t"), | ||
| DescribeRelation( | ||
| UnresolvedTableOrView(Seq("t"), "DESCRIBE TABLE", true), Map.empty, isExtended = false)) | ||
| comparePlans(parsePlan("describe table extended t"), | ||
| DescribeRelation( | ||
| UnresolvedTableOrView(Seq("t"), "DESCRIBE TABLE", true), Map.empty, isExtended = true)) | ||
| comparePlans(parsePlan("describe table formatted t"), | ||
| DescribeRelation( | ||
| UnresolvedTableOrView(Seq("t"), "DESCRIBE TABLE", true), Map.empty, isExtended = true)) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should still use v1 command for views.