File tree Expand file tree Collapse file tree 2 files changed +28
-10
lines changed
main/scala/org/apache/spark/sql/execution/command
test/scala/org/apache/spark/sql Expand file tree Collapse file tree 2 files changed +28
-10
lines changed Original file line number Diff line number Diff line change @@ -42,16 +42,14 @@ object CommandUtils extends Logging {
42
42
43
43
/** Change statistics after changing data by commands. */
44
44
def updateTableStats (sparkSession : SparkSession , table : CatalogTable ): Unit = {
45
- if (table.stats.nonEmpty) {
46
- val catalog = sparkSession.sessionState.catalog
47
- if (sparkSession.sessionState.conf.autoSizeUpdateEnabled) {
48
- val newTable = catalog.getTableMetadata(table.identifier)
49
- val newSize = CommandUtils .calculateTotalSize(sparkSession, newTable)
50
- val newStats = CatalogStatistics (sizeInBytes = newSize)
51
- catalog.alterTableStats(table.identifier, Some (newStats))
52
- } else {
53
- catalog.alterTableStats(table.identifier, None )
54
- }
45
+ val catalog = sparkSession.sessionState.catalog
46
+ if (sparkSession.sessionState.conf.autoSizeUpdateEnabled) {
47
+ val newTable = catalog.getTableMetadata(table.identifier)
48
+ val newSize = CommandUtils .calculateTotalSize(sparkSession, newTable)
49
+ val newStats = CatalogStatistics (sizeInBytes = newSize)
50
+ catalog.alterTableStats(table.identifier, Some (newStats))
51
+ } else if (table.stats.nonEmpty) {
52
+ catalog.alterTableStats(table.identifier, None )
55
53
}
56
54
}
57
55
Original file line number Diff line number Diff line change @@ -337,6 +337,26 @@ class StatisticsCollectionSuite extends StatisticsCollectionTestBase with Shared
337
337
}
338
338
}
339
339
340
+ test(" auto gather stats after insert command" ) {
341
+ val table = " change_stats_insert_datasource_table"
342
+ Seq (false , true ).foreach { autoUpdate =>
343
+ withSQLConf(SQLConf .AUTO_SIZE_UPDATE_ENABLED .key -> autoUpdate.toString) {
344
+ withTable(table) {
345
+ sql(s " CREATE TABLE $table (i int, j string) USING PARQUET " )
346
+ // insert into command
347
+ sql(s " INSERT INTO TABLE $table SELECT 1, 'abc' " )
348
+ val stats = getCatalogTable(table).stats
349
+ if (autoUpdate) {
350
+ assert(stats.isDefined)
351
+ assert(stats.get.sizeInBytes >= 0 )
352
+ } else {
353
+ assert(stats.isEmpty)
354
+ }
355
+ }
356
+ }
357
+ }
358
+ }
359
+
340
360
test(" invalidation of tableRelationCache after inserts" ) {
341
361
val table = " invalidate_catalog_cache_table"
342
362
Seq (false , true ).foreach { autoUpdate =>
You can’t perform that action at this time.
0 commit comments