-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-28238][SQL] Implement DESCRIBE TABLE for Data Source V2 Tables. #25040
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
Changes from all commits
d998c96
596832b
bdae301
527cbc3
6e5f0ea
eb5c843
25ea40b
4d32701
a947006
da202b1
c396d32
ee31d8a
18d688f
cf51488
2b77c80
f701daa
9e04c6e
d0a4533
cff78a1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /* | ||
| * 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.catalyst.plans | ||
|
|
||
| import org.apache.spark.sql.catalyst.expressions.AttributeReference | ||
| import org.apache.spark.sql.types.{MetadataBuilder, StringType, StructField, StructType} | ||
|
|
||
| private[sql] object DescribeTableSchema { | ||
| def describeTableAttributes(): Seq[AttributeReference] = Seq( | ||
| AttributeReference("col_name", StringType, nullable = false, | ||
| new MetadataBuilder().putString("comment", "name of the column").build())(), | ||
| AttributeReference("data_type", StringType, nullable = false, | ||
| new MetadataBuilder().putString("comment", "data type of the column").build())(), | ||
| AttributeReference("comment", StringType, nullable = true, | ||
| new MetadataBuilder().putString("comment", "comment of the column").build())()) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /* | ||
| * 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.catalyst.plans.logical.sql | ||
|
|
||
| import org.apache.spark.sql.catalyst.expressions.{Attribute, AttributeReference} | ||
| import org.apache.spark.sql.types.{MetadataBuilder, StringType} | ||
|
|
||
| case class DescribeColumnStatement( | ||
| tableName: Seq[String], | ||
| colNameParts: Seq[String], | ||
| isExtended: Boolean) extends ParsedStatement { | ||
| override def output: Seq[Attribute] = { | ||
| Seq( | ||
| AttributeReference("info_name", StringType, nullable = false, | ||
| new MetadataBuilder().putString("comment", "name of the column info").build())(), | ||
| AttributeReference("info_value", StringType, nullable = false, | ||
| new MetadataBuilder().putString("comment", "value of the column info").build())() | ||
| ) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /* | ||
| * 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.catalyst.plans.logical.sql | ||
|
|
||
| import org.apache.spark.sql.catalyst.catalog.CatalogTypes.TablePartitionSpec | ||
| import org.apache.spark.sql.catalyst.expressions.Attribute | ||
| import org.apache.spark.sql.catalyst.plans.DescribeTableSchema | ||
|
|
||
| case class DescribeTableStatement( | ||
| tableName: Seq[String], | ||
| partitionSpec: TablePartitionSpec, | ||
| isExtended: Boolean) extends ParsedStatement { | ||
| override def output: Seq[Attribute] = DescribeTableSchema.describeTableAttributes() | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,7 +24,7 @@ import org.apache.spark.sql.catalog.v2.expressions.{ApplyTransform, BucketTransf | |
| import org.apache.spark.sql.catalyst.analysis.{AnalysisTest, UnresolvedRelation, UnresolvedStar} | ||
| import org.apache.spark.sql.catalyst.catalog.BucketSpec | ||
| import org.apache.spark.sql.catalyst.plans.logical.{LogicalPlan, Project} | ||
| import org.apache.spark.sql.catalyst.plans.logical.sql.{AlterTableAddColumnsStatement, AlterTableAlterColumnStatement, AlterTableDropColumnsStatement, AlterTableRenameColumnStatement, AlterTableSetLocationStatement, AlterTableSetPropertiesStatement, AlterTableUnsetPropertiesStatement, AlterViewSetPropertiesStatement, AlterViewUnsetPropertiesStatement, CreateTableAsSelectStatement, CreateTableStatement, DropTableStatement, DropViewStatement, InsertIntoStatement, QualifiedColType, ReplaceTableAsSelectStatement, ReplaceTableStatement} | ||
| import org.apache.spark.sql.catalyst.plans.logical.sql.{AlterTableAddColumnsStatement, AlterTableAlterColumnStatement, AlterTableDropColumnsStatement, AlterTableRenameColumnStatement, AlterTableSetLocationStatement, AlterTableSetPropertiesStatement, AlterTableUnsetPropertiesStatement, AlterViewSetPropertiesStatement, AlterViewUnsetPropertiesStatement, CreateTableAsSelectStatement, CreateTableStatement, DescribeColumnStatement, DescribeTableStatement, DropTableStatement, DropViewStatement, InsertIntoStatement, QualifiedColType, ReplaceTableAsSelectStatement, ReplaceTableStatement} | ||
|
Contributor
Author
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. These are getting really really long, and in particular the merge conflicts are a bit tedious to resolve. I'm normally very averse to wildcard imports, but there might come a point where we'll have to do that. Or I wonder if we could have a helper
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. +1 for wildcard here.
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. This package may make sense for a wildcard import because it has no sub-packages and is unlikely to in the future. Still, because Scala will import sub-packages, I think it's probably best to keep avoiding wildcard imports, even here. |
||
| import org.apache.spark.sql.types.{IntegerType, LongType, StringType, StructType, TimestampType} | ||
| import org.apache.spark.unsafe.types.UTF8String | ||
|
|
||
|
|
@@ -617,6 +617,47 @@ class DDLParserSuite extends AnalysisTest { | |
| } | ||
| } | ||
|
|
||
| test("describe table column") { | ||
| comparePlans(parsePlan("DESCRIBE t col"), | ||
| DescribeColumnStatement( | ||
| Seq("t"), Seq("col"), isExtended = false)) | ||
| comparePlans(parsePlan("DESCRIBE t `abc.xyz`"), | ||
| DescribeColumnStatement( | ||
| Seq("t"), Seq("abc.xyz"), isExtended = false)) | ||
| comparePlans(parsePlan("DESCRIBE t abc.xyz"), | ||
| DescribeColumnStatement( | ||
| Seq("t"), Seq("abc", "xyz"), isExtended = false)) | ||
| comparePlans(parsePlan("DESCRIBE t `a.b`.`x.y`"), | ||
| DescribeColumnStatement( | ||
| Seq("t"), Seq("a.b", "x.y"), isExtended = false)) | ||
|
|
||
| comparePlans(parsePlan("DESCRIBE TABLE t col"), | ||
| DescribeColumnStatement( | ||
| Seq("t"), Seq("col"), isExtended = false)) | ||
| comparePlans(parsePlan("DESCRIBE TABLE EXTENDED t col"), | ||
| DescribeColumnStatement( | ||
| Seq("t"), Seq("col"), isExtended = true)) | ||
| comparePlans(parsePlan("DESCRIBE TABLE FORMATTED t col"), | ||
| DescribeColumnStatement( | ||
| Seq("t"), Seq("col"), isExtended = true)) | ||
|
|
||
| val caught = intercept[AnalysisException]( | ||
| parsePlan("DESCRIBE TABLE t PARTITION (ds='1970-01-01') col")) | ||
| assert(caught.getMessage.contains( | ||
| "DESC TABLE COLUMN for a specific partition is not supported")) | ||
| } | ||
|
|
||
| test("SPARK-17328 Fix NPE with EXPLAIN DESCRIBE TABLE") { | ||
| comparePlans(parsePlan("describe t"), | ||
| DescribeTableStatement(Seq("t"), Map.empty, isExtended = false)) | ||
| comparePlans(parsePlan("describe table t"), | ||
| DescribeTableStatement(Seq("t"), Map.empty, isExtended = false)) | ||
| comparePlans(parsePlan("describe table extended t"), | ||
| DescribeTableStatement(Seq("t"), Map.empty, isExtended = true)) | ||
| comparePlans(parsePlan("describe table formatted t"), | ||
| DescribeTableStatement(Seq("t"), Map.empty, isExtended = true)) | ||
| } | ||
|
|
||
| test("insert table: basic append") { | ||
| Seq( | ||
| "INSERT INTO TABLE testcat.ns1.ns2.tbl SELECT * FROM source", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -327,38 +327,6 @@ class SparkSqlAstBuilder(conf: SQLConf) extends AstBuilder(conf) { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Create a [[DescribeColumnCommand]] or [[DescribeTableCommand]] logical commands. | ||
| */ | ||
| override def visitDescribeTable(ctx: DescribeTableContext): LogicalPlan = withOrigin(ctx) { | ||
| val isExtended = ctx.EXTENDED != null || ctx.FORMATTED != null | ||
| if (ctx.describeColName != null) { | ||
| if (ctx.partitionSpec != null) { | ||
| throw new ParseException("DESC TABLE COLUMN for a specific partition is not supported", ctx) | ||
| } else { | ||
| DescribeColumnCommand( | ||
| visitTableIdentifier(ctx.tableIdentifier), | ||
|
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. Now that these rules create
Contributor
Author
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. Do you mean that |
||
| ctx.describeColName.nameParts.asScala.map(_.getText), | ||
| isExtended) | ||
| } | ||
| } else { | ||
| val partitionSpec = if (ctx.partitionSpec != null) { | ||
| // According to the syntax, visitPartitionSpec returns `Map[String, Option[String]]`. | ||
| visitPartitionSpec(ctx.partitionSpec).map { | ||
| case (key, Some(value)) => key -> value | ||
| case (key, _) => | ||
| throw new ParseException(s"PARTITION specification is incomplete: `$key`", ctx) | ||
| } | ||
| } else { | ||
| Map.empty[String, String] | ||
| } | ||
| DescribeTableCommand( | ||
| visitTableIdentifier(ctx.tableIdentifier), | ||
| partitionSpec, | ||
| isExtended) | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Create a [[DescribeQueryCommand]] logical command. | ||
| */ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.