From 12918adf3dad45daf3bead06e626a2c07b274bbd Mon Sep 17 00:00:00 2001 From: Dawid Chodura Date: Wed, 10 Jan 2024 13:04:30 +0100 Subject: [PATCH] Remove filtering by DatabaseName when extracting DatabasesV (#337) --- .../teradata/MetadataQueryGenerator.java | 20 ++--- .../teradata/TeradataMetadataConnector.java | 7 +- .../teradata/MetadataQueryGeneratorTest.java | 75 +------------------ 3 files changed, 13 insertions(+), 89 deletions(-) diff --git a/dumper/app/src/main/java/com/google/edwmigration/dumper/application/dumper/connector/teradata/MetadataQueryGenerator.java b/dumper/app/src/main/java/com/google/edwmigration/dumper/application/dumper/connector/teradata/MetadataQueryGenerator.java index a7de46d21..a5e8a4917 100644 --- a/dumper/app/src/main/java/com/google/edwmigration/dumper/application/dumper/connector/teradata/MetadataQueryGenerator.java +++ b/dumper/app/src/main/java/com/google/edwmigration/dumper/application/dumper/connector/teradata/MetadataQueryGenerator.java @@ -17,7 +17,6 @@ package com.google.edwmigration.dumper.application.dumper.connector.teradata; import static com.google.edwmigration.dumper.application.dumper.connector.teradata.TeradataUtils.optionalIf; -import static com.google.edwmigration.dumper.application.dumper.connector.teradata.query.TeradataSelectBuilder.and; import static com.google.edwmigration.dumper.application.dumper.connector.teradata.query.TeradataSelectBuilder.eq; import static com.google.edwmigration.dumper.application.dumper.connector.teradata.query.TeradataSelectBuilder.identifier; import static com.google.edwmigration.dumper.application.dumper.connector.teradata.query.TeradataSelectBuilder.in; @@ -59,13 +58,12 @@ class MetadataQueryGenerator { .where(eq(identifier("InfoKey"), stringLiteral("VERSION"))) .serialize(); - static String createSelectForDatabasesV( - OptionalLong userRows, OptionalLong dbRows, Optional condition) { + static String createSelectForDatabasesV(OptionalLong userRows, OptionalLong dbRows) { if (!userRows.isPresent() && !dbRows.isPresent()) { - return createSimpleSelect("DBC.DatabasesV", condition); + return select("%s").from("DBC.DatabasesV").serialize(); } - SelectExpression usersSelect = createSingleDbKindSelectFromDatabasesV("U", userRows, condition); - SelectExpression dbsSelect = createSingleDbKindSelectFromDatabasesV("D", dbRows, condition); + SelectExpression usersSelect = createSingleDbKindSelectFromDatabasesV("U", userRows); + SelectExpression dbsSelect = createSingleDbKindSelectFromDatabasesV("D", dbRows); return select("%s") .from( subquery( @@ -122,19 +120,13 @@ static String createSelectForDiskSpaceV(OptionalLong rowCount, Optional condition) { + String dbKind, OptionalLong rowCount) { Expression dbKindCondition = eq(identifier("DBKind"), stringLiteral(dbKind)); Optional params = optionalIf( rowCount.isPresent(), () -> LimitedSelectParams.create(rowCount.getAsLong(), "PermSpace")); - return createLimitedSelect( - params, - "DBC.DatabasesV", - Optional.of( - condition - .map(innerCondition -> and(innerCondition, dbKindCondition)) - .orElse(dbKindCondition))); + return createLimitedSelect(params, "DBC.DatabasesV", Optional.of(dbKindCondition)); } private static SelectExpression createLimitedSelect( diff --git a/dumper/app/src/main/java/com/google/edwmigration/dumper/application/dumper/connector/teradata/TeradataMetadataConnector.java b/dumper/app/src/main/java/com/google/edwmigration/dumper/application/dumper/connector/teradata/TeradataMetadataConnector.java index acbe55989..c230c2fc1 100644 --- a/dumper/app/src/main/java/com/google/edwmigration/dumper/application/dumper/connector/teradata/TeradataMetadataConnector.java +++ b/dumper/app/src/main/java/com/google/edwmigration/dumper/application/dumper/connector/teradata/TeradataMetadataConnector.java @@ -131,7 +131,7 @@ public void addTasksTo(List> out, ConnectorArguments arguments) // out.add(new JdbcSelectTask(ColumnsFormat.ZIP_ENTRY_NAME, // Was: teradata.columns.csv // "SELECT \"DatabaseName\", \"TableName\", \"ColumnId\", \"ColumnName\", \"ColumnType\" FROM // DBC.Columns" + whereDatabaseNameClause + " ;")); - out.add(createTaskForDatabasesV(arguments, databaseNameCondition)); + out.add(createTaskForDatabasesV(arguments)); // out.add(new TeradataJdbcSelectTask("td.dbc.Tables.others.csv", "SELECT * FROM DBC.Tables // WHERE TableKind <> 'F' ORDER BY 1,2,3,4;")); // out.add(new TeradataJdbcSelectTask("td.dbc.Tables.functions.csv", "SELECT * FROM DBC.Tables @@ -228,8 +228,7 @@ private TeradataJdbcSelectTask createTaskForTableTextV( createSelectForTableTextV(textMaxLength, databaseNameCondition)); } - private TeradataJdbcSelectTask createTaskForDatabasesV( - ConnectorArguments arguments, Optional databaseNameCondition) + private TeradataJdbcSelectTask createTaskForDatabasesV(ConnectorArguments arguments) throws MetadataDumperUsageException { OptionalLong userRows = parseMaxRows(arguments, TeradataMetadataConnectorProperties.DATABASES_V_USERS_MAX_ROWS); @@ -238,7 +237,7 @@ private TeradataJdbcSelectTask createTaskForDatabasesV( return new TeradataJdbcSelectTask( DatabasesVFormat.ZIP_ENTRY_NAME, TaskCategory.REQUIRED, - MetadataQueryGenerator.createSelectForDatabasesV(userRows, dbRows, databaseNameCondition)); + MetadataQueryGenerator.createSelectForDatabasesV(userRows, dbRows)); } private TeradataJdbcSelectTask createTaskForAllTempTablesVX(ConnectorArguments arguments) { diff --git a/dumper/app/src/test/java/com/google/edwmigration/dumper/application/dumper/connector/teradata/MetadataQueryGeneratorTest.java b/dumper/app/src/test/java/com/google/edwmigration/dumper/application/dumper/connector/teradata/MetadataQueryGeneratorTest.java index c632edfbd..e7ae31a00 100644 --- a/dumper/app/src/test/java/com/google/edwmigration/dumper/application/dumper/connector/teradata/MetadataQueryGeneratorTest.java +++ b/dumper/app/src/test/java/com/google/edwmigration/dumper/application/dumper/connector/teradata/MetadataQueryGeneratorTest.java @@ -22,7 +22,6 @@ import static com.google.edwmigration.dumper.application.dumper.connector.teradata.MetadataQueryGenerator.createSelectForTableTextV; import static com.google.edwmigration.dumper.application.dumper.connector.teradata.query.TeradataSelectBuilder.eq; import static com.google.edwmigration.dumper.application.dumper.connector.teradata.query.TeradataSelectBuilder.identifier; -import static com.google.edwmigration.dumper.application.dumper.connector.teradata.query.TeradataSelectBuilder.in; import static com.google.edwmigration.dumper.application.dumper.connector.teradata.query.TeradataSelectBuilder.stringLiteral; import static com.google.edwmigration.dumper.application.dumper.test.DumperTestUtils.assertQueryEquals; @@ -41,35 +40,18 @@ public void createSelectForDatabasesV_noLimits() { // Act String query = MetadataQueryGenerator.createSelectForDatabasesV( - /* userRows= */ OptionalLong.empty(), - /* dbRows= */ OptionalLong.empty(), - /* condition= */ Optional.empty()); + /* userRows= */ OptionalLong.empty(), /* dbRows= */ OptionalLong.empty()); // Assert assertQueryEquals("SELECT %s FROM DBC.DatabasesV", query); } - @Test - public void createSelectForDatabasesV_condition() { - // Act - String query = - MetadataQueryGenerator.createSelectForDatabasesV( - /* userRows= */ OptionalLong.empty(), - /* dbRows= */ OptionalLong.empty(), - /* condition= */ Optional.of(eq(identifier("DatabaseName"), stringLiteral("abc")))); - - // Assert - assertQueryEquals("SELECT %s FROM DBC.DatabasesV WHERE DatabaseName = 'abc'", query); - } - @Test public void createSelectForDatabasesV_usersLimit() { // Act String query = MetadataQueryGenerator.createSelectForDatabasesV( - /* userRows= */ OptionalLong.of(13), - /* dbRows= */ OptionalLong.empty(), - /* condition= */ Optional.empty()); + /* userRows= */ OptionalLong.of(13), /* dbRows= */ OptionalLong.empty()); // Assert assertQueryEquals( @@ -82,35 +64,12 @@ public void createSelectForDatabasesV_usersLimit() { query); } - @Test - public void createSelectForDatabasesV_usersLimitAndCondition() { - // Act - String query = - MetadataQueryGenerator.createSelectForDatabasesV( - /* userRows= */ OptionalLong.of(13), - /* dbRows= */ OptionalLong.empty(), - /* condition= */ Optional.of(eq(identifier("DatabaseName"), stringLiteral("abc")))); - - // Assert - assertQueryEquals( - "SELECT %s FROM (" - + " SELECT * FROM (SELECT TOP 13 * FROM DBC.DatabasesV" - + " WHERE (DatabaseName = 'abc' AND DBKind = 'U') ORDER BY PermSpace DESC) AS users" - + " UNION ALL " - + " SELECT * FROM (SELECT * FROM DBC.DatabasesV" - + " WHERE (DatabaseName = 'abc' AND DBKind = 'D')) AS dbs" - + ") AS t", - query); - } - @Test public void createSelectForDatabasesV_dbsLimit() { // Act String query = MetadataQueryGenerator.createSelectForDatabasesV( - /* userRows= */ OptionalLong.empty(), - /* dbRows= */ OptionalLong.of(18), - /* condition= */ Optional.empty()); + /* userRows= */ OptionalLong.empty(), /* dbRows= */ OptionalLong.of(18)); // Assert assertQueryEquals( @@ -128,9 +87,7 @@ public void createSelectForDatabasesV_usersAndDbsLimit() { // Act String query = MetadataQueryGenerator.createSelectForDatabasesV( - /* userRows= */ OptionalLong.of(15), - /* dbRows= */ OptionalLong.of(18), - /* condition= */ Optional.empty()); + /* userRows= */ OptionalLong.of(15), /* dbRows= */ OptionalLong.of(18)); // Assert assertQueryEquals( @@ -144,30 +101,6 @@ public void createSelectForDatabasesV_usersAndDbsLimit() { query); } - @Test - public void createSelectForDatabasesV_usersAndDbsLimitAndCondition() { - // Act - String query = - MetadataQueryGenerator.createSelectForDatabasesV( - /* userRows= */ OptionalLong.of(15), - /* dbRows= */ OptionalLong.of(18), - /* condition= */ Optional.of( - in(identifier("DatabaseName"), ImmutableList.of("db1", "db2")))); - - // Assert - assertQueryEquals( - "SELECT %s FROM (" - + " SELECT * FROM (SELECT TOP 15 * FROM DBC.DatabasesV" - + " WHERE (DatabaseName IN ('db1', 'db2') AND DBKind = 'U')" - + " ORDER BY PermSpace DESC) AS users" - + " UNION ALL " - + " SELECT * FROM (SELECT TOP 18 * FROM DBC.DatabasesV" - + " WHERE (DatabaseName IN ('db1', 'db2') AND DBKind = 'D')" - + " ORDER BY PermSpace DESC) AS dbs" - + ") AS t", - query); - } - @Test public void dbcInfoQuery() { assertQueryEquals(