Skip to content

Commit

Permalink
[SPARK-49078][SQL] Support show columns syntax in v2 table
Browse files Browse the repository at this point in the history
### What changes were proposed in this pull request?

Support v2 table with show columns syntax.

### Why are the changes needed?

In lakehouse format such as Paimon、Iceberg,table are v2 which not support show column syntax,this pr is aimed to support it

### Does this PR introduce _any_ user-facing change?

No

### How was this patch tested?

DataSourceV2SQLSuite

### Was this patch authored or co-authored using generative AI tooling?

no

Closes apache#47568 from xuzifu666/support_show_columns_v2.

Lead-authored-by: xuyu <11161569@vivo.com>
Co-authored-by: Kent Yao <yao@apache.org>
Signed-off-by: Kent Yao <yao@apache.org>
  • Loading branch information
xuyu and yaooqinn committed Aug 5, 2024
1 parent b76f0b9 commit 94f8872
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,8 @@ class DataSourceV2Strategy(session: SparkSession) extends Strategy with Predicat
Seq(part).asResolvedPartitionSpecs.head,
recacheTable(r)) :: Nil

case ShowColumns(_: ResolvedTable, _, _) =>
throw QueryCompilationErrors.showColumnsNotSupportedForV2TablesError()
case ShowColumns(resolvedTable: ResolvedTable, _, output) =>
ShowColumnsExec(output, resolvedTable) :: Nil

case r @ ShowPartitions(
ResolvedTable(catalog, _, table: SupportsPartitionManagement, _),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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.datasources.v2

import org.apache.spark.sql.catalyst.InternalRow
import org.apache.spark.sql.catalyst.analysis.ResolvedTable
import org.apache.spark.sql.catalyst.expressions.Attribute
import org.apache.spark.sql.execution.LeafExecNode

/**
* Physical plan node for show columns from table.
*/
case class ShowColumnsExec(
output: Seq[Attribute],
resolvedTable: ResolvedTable) extends V2CommandExec with LeafExecNode {
override protected def run(): Seq[InternalRow] = {
resolvedTable.table.columns().map(f => toCatalystRow(f.name())).toSeq
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2377,10 +2377,7 @@ class DataSourceV2SQLSuiteV1Filter
val t = "testcat.ns1.ns2.tbl"
withTable(t) {
spark.sql(s"CREATE TABLE $t (id bigint, data string) USING foo")

testNotSupportedV2Command("SHOW COLUMNS", s"FROM $t")
testNotSupportedV2Command("SHOW COLUMNS", s"IN $t")
testNotSupportedV2Command("SHOW COLUMNS", "FROM tbl IN testcat.ns1.ns2")
checkAnswer(sql(s"SHOW COLUMNS FROM $t"), Seq(Row("id"), Row("data")))
}
}

Expand Down Expand Up @@ -2497,7 +2494,6 @@ class DataSourceV2SQLSuiteV1Filter
verify(s"CACHE TABLE $t")
verify(s"UNCACHE TABLE $t")
verify(s"TRUNCATE TABLE $t")
verify(s"SHOW COLUMNS FROM $t")
}
}

Expand Down

0 comments on commit 94f8872

Please sign in to comment.