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 @@ -679,7 +679,8 @@ case class AlterTableSetLocationCommand(
} else {
table.withNewStorage(locationUri = Some(location))
}
catalog.alterTable(newTable)
val newTableWithInvalidatedStats = newTable.copy(stats = None)
catalog.alterTable(newTableWithInvalidatedStats)
}
Seq.empty[Row]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,27 @@ class StatisticsSuite extends QueryTest with TestHiveSingleton with SQLTestUtils
}
}

test("alter table set location after analyze table") {
val textTable = "textTable"
withTable(textTable) {
sql(s"CREATE TABLE $textTable (key STRING, value STRING) STORED AS TEXTFILE")
sql(s"INSERT INTO TABLE $textTable SELECT * FROM src")
sql(s"ANALYZE TABLE $textTable COMPUTE STATISTICS")
checkStats(
textTable, isDataSourceTable = false, hasSizeInBytes = true, expectedRowCounts = Some(500))

withTempDir { tmpDir =>
val path = tmpDir.getCanonicalPath
sql(s"ALTER TABLE $textTable SET LOCATION '$path'")
checkStats(
textTable,
isDataSourceTable = false,
hasSizeInBytes = false,
Copy link
Member Author

Choose a reason for hiding this comment

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

After the PR: #14971, we can reuse the Hive-generated statistics. Thus, this value will be true.

expectedRowCounts = None)
}
}
}

test("test table-level statistics for data source table created in HiveExternalCatalog") {
val parquetTable = "parquetTable"
withTable(parquetTable) {
Expand Down