Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,10 @@ public String getQueryLogEarliestTimestamp() {
return getOptions().valueOf(optionQueryLogEarliestTimestamp);
}

public boolean hasQueryLogEarliestTimestamp() {
return getOptions().valueOf(optionQueryLogEarliestTimestamp) != null;
}

@CheckForNull
public Integer getQueryLogDays() {
return getOptions().valueOf(optionQueryLogDays);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,6 @@ private String createExtendedQueryFromAccountUsage(ConnectorArguments arguments)
String overrideQuery = getOverrideQuery(arguments);
if (overrideQuery != null) return overrideQuery;

String overrideWhere = getOverrideWhere(arguments);

@SuppressWarnings("OrphanedFormatString")
StringBuilder queryBuilder =
new StringBuilder(
Expand Down Expand Up @@ -333,12 +331,8 @@ private String createExtendedQueryFromAccountUsage(ConnectorArguments arguments)
+ "WHERE end_time >= to_timestamp_ltz('%s')\n"
+ "AND end_time <= to_timestamp_ltz('%s')\n"
+ "AND is_client_generated_statement = FALSE\n");
if (!StringUtils.isBlank(arguments.getQueryLogEarliestTimestamp()))
queryBuilder
.append("AND start_time >= ")
.append(arguments.getQueryLogEarliestTimestamp())
.append("\n");
if (overrideWhere != null) queryBuilder.append(" AND ").append(overrideWhere);

queryBuilder.append(getOverrideWhere(arguments));
return queryBuilder.toString().replace('\n', ' ');
}

Expand All @@ -356,16 +350,29 @@ private String getOverrideQuery(@Nonnull ConnectorArguments arguments)
return null;
}

@CheckForNull
@Nonnull
private String getOverrideWhere(@Nonnull ConnectorArguments arguments)
throws MetadataDumperUsageException {
return arguments.getDefinition(SnowflakeLogConnectorProperties.OVERRIDE_WHERE);
ConnectorProperty property = SnowflakeLogConnectorProperties.OVERRIDE_WHERE;
String overrideWhere = arguments.getDefinition(property);
if (overrideWhere != null) {
return String.format(" AND %s", overrideWhere);
} else {
return "";
}
}

@Override
public final void addTasksTo(
@Nonnull List<? super Task<?>> out, @Nonnull ConnectorArguments arguments)
throws MetadataDumperUsageException {

boolean isAssessment = arguments.isAssessment();

if (isAssessment && arguments.hasQueryLogEarliestTimestamp()) {
throw unsupportedOption(ConnectorArguments.OPT_QUERY_LOG_EARLIEST_TIMESTAMP);
}

out.add(new DumpMetadataTask(arguments, FORMAT_NAME));
out.add(new FormatTask(FORMAT_NAME));

Expand Down Expand Up @@ -401,6 +408,13 @@ public final void addTasksTo(
.forEach(interval -> timeSeriesTasks.forEach(task -> addJdbcTask(out, interval, task)));
}

private static MetadataDumperUsageException unsupportedOption(String option) {
String assessment = ConnectorArguments.OPT_ASSESSMENT;
String message =
String.format("Unsupported option used with --%s: please remove --%s", assessment, option);
return new MetadataDumperUsageException(message);
}

private static void addJdbcTask(
List<? super Task<?>> out, ZonedInterval interval, TaskDescription task) {
String query =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@
package com.google.edwmigration.dumper.application.dumper.connector.snowflake;

import com.google.common.base.Predicates;
import com.google.edwmigration.dumper.application.dumper.ConnectorArguments;
import com.google.edwmigration.dumper.application.dumper.MetadataDumperUsageException;
import com.google.edwmigration.dumper.plugin.lib.dumper.spi.SnowflakeLogsDumpFormat;
import com.google.edwmigration.dumper.test.TestUtils;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand All @@ -41,4 +46,19 @@ public void testExecution() throws Exception {

validator.run(outputFile);
}

@Test
public void addTasksTo_unsupportedOption_throwsException() throws IOException {
ConnectorArguments arguments =
new ConnectorArguments(
"--connector",
"snowflake-logs",
"--assessment",
"--" + ConnectorArguments.OPT_QUERY_LOG_EARLIEST_TIMESTAMP,
"2024");

Assert.assertThrows(
MetadataDumperUsageException.class,
() -> connector.addTasksTo(new ArrayList<>(), arguments));
}
}
Loading