Skip to content
Closed
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 @@ -190,6 +190,44 @@ public void testFiltersAndProjections()
assertQuery("SELECT if(orderkey % 2 = 0, quantity_by_linenumber) FROM orders_ex");
}

@Test
public void testAnalyzeStats()
{
assertQuery("ANALYZE region");
// presto:tpch> show stats for region;
// column_name | data_size | distinct_values_count | nulls_fraction | row_count | low_value | high_value
// -------------+-----------+-----------------------+----------------+-----------+-----------+------------
// regionkey | NULL | 5.0 | 0.0 | NULL | 0 | 4
// name | 34.0 | 5.0 | 0.0 | NULL | NULL | NULL
// comment | 330.0 | 5.0 | 0.0 | NULL | NULL | NULL
// NULL | NULL | NULL | NULL | 5.0 | NULL | NULL
// (4 rows)
assertQuery("SHOW STATS FOR region");
// Create a partitioned table and run analyze on it.
String tmpTableName = generateRandomTableName();
try {
getQueryRunner().execute(getSession(), String.format("CREATE TABLE %s (name VARCHAR, regionkey BIGINT," +
"nationkey BIGINT) WITH (partitioned_by = ARRAY['regionkey','nationkey'])", tmpTableName));
Session writeSession = buildSessionForTableWrite();
getQueryRunner().execute(writeSession,
String.format("INSERT INTO %s SELECT name, regionkey, nationkey FROM nation", tmpTableName));
Copy link
Contributor

Choose a reason for hiding this comment

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

"nation" is a very tiny table for this kind of test. But its probably sufficient to test the correctness of this work.

assertQuery(String.format("SELECT * FROM %s", tmpTableName),
"SELECT name, regionkey, nationkey FROM nation");
assertQuery("ANALYZE %s WITH (partitions = ARRAY[ARRAY['0','0'],ARRAY['4', '11']])", tmpTableName);
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be worth adding a comment about the results returned by ANALYZE for this query. Is one of the arrays an empty result ?

Copy link
Contributor Author

@karteekmurthys karteekmurthys Jun 29, 2023

Choose a reason for hiding this comment

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

I dont' think so. Here are the partitions would look like:

presto:tpch> select * from "tmpregion$partitions";
 regionkey | nationkey 
-----------+-----------
         2 |        12 
         2 |         8 
         2 |         9 
         2 |        18 
         2 |        21 
         4 |        13 
         4 |        11 
         4 |        20 
         4 |        10 
         4 |         4 
         3 |        23 
         3 |        22 
         3 |         6 
         3 |         7 
         3 |        19 
         1 |        24 
         1 |         1 
         1 |        17 
         1 |         2 
         1 |         3 
         0 |        15 
         0 |        14 
         0 |         0 
         0 |        16 
         0 |         5 
(25 rows)

Added the output in the comments.

// column_name | data_size | distinct_values_count | nulls_fraction | row_count | low_value | high_value
//-------------+-----------+-----------------------+----------------+-----------+-----------+------------
// name | 137.5 | 1.0 | 0.0 | NULL | NULL | NULL
// regionkey | NULL | 5.0 | 0.0 | NULL | 0 | 4
// nationkey | NULL | 25.0 | 0.0 | NULL | 0 | 24
// NULL | NULL | NULL | NULL | 25.0 | NULL | NULL
// (4 rows)
assertQuery("SHOW STATS for %s", tmpTableName);
}
finally {
dropTableIfExists(tmpTableName);
}
}

@Test
public void testDateFilter()
{
Expand Down