33
33
import static com .facebook .presto .nativeworker .NativeQueryRunnerUtils .createNation ;
34
34
import static com .facebook .presto .nativeworker .NativeQueryRunnerUtils .createOrders ;
35
35
import static com .facebook .presto .nativeworker .NativeQueryRunnerUtils .createOrdersEx ;
36
+ import static com .facebook .presto .nativeworker .NativeQueryRunnerUtils .createRegion ;
36
37
import static com .facebook .presto .sidecar .NativeSidecarPluginQueryRunnerUtils .setupNativeSidecarPlugin ;
37
38
import static java .lang .String .format ;
38
39
import static org .testng .Assert .assertEquals ;
@@ -54,6 +55,7 @@ protected void createTables()
54
55
createNation (queryRunner );
55
56
createOrders (queryRunner );
56
57
createOrdersEx (queryRunner );
58
+ createRegion (queryRunner );
57
59
}
58
60
59
61
@ Override
@@ -234,6 +236,49 @@ public void testShowStats()
234
236
}
235
237
}
236
238
239
+ @ Test
240
+ public void testAnalyzeStats ()
241
+ {
242
+ assertUpdate ("ANALYZE region" , 5 );
243
+
244
+ // Show stats returns the following stats for each column in region table:
245
+ // column_name | data_size | distinct_values_count | nulls_fraction | row_count | low_value | high_value
246
+ assertQuery ("SHOW STATS FOR region" ,
247
+ "SELECT * FROM (VALUES" +
248
+ "('regionkey', NULL, 5e0, 0e0, NULL, '0', '4', NULL)," +
249
+ "('name', 5.4e1, 5e0, 0e0, NULL, NULL, NULL, NULL)," +
250
+ "('comment', 3.5e2, 5e0, 0e0, NULL, NULL, NULL, NULL)," +
251
+ "(NULL, NULL, NULL, NULL, 5e0, NULL, NULL, NULL))" );
252
+
253
+ // Create a partitioned table and run analyze on it.
254
+ String tmpTableName = generateRandomTableName ();
255
+ try {
256
+ getQueryRunner ().execute (String .format ("CREATE TABLE %s (name VARCHAR, regionkey BIGINT," +
257
+ "nationkey BIGINT) WITH (partitioned_by = ARRAY['regionkey','nationkey'])" , tmpTableName ));
258
+ getQueryRunner ().execute (
259
+ String .format ("INSERT INTO %s SELECT name, regionkey, nationkey FROM nation" , tmpTableName ));
260
+ assertQuery (String .format ("SELECT * FROM %s" , tmpTableName ),
261
+ "SELECT name, regionkey, nationkey FROM nation" );
262
+ assertUpdate (String .format ("ANALYZE %s" , tmpTableName ), 25 );
263
+ assertQuery (String .format ("SHOW STATS for %s" , tmpTableName ),
264
+ "SELECT * FROM (VALUES" +
265
+ "('name', 2.77e2, 1e0, 0e0, NULL, NULL, NULL, NULL)," +
266
+ "('regionkey', NULL, 5e0, 0e0, NULL, '0', '4', NULL)," +
267
+ "('nationkey', NULL, 2.5e1, 0e0, NULL, '0', '24', NULL)," +
268
+ "(NULL, NULL, NULL, NULL, 2.5e1, NULL, NULL, NULL))" );
269
+ assertUpdate (String .format ("ANALYZE %s WITH (partitions = ARRAY[ARRAY['0','0'],ARRAY['4', '11']])" , tmpTableName ), 2 );
270
+ assertQuery (String .format ("SHOW STATS for (SELECT * FROM %s where regionkey=4 and nationkey=11)" , tmpTableName ),
271
+ "SELECT * FROM (VALUES" +
272
+ "('name', 8e0, 1e0, 0e0, NULL, NULL, NULL, NULL)," +
273
+ "('regionkey', NULL, 1e0, 0e0, NULL, '4', '4', NULL)," +
274
+ "('nationkey', NULL, 1e0, 0e0, NULL, '11', '11', NULL)," +
275
+ "(NULL, NULL, NULL, NULL, 1e0, NULL, NULL, NULL))" );
276
+ }
277
+ finally {
278
+ dropTableIfExists (tmpTableName );
279
+ }
280
+ }
281
+
237
282
private String generateRandomTableName ()
238
283
{
239
284
String tableName = "tmp_presto_" + UUID .randomUUID ().toString ().replace ("-" , "" );
0 commit comments