Skip to content
Closed
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 @@ -276,6 +276,7 @@ case class AlterTableSetPropertiesCommand(
properties = table.properties ++ properties,
comment = properties.get(TableCatalog.PROP_COMMENT).orElse(table.comment))
catalog.alterTable(newTable)
catalog.invalidateCachedTable(tableName)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be better to do this inside SessionCatalog.alterTable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you @sunchao . I think it's a code improvement, and if we decide to do that, it should consider more methods include alterTableDataSchema, alterPartition, etc. So for now in this PR, I prefer do the simple fix which is straightforward.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. This looks good to me. I'm just curious whether other alter table variants have the same issue.

Seq.empty[Row]
}

Expand Down Expand Up @@ -312,6 +313,7 @@ case class AlterTableUnsetPropertiesCommand(
val newProperties = table.properties.filter { case (k, _) => !propKeys.contains(k) }
val newTable = table.copy(properties = newProperties, comment = tableComment)
catalog.alterTable(newTable)
catalog.invalidateCachedTable(tableName)
Seq.empty[Row]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,28 @@ class HiveParquetSuite extends QueryTest with ParquetTest with TestHiveSingleton
.plus(123456, ChronoUnit.MICROS)))
}
}

test("SPARK-37098: Alter table properties should invalidate cache") {
// specify the compression in case we change it in future
withSQLConf(SQLConf.PARQUET_COMPRESSION.key -> "snappy") {
withTempPath { dir =>
withTable("t") {
sql(s"CREATE TABLE t (c int) STORED AS PARQUET LOCATION '${dir.getCanonicalPath}'")
// cache table metadata
sql("SELECT * FROM t")
sql("ALTER TABLE t SET TBLPROPERTIES('parquet.compression'='zstd')")
sql("INSERT INTO TABLE t values(1)")
val files1 = dir.listFiles().filter(_.getName.endsWith("zstd.parquet"))
assert(files1.length == 1)

// cache table metadata again
sql("SELECT * FROM t")
sql("ALTER TABLE t UNSET TBLPROPERTIES('parquet.compression')")
sql("INSERT INTO TABLE t values(1)")
val files2 = dir.listFiles().filter(_.getName.endsWith("snappy.parquet"))
assert(files2.length == 1)
}
}
}
}
}