Skip to content

Commit 01ed184

Browse files
committed
Create and use AssessmentQuery#substitute
1 parent 8de9fb7 commit 01ed184

File tree

2 files changed

+30
-23
lines changed

2 files changed

+30
-23
lines changed

dumper/app/src/main/java/com/google/edwmigration/dumper/application/dumper/connector/snowflake/SnowflakeMetadataConnector.java

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,11 @@ public final void addTasksTo(
287287

288288
if (isAssessment) {
289289
for (AssessmentQuery item : planner.generateAssessmentQueries()) {
290-
out.add(taskForAssessment(item, arguments));
290+
String query = queryForAssessment(item, arguments);
291+
Task<?> task =
292+
new JdbcSelectTask(item.zipEntryName, query, TaskCategory.REQUIRED, TaskOptions.DEFAULT)
293+
.withHeaderTransformer(item.transformer());
294+
out.add(task);
291295
}
292296
} else {
293297
if (!arguments.getDatabases().isEmpty()) {
@@ -317,29 +321,28 @@ public final void addTasksTo(
317321
}
318322
}
319323

320-
private Task<?> taskForAssessment(AssessmentQuery item, ConnectorArguments arguments) {
321-
String formatString =
322-
item.needsOverride
323-
? getOverrideableQuery(arguments, item.formatString, TABLE_STORAGE_METRICS)
324-
: item.formatString;
325-
// Check whether the overrides changed anything.
326-
if (formatString.equals(item.formatString)) {
327-
// Overrides either not applied or equal to default values.
328-
String whereCondition =
329-
" WHERE deleted = FALSE AND schema_dropped IS NULL AND table_dropped IS NULL";
330-
// The condition is always passed to String.format. SHOW queries simply ignore it.
331-
String query = String.format(formatString, ACCOUNT_USAGE_SCHEMA_NAME, whereCondition);
332-
return new JdbcSelectTask(
333-
item.zipEntryName, query, TaskCategory.REQUIRED, TaskOptions.DEFAULT)
334-
.withHeaderTransformer(item.transformer());
335-
} else {
336-
String whereCondition = "";
337-
// The condition is always passed to String.format. SHOW queries simply ignore it.
338-
String query = String.format(formatString, ACCOUNT_USAGE_SCHEMA_NAME, whereCondition);
339-
return new JdbcSelectTask(
340-
item.zipEntryName, query, TaskCategory.REQUIRED, TaskOptions.DEFAULT)
341-
.withHeaderTransformer(item.transformer());
324+
private String queryForAssessment(AssessmentQuery item, ConnectorArguments arguments) {
325+
MetadataView view = TABLE_STORAGE_METRICS;
326+
String schema = ACCOUNT_USAGE_SCHEMA_NAME;
327+
if (!item.needsOverride) {
328+
return item.substitute(schema, "");
329+
}
330+
331+
ConnectorProperty propertyQuery = PropertyAction.QUERY.toProperty(view);
332+
String overrideQuery = arguments.getDefinition(propertyQuery);
333+
if (overrideQuery != null) {
334+
return String.format(overrideQuery, schema, "");
342335
}
336+
337+
ConnectorProperty propertyWhere = PropertyAction.WHERE.toProperty(view);
338+
String overrideWhere = arguments.getDefinition(propertyWhere);
339+
if (overrideWhere != null) {
340+
return item.substitute(schema, overrideWhere);
341+
}
342+
343+
String whereCondition =
344+
" WHERE deleted = FALSE AND schema_dropped IS NULL AND table_dropped IS NULL";
345+
return item.substitute(schema, whereCondition);
343346
}
344347

345348
private void addAssessmentQuery(

dumper/app/src/main/java/com/google/edwmigration/dumper/application/dumper/connector/snowflake/SnowflakePlanner.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ static AssessmentQuery createShow(String view, Format zipFormat, CaseFormat case
147147
ResultSetTransformer<String[]> transformer() {
148148
return HeaderTransformerUtil.toCamelCaseFrom(caseFormat);
149149
}
150+
151+
String substitute(String schema, String whereCondition) {
152+
return String.format(formatString, schema, whereCondition);
153+
}
150154
}
151155

152156
Task<?> eventStateTask() {

0 commit comments

Comments
 (0)