Skip to content

Commit d8bb37e

Browse files
cloud-fanyaooqinn
authored andcommitted
[SPARK-47265][SQL][FOLLOWUP] V2SessionCatalog#createTable should not fail
### What changes were proposed in this pull request? This is a followup of #45368 . `DelegatingCatalogExtension` can invoke any method in `V2SessionCatalog`, and we should make sure the two overloads of `createTable` in `V2SessionCatalog` both work. ### Why are the changes needed? Avoid breaking custom catalogs that extend `DelegatingCatalogExtension`. ### Does this PR introduce _any_ user-facing change? no ### How was this patch tested? N/A ### Was this patch authored or co-authored using generative AI tooling? no Closes #47755 from cloud-fan/create-table. Authored-by: Wenchen Fan <[email protected]> Signed-off-by: Kent Yao <[email protected]>
1 parent 89bdc50 commit d8bb37e

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/V2SessionCatalog.scala

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import org.apache.spark.sql.internal.connector.V1Function
3939
import org.apache.spark.sql.types.{DataType, StructType}
4040
import org.apache.spark.sql.util.CaseInsensitiveStringMap
4141
import org.apache.spark.util.ArrayImplicits._
42+
import org.apache.spark.util.Utils
4243

4344
/**
4445
* A [[TableCatalog]] that translates calls to the v1 SessionCatalog.
@@ -158,9 +159,9 @@ class V2SessionCatalog(catalog: SessionCatalog)
158159
catalog.refreshTable(ident.asTableIdentifier)
159160
}
160161

161-
override def createTable(
162+
private def createTable0(
162163
ident: Identifier,
163-
columns: Array[Column],
164+
schema: StructType,
164165
partitions: Array[Transform],
165166
properties: util.Map[String, String]): Table = {
166167
import org.apache.spark.sql.connector.catalog.CatalogV2Implicits._
@@ -178,7 +179,6 @@ class V2SessionCatalog(catalog: SessionCatalog)
178179
CatalogTableType.MANAGED
179180
}
180181

181-
val schema = CatalogV2Util.v2ColumnsToStructType(columns)
182182
val (newSchema, newPartitions) = DataSourceV2Utils.getTableProvider(provider, conf) match {
183183
// If the provider does not support external metadata, users should not be allowed to
184184
// specify custom schema when creating the data source table, since the schema will not
@@ -255,7 +255,18 @@ class V2SessionCatalog(catalog: SessionCatalog)
255255
schema: StructType,
256256
partitions: Array[Transform],
257257
properties: util.Map[String, String]): Table = {
258-
throw QueryCompilationErrors.createTableDeprecatedError()
258+
if (Utils.isTesting) {
259+
throw QueryCompilationErrors.createTableDeprecatedError()
260+
}
261+
createTable0(ident, schema, partitions, properties)
262+
}
263+
264+
override def createTable(
265+
ident: Identifier,
266+
columns: Array[Column],
267+
partitions: Array[Transform],
268+
properties: util.Map[String, String]): Table = {
269+
createTable0(ident, CatalogV2Util.v2ColumnsToStructType(columns), partitions, properties)
259270
}
260271

261272
private def toOptions(properties: Map[String, String]): Map[String, String] = {

0 commit comments

Comments
 (0)