Skip to content

Commit 7bdae01

Browse files
authored
[b/343058608] Change the format of master-keys file from csv to jsonl (GoogleCloudPlatform#455)
1 parent 315fb87 commit 7bdae01

2 files changed

Lines changed: 20 additions & 9 deletions

File tree

dumper/app/src/main/java/com/google/edwmigration/dumper/application/dumper/connector/hive/HiveMetadataConnector.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@
1616
*/
1717
package com.google.edwmigration.dumper.application.dumper.connector.hive;
1818

19+
import com.fasterxml.jackson.annotation.JsonProperty;
1920
import com.fasterxml.jackson.core.JsonFactory;
2021
import com.fasterxml.jackson.core.JsonGenerator;
22+
import com.fasterxml.jackson.databind.ObjectMapper;
2123
import com.google.auto.service.AutoService;
24+
import com.google.auto.value.AutoValue;
2225
import com.google.common.base.MoreObjects;
2326
import com.google.common.base.Preconditions;
2427
import com.google.common.collect.ImmutableList;
@@ -522,11 +525,10 @@ private CatalogsJsonlTask() {
522525
}
523526

524527
private static class MasterKeysTask extends AbstractHiveMetadataTask {
525-
private static final CSVFormat MASTER_KEYS_FORMAT =
526-
FORMAT.builder().setHeader("MasterKey").build();
528+
private final ObjectMapper objectMapper = new ObjectMapper();
527529

528530
private MasterKeysTask() {
529-
super("master-keys.csv");
531+
super("master-keys.jsonl");
530532
}
531533

532534
@Override
@@ -537,11 +539,10 @@ protected void run(@Nonnull Writer writer, @Nonnull ThriftClientHandle thriftCli
537539
RecordProgressMonitor monitor =
538540
new RecordProgressMonitor("Writing Master Keys to " + getTargetPath())) {
539541
ImmutableList<String> masterKeys = client.getMasterKeys();
540-
try (CSVPrinter printer = MASTER_KEYS_FORMAT.print(writer)) {
541-
for (String masterKey : masterKeys) {
542-
monitor.count();
543-
printer.printRecord(masterKey);
544-
}
542+
for (String masterKey : masterKeys) {
543+
monitor.count();
544+
writer.write(objectMapper.writeValueAsString(MasterKey.create(masterKey)));
545+
writer.write('\n');
545546
}
546547
}
547548
}
@@ -557,6 +558,16 @@ protected String toCallDescription() {
557558
}
558559
}
559560

561+
@AutoValue
562+
abstract static class MasterKey {
563+
@JsonProperty
564+
abstract String masterKey();
565+
566+
public static MasterKey create(String masterKey) {
567+
return new AutoValue_HiveMetadataConnector_MasterKey(masterKey);
568+
}
569+
}
570+
560571
private static class DelegationTokensTask extends AbstractHiveMetadataTask {
561572
private static final CSVFormat DELEGATION_TOKENS_FORMAT =
562573
FORMAT.builder().setHeader("Identifier", "Token").build();

dumper/app/src/test/java/com/google/edwmigration/dumper/application/dumper/connector/hive/HiveMetadataConnectorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public void addTasksTo_originalTableJsonl_success() throws IOException {
119119
ImmutableList.of(
120120
"catalogs.jsonl",
121121
"databases.jsonl",
122-
"master-keys.csv",
122+
"master-keys.jsonl",
123123
"delegation-tokens.csv",
124124
"functions.jsonl",
125125
"resource-plans.jsonl",

0 commit comments

Comments
 (0)