Skip to content
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

[Spark] Resolves #1679 issue glue catalog #2310

Open
wants to merge 2 commits into
base: branch-2.3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,9 @@ case class CreateDeltaTableCommand(
ignoreIfExists = false,
validateLocation = false)
}
if (conf.getConf(DeltaSQLConf.DELTA_SAVE_SCHEMA_GLUE_CATALOG_ENABLED)) {
spark.sessionState.catalog.alterTableDataSchema(cleaned.identifier, cleaned.schema)
}
}

/** Clean up the information we pass on to store in the catalog. */
Expand All @@ -421,8 +424,14 @@ case class CreateDeltaTableCommand(
table.storage.copy(properties = Map.empty)
}

val newSchema = if (conf.getConf(DeltaSQLConf.DELTA_SAVE_SCHEMA_GLUE_CATALOG_ENABLED)) {
table.schema.copy()
} else {
new StructType()
}

table.copy(
schema = new StructType(),
schema = newSchema,
properties = Map.empty,
partitionColumnNames = Nil,
// Remove write specific options when updating the catalog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,18 @@ trait DeltaSQLConfBase {
|Only change this for testing!""".stripMargin)
.booleanConf
.createWithDefault(true)

val DELTA_SAVE_SCHEMA_GLUE_CATALOG_ENABLED =
buildConf("fixSchema.GlueCatalog")
.internal()
.doc(
"""
| This conf fix the schema in tableCatalog object and force an alter table
| schema command after upload the schema. As in spark project the schema is removed
| because delta is not a valid serDe configuration.
|""".stripMargin)
.booleanConf
.createWithDefault(false)
}

object DeltaSQLConf extends DeltaSQLConfBase
37 changes: 37 additions & 0 deletions core/src/test/scala/io/delta/tables/DeltaTableBuilderSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -456,4 +456,41 @@ class DeltaTableBuilderSuite extends QueryTest with SharedSparkSession with Delt
}
}

test("Test schema external table delta glue catalog conf activated") {
withSQLConf(DeltaSQLConf.DELTA_SAVE_SCHEMA_GLUE_CATALOG_ENABLED.key -> "true") {
withTable("deltaTable") {
withTempDir { dir =>
spark.range(10).toDF("key").write.format("delta")
.option("mergeSchema", true)
.mode("overwrite")
.save(dir.getAbsolutePath)
val existingSchema = spark.read.format("delta").load(dir.getAbsolutePath).schema
verifyTestTableMetadata(s"delta.`${dir.getAbsolutePath}`",
"key bigint", colNullables = Set("key"))
}
}
}
}

test("Test schema delta glue catalog conf activated") {
withSQLConf(DeltaSQLConf.DELTA_SAVE_SCHEMA_GLUE_CATALOG_ENABLED.key -> "true") {
withTable("table2") {
withTempDir { dir =>
spark.range(10).toDF("key").write.format("delta")
.mode("overwrite")
.saveAsTable("tableA")
val existingSchema = spark.read.format("delta")
.table("tableA").schema
io.delta.tables.DeltaTable.create()
.tableName("tableB")
.location(dir.getAbsolutePath)
.addColumns(existingSchema)
.addColumn("value", "string", false)
.execute()
verifyTestTableMetadata(s"delta.`${dir.getAbsolutePath}`",
"key bigint, value string", colNullables = Set("key"))
}
}
}
}
}