Skip to content

Commit

Permalink
Test IO cost of materialized_views metadata table
Browse files Browse the repository at this point in the history
  • Loading branch information
findepi committed Oct 18, 2023
1 parent b6a28b6 commit 6ed291e
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class CountingAccessHiveMetastore
public enum Method
{
CREATE_DATABASE,
DROP_DATABASE,
CREATE_TABLE,
GET_ALL_DATABASES,
GET_DATABASE,
Expand Down Expand Up @@ -144,7 +145,8 @@ public void createDatabase(Database database)
@Override
public void dropDatabase(String databaseName, boolean deleteData)
{
throw new UnsupportedOperationException();
methodInvocations.add(Method.DROP_DATABASE);
delegate.dropDatabase(databaseName, deleteData);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,57 @@ public Object[][] metadataQueriesTestTableCountDataProvider()
};
}

@Test
public void testSystemMetadataMaterializedViews()
{
String schemaName = "test_materialized_views_" + randomNameSuffix();
assertUpdate("CREATE SCHEMA " + schemaName);
Session session = Session.builder(getSession())
.setSchema(schemaName)
.build();

assertUpdate(session, "CREATE TABLE test_table1 AS SELECT 1 a", 1);
assertUpdate(session, "CREATE TABLE test_table2 AS SELECT 1 a", 1);

assertUpdate(session, "CREATE MATERIALIZED VIEW mv1 AS SELECT * FROM test_table1 JOIN test_table2 USING (a)");
assertUpdate(session, "REFRESH MATERIALIZED VIEW mv1", 1);

assertUpdate(session, "CREATE MATERIALIZED VIEW mv2 AS SELECT count(*) c FROM test_table1 JOIN test_table2 USING (a)");
assertUpdate(session, "REFRESH MATERIALIZED VIEW mv2", 1);

// Bulk retrieval
assertFileSystemAccesses(session, "SELECT * FROM system.metadata.materialized_views WHERE schema_name = CURRENT_SCHEMA",
ImmutableMultiset.<FileOperation>builder()
.addCopies(new FileOperation(METADATA_JSON, INPUT_FILE_NEW_STREAM), 4)
.build());

// Bulk retrieval without selecting freshness
assertFileSystemAccesses(session, "SELECT schema_name, name FROM system.metadata.materialized_views WHERE schema_name = CURRENT_SCHEMA",
ImmutableMultiset.<FileOperation>builder()
.addCopies(new FileOperation(METADATA_JSON, INPUT_FILE_NEW_STREAM), 4)
.build());

// Bulk retrieval for two schemas
assertFileSystemAccesses(session, "SELECT * FROM system.metadata.materialized_views WHERE schema_name IN (CURRENT_SCHEMA, 'non_existent')",
ImmutableMultiset.<FileOperation>builder()
.addCopies(new FileOperation(METADATA_JSON, INPUT_FILE_NEW_STREAM), 4)
.build());

// Pointed lookup
assertFileSystemAccesses(session, "SELECT * FROM system.metadata.materialized_views WHERE schema_name = CURRENT_SCHEMA AND name = 'mv1'",
ImmutableMultiset.<FileOperation>builder()
.addCopies(new FileOperation(METADATA_JSON, INPUT_FILE_NEW_STREAM), 3)
.build());

// Pointed lookup without selecting freshness
assertFileSystemAccesses(session, "SELECT schema_name, name FROM system.metadata.materialized_views WHERE schema_name = CURRENT_SCHEMA AND name = 'mv1'",
ImmutableMultiset.<FileOperation>builder()
.addCopies(new FileOperation(METADATA_JSON, INPUT_FILE_NEW_STREAM), 3)
.build());

assertUpdate("DROP SCHEMA " + schemaName + " CASCADE");
}

@Test
public void testShowTables()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,60 @@ public Object[][] metadataQueriesTestTableCountDataProvider()
};
}

@Test
public void testSystemMetadataMaterializedViews()
{
String schemaName = "test_materialized_views_" + randomNameSuffix();
assertUpdate("CREATE SCHEMA " + schemaName);
Session session = Session.builder(getSession())
.setSchema(schemaName)
.build();

assertUpdate(session, "CREATE TABLE test_table1 AS SELECT 1 a", 1);
assertUpdate(session, "CREATE TABLE test_table2 AS SELECT 1 a", 1);

assertUpdate(session, "CREATE MATERIALIZED VIEW mv1 AS SELECT * FROM test_table1 JOIN test_table2 USING (a)");
assertUpdate(session, "REFRESH MATERIALIZED VIEW mv1", 1);

assertUpdate(session, "CREATE MATERIALIZED VIEW mv2 AS SELECT count(*) c FROM test_table1 JOIN test_table2 USING (a)");
assertUpdate(session, "REFRESH MATERIALIZED VIEW mv2", 1);

// Bulk retrieval
assertMetastoreInvocations(session, "SELECT * FROM system.metadata.materialized_views WHERE schema_name = CURRENT_SCHEMA",
ImmutableMultiset.builder()
.add(GET_TABLES_WITH_PARAMETER)
.addCopies(GET_TABLE, 6)
.build());

// Bulk retrieval without selecting freshness
assertMetastoreInvocations(session, "SELECT schema_name, name FROM system.metadata.materialized_views WHERE schema_name = CURRENT_SCHEMA",
ImmutableMultiset.builder()
.add(GET_TABLES_WITH_PARAMETER)
.addCopies(GET_TABLE, 6)
.build());

// Bulk retrieval for two schemas
assertMetastoreInvocations(session, "SELECT * FROM system.metadata.materialized_views WHERE schema_name IN (CURRENT_SCHEMA, 'non_existent')",
ImmutableMultiset.builder()
.addCopies(GET_TABLES_WITH_PARAMETER, 2)
.addCopies(GET_TABLE, 6)
.build());

// Pointed lookup
assertMetastoreInvocations(session, "SELECT * FROM system.metadata.materialized_views WHERE schema_name = CURRENT_SCHEMA AND name = 'mv1'",
ImmutableMultiset.builder()
.addCopies(GET_TABLE, 4)
.build());

// Pointed lookup without selecting freshness
assertMetastoreInvocations(session, "SELECT schema_name, name FROM system.metadata.materialized_views WHERE schema_name = CURRENT_SCHEMA AND name = 'mv1'",
ImmutableMultiset.builder()
.addCopies(GET_TABLE, 4)
.build());

assertUpdate("DROP SCHEMA " + schemaName + " CASCADE");
}

@Test
public void testShowTables()
{
Expand Down

0 comments on commit 6ed291e

Please sign in to comment.