Skip to content

Commit a3ed6f9

Browse files
authored
Make Snowflake QUERY_ACCELERATION_HISTORY optional (#353)
The extraction of Snowflake `QUERY_ACCELERATION_HISTORY` table is sometimes not possible, therefore I'm changing the TaskCategory from `REQUIRED` to `OPTIONAL`, so that the extraction doesn't fail in case this table is not available. Additionally, cleanup the `TeradataJdbcSelectTask` class, because otherwise the `TeradataJdbcSelectTask` class would contain a duplicated code between it and the `JdbcSelectTask` class.
1 parent 3a6be98 commit a3ed6f9

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import com.google.edwmigration.dumper.application.dumper.task.FormatTask;
3535
import com.google.edwmigration.dumper.application.dumper.task.JdbcSelectTask;
3636
import com.google.edwmigration.dumper.application.dumper.task.Task;
37+
import com.google.edwmigration.dumper.application.dumper.task.TaskCategory;
3738
import com.google.edwmigration.dumper.plugin.ext.jdk.annotation.Description;
3839
import com.google.edwmigration.dumper.plugin.lib.dumper.spi.SnowflakeLogsDumpFormat;
3940
import com.google.errorprone.annotations.ForOverride;
@@ -135,11 +136,22 @@ private static class TaskDescription {
135136
private final String unformattedQuery;
136137
private final Class<? extends Enum<?>> headerClass;
137138

139+
private final TaskCategory taskCategory;
140+
138141
private TaskDescription(
139142
String zipPrefix, String unformattedQuery, Class<? extends Enum<?>> headerClass) {
140-
this.unformattedQuery = unformattedQuery;
143+
this(zipPrefix, unformattedQuery, headerClass, TaskCategory.REQUIRED);
144+
}
145+
146+
private TaskDescription(
147+
String zipPrefix,
148+
String unformattedQuery,
149+
Class<? extends Enum<?>> headerClass,
150+
TaskCategory taskCategory) {
141151
this.zipPrefix = zipPrefix;
152+
this.unformattedQuery = unformattedQuery;
142153
this.headerClass = headerClass;
154+
this.taskCategory = taskCategory;
143155
}
144156
}
145157

@@ -381,7 +393,7 @@ private static void addJdbcTask(
381393
task.zipPrefix
382394
+ DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(interval.getStartUTC())
383395
+ ".csv";
384-
out.add(new JdbcSelectTask(file, query).withHeaderClass(task.headerClass));
396+
out.add(new JdbcSelectTask(file, query, task.taskCategory).withHeaderClass(task.headerClass));
385397
}
386398

387399
private String getOverrideableQuery(
@@ -495,7 +507,8 @@ private List<TaskDescription> createTimeSeriesTasks(ConnectorArguments arguments
495507
parseColumnsFromHeader(QueryAccelerationHistoryFormat.Header.class),
496508
"QUERY_ACCELERATION_HISTORY"),
497509
"END_TIME"),
498-
QueryAccelerationHistoryFormat.Header.class),
510+
QueryAccelerationHistoryFormat.Header.class,
511+
TaskCategory.OPTIONAL),
499512
new TaskDescription(
500513
ReplicationGroupUsageHistoryFormat.ZIP_ENTRY_PREFIX,
501514
getOverrideableQuery(

dumper/app/src/main/java/com/google/edwmigration/dumper/application/dumper/connector/teradata/AbstractTeradataConnector.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,10 @@ public String getDescription() {
121121
protected static class TeradataJdbcSelectTask extends JdbcSelectTask {
122122

123123
private final String sqlCount;
124-
private final TaskCategory category;
125124

126125
public TeradataJdbcSelectTask(String targetPath, TaskCategory category, String sqlTemplate) {
127-
super(targetPath, String.format(sqlTemplate, "*"));
126+
super(targetPath, String.format(sqlTemplate, "*"), Preconditions.checkNotNull(category));
128127
this.sqlCount = sqlTemplate.contains("%s") ? String.format(sqlTemplate, "count(*)") : null;
129-
this.category = Preconditions.checkNotNull(category);
130-
}
131-
132-
@Override
133-
public TaskCategory getCategory() {
134-
return category;
135128
}
136129

137130
// This works to execute the count SQL on the same connection as the data SQL,

dumper/app/src/main/java/com/google/edwmigration/dumper/application/dumper/task/JdbcSelectTask.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,23 @@ public class JdbcSelectTask extends AbstractJdbcTask<Summary> {
3333

3434
@Nonnull private final String sql;
3535

36+
@Nonnull private final TaskCategory taskCategory;
37+
3638
public JdbcSelectTask(@Nonnull String targetPath, @Nonnull String sql) {
39+
this(targetPath, sql, TaskCategory.REQUIRED);
40+
}
41+
42+
public JdbcSelectTask(
43+
@Nonnull String targetPath, @Nonnull String sql, TaskCategory taskCategory) {
3744
super(targetPath);
3845
this.sql = sql;
46+
this.taskCategory = taskCategory;
47+
}
48+
49+
@Override
50+
@Nonnull
51+
public TaskCategory getCategory() {
52+
return taskCategory;
3953
}
4054

4155
@Nonnull

0 commit comments

Comments
 (0)