MaxGekk opened a new pull request #31350:
URL: https://github.com/apache/spark/pull/31350


   ### What changes were proposed in this pull request?
   1. Take into account the SQL config 
`spark.sql.statistics.size.autoUpdate.enabled` as other commands do.
   2. Re-calculate actual table size in fs. Before the changes, `TRUNCATE 
TABLE` always sets table size to 0 in stats.
   
   ### Why are the changes needed?
   This fixes the bug that demonstrated by the example:
   1. Create a partitioned table with 2 non-empty partitions:
   ```sql
   spark-sql> CREATE TABLE tbl (c0 int, part int) PARTITIONED BY (part);
   spark-sql> INSERT INTO tbl PARTITION (part=0) SELECT 0;
   spark-sql> INSERT INTO tbl PARTITION (part=1) SELECT 1;
   spark-sql> ANALYZE TABLE tbl COMPUTE STATISTICS;
   spark-sql> DESCRIBE TABLE EXTENDED tbl;
   ...
   Statistics   4 bytes, 2 rows
   ...
   ``` 
   2. Truncate only one partition:
   ```sql
   spark-sql> TRUNCATE TABLE tbl PARTITION (part=1);
   spark-sql> SELECT * FROM tbl;
   0    0
   ```
   3. The table is still non-empty but `TRUNCATE TABLE` reseted stats:
   ```
   spark-sql> DESCRIBE TABLE EXTENDED tbl;
   ...
   Statistics   0 bytes, 0 rows
   ...
   ```
   
   ### Does this PR introduce _any_ user-facing change?
   It could impact on performance of following queries.
   
   ### How was this patch tested?
   Added new test to `StatisticsCollectionSuite`:
   ```
   $ build/sbt -Phive -Phive-thriftserver "test:testOnly 
*StatisticsCollectionSuite"
   $ build/sbt -Phive -Phive-thriftserver "test:testOnly *StatisticsSuite"
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to