saihemanth-cloudera commented on code in PR #6199:
URL: https://github.com/apache/hive/pull/6199#discussion_r2612017380
##########
standalone-metastore/metastore-tools/metastore-benchmarks/src/main/java/org/apache/hadoop/hive/metastore/tools/HMSBenchmarks.java:
##########
@@ -695,4 +697,68 @@ static DescriptiveStatistics
benchmarkPartitionManagement(@NotNull MicroBenchmar
}
}
+ static DescriptiveStatistics benchmarkStatisticsManagement(@NotNull
MicroBenchmark bench,
+ @NotNull
BenchData data,
+ int tableCount) {
+
+ String dbName = data.dbName + "_" + tableCount;
+ String tableNamePrefix = data.tableName;
+ final HMSClient client = data.getClient();
+ final StatisticsManagementTask statsTask = new StatisticsManagementTask();
+ final FileSystem fs;
+ try {
+ fs = FileSystem.get(client.getHadoopConf());
+ client.getHadoopConf().set("hive.metastore.uris",
client.getServerURI().toString());
+
client.getHadoopConf().set("metastore.statistics.management.database.pattern",
dbName);
+ statsTask.setConf(client.getHadoopConf());
+
+ client.createDatabase(dbName);
+ for (int i = 0; i < tableCount; i++) {
+ String tableName = tableNamePrefix + "_" + i;
+ Util.TableBuilder tableBuilder = new Util.TableBuilder(dbName,
tableName)
+ .withType(TableType.MANAGED_TABLE)
+ .withColumns(createSchema(Arrays.asList("col1:string",
"col2:int")))
+
.withPartitionKeys(createSchema(Collections.singletonList("part_col")))
+ .withParameter("columnStatsAccurate", "true");
+
+ client.createTable(tableBuilder.build());
+ addManyPartitionsNoException(client, dbName, tableName, null,
Collections.singletonList("part_col"), 100);
+
+ // simulate the partitions of each table which its stats has an old
"lastAnalyzed"
+ List<Partition> partitions = client.listPartitions(dbName, tableName);
+ for (Partition partition : partitions) {
+ Map<String, String> params = partition.getParameters();
+ // to manually change the "lastAnalyzed" to an old time, ex. 400 days
+ params.put("lastAnalyzed", String.valueOf(System.currentTimeMillis()
- TimeUnit.DAYS.toMillis(400)));
+ client.alterPartition(dbName, tableName, partition);
+ }
+ }
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+
+ Runnable preRun = () -> {
+ System.out.println("Preparing for benchmark...");
+ };
+
+ try {
+ DescriptiveStatistics stats = bench.measure(preRun, statsTask, null);
+
+ // check if the stats are deleted
+ for (int i = 0; i < tableCount; i++) {
+ String tableName = tableNamePrefix + "_" + i;
+ List<Partition> partitions = client.listPartitions(dbName, tableName);
+ for (Partition partition : partitions) {
+ Map<String, String> params = partition.getParameters();
+ if (params.containsKey("lastAnalyzed")) {
+ throw new AssertionError("Partition stats not deleted for table: "
+ tableName);
+ }
+ }
+ }
+ return stats;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
Review Comment:
I think we can also test a scenario where auto stats are skip by setting the
table property and verify that stats exists even after running stats management
task.
I think it would be better to test it out in a different test class instead
of benchmark test
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]