Skip to content

Commit e42377a

Browse files
committed
Add a DumpMetadataTask clone for Snowflake
1 parent 0daf8ed commit e42377a

File tree

4 files changed

+123
-6
lines changed

4 files changed

+123
-6
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import com.google.edwmigration.dumper.application.dumper.MetadataDumperUsageException;
2222
import com.google.edwmigration.dumper.application.dumper.annotations.RespectsArgumentAssessment;
2323
import com.google.edwmigration.dumper.application.dumper.connector.Connector;
24-
import com.google.edwmigration.dumper.application.dumper.task.DumpMetadataTask;
2524
import com.google.edwmigration.dumper.application.dumper.task.FormatTask;
2625
import com.google.edwmigration.dumper.application.dumper.task.Task;
2726
import com.google.edwmigration.dumper.application.dumper.utils.ArchiveNameUtil;
@@ -59,7 +58,7 @@ public String getDescription() {
5958

6059
@Override
6160
public final void addTasksTo(List<? super Task<?>> out, ConnectorArguments arguments) {
62-
out.add(new DumpMetadataTask(arguments, FORMAT_NAME));
61+
out.add(SnowflakeYamlSummaryTask.create(FORMAT_NAME, arguments));
6362
out.add(new FormatTask(FORMAT_NAME));
6463
out.addAll(planner.generateLiteSpecificQueries());
6564
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import com.google.edwmigration.dumper.application.dumper.connector.ZonedInterval;
4040
import com.google.edwmigration.dumper.application.dumper.connector.ZonedIntervalIterable;
4141
import com.google.edwmigration.dumper.application.dumper.connector.ZonedIntervalIterableGenerator;
42-
import com.google.edwmigration.dumper.application.dumper.task.DumpMetadataTask;
4342
import com.google.edwmigration.dumper.application.dumper.task.FormatTask;
4443
import com.google.edwmigration.dumper.application.dumper.task.JdbcSelectTask;
4544
import com.google.edwmigration.dumper.application.dumper.task.Task;
@@ -300,7 +299,7 @@ private static String getOverrideQuery(@Nonnull ConnectorArguments arguments)
300299
public final void addTasksTo(
301300
@Nonnull List<? super Task<?>> out, @Nonnull ConnectorArguments arguments)
302301
throws MetadataDumperUsageException {
303-
out.add(new DumpMetadataTask(arguments, FORMAT_NAME));
302+
out.add(SnowflakeYamlSummaryTask.create(FORMAT_NAME, arguments));
304303
out.add(new FormatTask(FORMAT_NAME));
305304

306305
// (24 * 7) -> 7 trailing days == 168 hours

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import com.google.edwmigration.dumper.application.dumper.io.OutputHandle.WriteMode;
3535
import com.google.edwmigration.dumper.application.dumper.task.AbstractJdbcTask;
3636
import com.google.edwmigration.dumper.application.dumper.task.AbstractTask.TaskOptions;
37-
import com.google.edwmigration.dumper.application.dumper.task.DumpMetadataTask;
3837
import com.google.edwmigration.dumper.application.dumper.task.FormatTask;
3938
import com.google.edwmigration.dumper.application.dumper.task.JdbcSelectTask;
4039
import com.google.edwmigration.dumper.application.dumper.task.Summary;
@@ -178,7 +177,7 @@ private void addSqlTasksWithInfoSchemaFallback(
178177
@Override
179178
public final void addTasksTo(
180179
@Nonnull List<? super Task<?>> out, @Nonnull ConnectorArguments arguments) {
181-
out.add(new DumpMetadataTask(arguments, FORMAT_NAME));
180+
out.add(SnowflakeYamlSummaryTask.create(FORMAT_NAME, arguments));
182181
out.add(new FormatTask(FORMAT_NAME));
183182

184183
boolean INJECT_IS_FAULT = arguments.isTestFlag('A');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/*
2+
* Copyright 2022-2025 Google LLC
3+
* Copyright 2013-2021 CompilerWorks
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package com.google.edwmigration.dumper.application.dumper.connector.snowflake;
18+
19+
import static java.nio.charset.StandardCharsets.UTF_8;
20+
import static java.util.Objects.requireNonNull;
21+
22+
import com.google.common.io.ByteSink;
23+
import com.google.common.io.CharSink;
24+
import com.google.edwmigration.dumper.application.dumper.ConnectorArguments;
25+
import com.google.edwmigration.dumper.application.dumper.handle.Handle;
26+
import com.google.edwmigration.dumper.application.dumper.task.AbstractTask;
27+
import com.google.edwmigration.dumper.application.dumper.task.TaskRunContext;
28+
import com.google.edwmigration.dumper.plugin.lib.dumper.spi.CoreMetadataDumpFormat;
29+
import com.google.edwmigration.dumper.plugin.lib.dumper.spi.CoreMetadataDumpFormat.CompilerWorksDumpMetadataTaskFormat;
30+
import com.google.edwmigration.dumper.plugin.lib.dumper.spi.CoreMetadataDumpFormat.CompilerWorksDumpMetadataTaskFormat.Product;
31+
import com.google.edwmigration.dumper.plugin.lib.dumper.spi.CoreMetadataDumpFormat.CompilerWorksDumpMetadataTaskFormat.Root;
32+
import java.io.IOException;
33+
import java.io.Writer;
34+
import javax.annotation.Nonnull;
35+
import javax.annotation.Nullable;
36+
import javax.annotation.ParametersAreNonnullByDefault;
37+
import org.anarres.jdiagnostics.ProductMetadata;
38+
39+
/** A {@link Task} that creates YAML with extraction metadata. */
40+
@ParametersAreNonnullByDefault
41+
abstract class SnowflakeYamlSummaryTask extends AbstractTask<Void> {
42+
43+
private static final String zipEntryName = CompilerWorksDumpMetadataTaskFormat.ZIP_ENTRY_NAME;
44+
45+
@Nonnull private final String zipFormat;
46+
47+
@Override
48+
public final String describeSourceData() {
49+
return "containing dump metadata.";
50+
}
51+
52+
@Override
53+
protected final Void doRun(@Nullable TaskRunContext context, ByteSink sink, Handle handle)
54+
throws IOException {
55+
Product product = new Product();
56+
product.version = String.valueOf(new ProductMetadata());
57+
product.arguments = serializedArguments(context);
58+
59+
CharSink streamSupplier = sink.asCharSink(UTF_8);
60+
try (Writer writer = streamSupplier.openBufferedStream()) {
61+
62+
Root root = new Root();
63+
root.format = zipFormat;
64+
root.timestamp = System.currentTimeMillis();
65+
root.product = product;
66+
CoreMetadataDumpFormat.MAPPER.writeValue(writer, root);
67+
return null;
68+
}
69+
}
70+
71+
@Nonnull
72+
static SnowflakeYamlSummaryTask create(String zipFormat) {
73+
return new ContextArgumentsTask(zipFormat);
74+
}
75+
76+
@Nonnull
77+
static SnowflakeYamlSummaryTask create(String zipFormat, ConnectorArguments arguments) {
78+
return new FixedArgumentsTask(zipFormat, arguments);
79+
}
80+
81+
private SnowflakeYamlSummaryTask(String format) {
82+
super(zipEntryName);
83+
this.zipFormat = format;
84+
}
85+
86+
@Nonnull
87+
abstract String serializedArguments(@Nullable TaskRunContext context);
88+
89+
/** A task that takes arguments from {@link TaskRunContext}. */
90+
private static class ContextArgumentsTask extends SnowflakeYamlSummaryTask {
91+
92+
ContextArgumentsTask(String zipFormat) {
93+
super(zipFormat);
94+
}
95+
96+
@Override
97+
@Nonnull
98+
String serializedArguments(@Nullable TaskRunContext context) {
99+
context = requireNonNull(context);
100+
return String.valueOf(context.getArguments());
101+
}
102+
}
103+
104+
/** A task that stores its own {@link ConnectorArguments}. */
105+
private static class FixedArgumentsTask extends SnowflakeYamlSummaryTask {
106+
107+
@Nonnull final ConnectorArguments arguments;
108+
109+
FixedArgumentsTask(String zipFormat, ConnectorArguments arguments) {
110+
super(zipFormat);
111+
this.arguments = arguments;
112+
}
113+
114+
@Override
115+
@Nonnull
116+
String serializedArguments(@Nullable TaskRunContext unused) {
117+
return String.valueOf(arguments);
118+
}
119+
}
120+
}

0 commit comments

Comments
 (0)