-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[HUDI-7399] hudi-aws sync integration testing #10614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a662442
Setup maven docker moto for IT tests
parisni 26def33
Temporary hide hudi-aws deps from hudi-client-common
parisni 9c20da8
Use hudi-java-client from hudi-aws
parisni d29fd4e
Move cloudwatch metrics to hudi-aws and use reflexion to instantiate it
parisni 769e6a8
First IT test for glue sync tool
parisni b3713e1
cleanup pom
parisni 3dd6bd9
Attempt to refactor
parisni 9c2af1e
Rm hudi-example deps
parisni 191f4dc
Fix partitions
parisni d7ec2e6
TestCleanup
parisni fb0c3ab
Fix style
parisni 43d691e
Fix rats
parisni f1d46fb
Refactor
parisni 9add9dd
Allow change data generator
parisni File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
222 changes: 222 additions & 0 deletions
222
hudi-aws/src/test/java/org/apache/hudi/aws/sync/HoodieDataGenerator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,222 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.hudi.aws.sync; | ||
|
|
||
| import org.apache.avro.Schema; | ||
| import org.apache.avro.generic.GenericData; | ||
| import org.apache.avro.generic.GenericRecord; | ||
|
|
||
| import org.apache.hudi.common.model.HoodieAvroPayload; | ||
| import org.apache.hudi.common.model.HoodieAvroRecord; | ||
| import org.apache.hudi.common.model.HoodieKey; | ||
| import org.apache.hudi.common.model.HoodieRecord; | ||
| import org.apache.hudi.common.model.HoodieRecordPayload; | ||
| import org.apache.hudi.common.util.Option; | ||
|
|
||
| import java.io.Serializable; | ||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Random; | ||
| import java.util.UUID; | ||
| import java.util.stream.Collectors; | ||
| import java.util.stream.IntStream; | ||
| import java.util.stream.Stream; | ||
|
|
||
| /** | ||
| * Class to be used to generate test data. | ||
| */ | ||
| public class HoodieDataGenerator<T extends HoodieRecordPayload<T>> { | ||
|
|
||
| public static final String DEFAULT_FIRST_PARTITION_PATH = "2020/01/01"; | ||
| public static final String DEFAULT_SECOND_PARTITION_PATH = "2020/01/02"; | ||
| public static final String DEFAULT_THIRD_PARTITION_PATH = "2020/01/03"; | ||
|
|
||
| public static final String[] DEFAULT_PARTITION_PATHS = | ||
| {DEFAULT_FIRST_PARTITION_PATH, DEFAULT_SECOND_PARTITION_PATH, DEFAULT_THIRD_PARTITION_PATH}; | ||
|
|
||
|
|
||
| private static final Random RAND = new Random(46474747); | ||
|
|
||
| private final Map<Integer, KeyPartition> existingKeys; | ||
|
|
||
|
|
||
| private String[] partitionPaths; | ||
| private int numExistingKeys; | ||
|
|
||
| public HoodieDataGenerator(String[] partitionPaths) { | ||
| this(partitionPaths, new HashMap<>()); | ||
| } | ||
|
|
||
| public HoodieDataGenerator() { | ||
| this(DEFAULT_PARTITION_PATHS); | ||
| } | ||
|
|
||
| public HoodieDataGenerator(String[] partitionPaths, Map<Integer, KeyPartition> keyPartitionMap) { | ||
| this.partitionPaths = Arrays.copyOf(partitionPaths, partitionPaths.length); | ||
| this.existingKeys = keyPartitionMap; | ||
| } | ||
|
|
||
| public String getAvroSchemaString() { | ||
| return "{\"type\": \"record\",\"name\": \"triprec\",\"fields\": [ " | ||
| + "{\"name\": \"ts\",\"type\": \"long\"},{\"name\": \"uuid\", \"type\": \"string\"}," | ||
| + "{\"name\": \"rider\", \"type\": \"string\"},{\"name\": \"driver\", \"type\": \"string\"}," | ||
| + "{\"name\": \"begin_lat\", \"type\": \"double\"},{\"name\": \"begin_lon\", \"type\": \"double\"}," | ||
| + "{\"name\": \"end_lat\", \"type\": \"double\"},{\"name\": \"end_lon\", \"type\": \"double\"}," | ||
| + "{\"name\":\"fare\",\"type\": \"double\"}]}"; | ||
| } | ||
|
|
||
| public Schema getAvroSchema() { | ||
| return new Schema.Parser().parse(getAvroSchemaString()); | ||
| } | ||
|
|
||
| /** | ||
| * Generates a new avro record of the above schema format, retaining the key if optionally provided. | ||
| */ | ||
| @SuppressWarnings("unchecked") | ||
| public T generateRandomValue(HoodieKey key, String commitTime) { | ||
| GenericRecord rec = generateGenericRecord(key.getRecordKey(), "rider-" + commitTime, "driver-" + commitTime, 0); | ||
| return (T) new HoodieAvroPayload(Option.of(rec)); | ||
| } | ||
|
|
||
| public GenericRecord generateGenericRecord(String rowKey, String riderName, String driverName, | ||
| long timestamp) { | ||
| GenericRecord rec = new GenericData.Record(getAvroSchema()); | ||
| rec.put("uuid", rowKey); | ||
| rec.put("ts", timestamp); | ||
| rec.put("rider", riderName); | ||
| rec.put("driver", driverName); | ||
| rec.put("begin_lat", RAND.nextDouble()); | ||
| rec.put("begin_lon", RAND.nextDouble()); | ||
| rec.put("end_lat", RAND.nextDouble()); | ||
| rec.put("end_lon", RAND.nextDouble()); | ||
| rec.put("fare", RAND.nextDouble() * 100); | ||
| return rec; | ||
| } | ||
|
|
||
| /** | ||
| * Generates new inserts, uniformly across the partition paths above. It also updates the list of existing keys. | ||
| */ | ||
| public List<HoodieRecord<T>> generateInserts(String commitTime, Integer n) { | ||
| return generateInsertsStream(commitTime, n).collect(Collectors.toList()); | ||
| } | ||
|
|
||
| /** | ||
| * Generates new inserts, uniformly across the partition paths above. It also updates the list of existing keys. | ||
| */ | ||
| public Stream<HoodieRecord<T>> generateInsertsStream(String commitTime, Integer n) { | ||
| int currSize = getNumExistingKeys(); | ||
|
|
||
| return IntStream.range(0, n).boxed().map(i -> { | ||
| String partitionPath = partitionPaths[RAND.nextInt(partitionPaths.length)]; | ||
| HoodieKey key = new HoodieKey(UUID.randomUUID().toString(), partitionPath); | ||
| KeyPartition kp = new KeyPartition(); | ||
| kp.key = key; | ||
| kp.partitionPath = partitionPath; | ||
| existingKeys.put(currSize + i, kp); | ||
| numExistingKeys++; | ||
| return new HoodieAvroRecord<>(key, generateRandomValue(key, commitTime)); | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Generates new inserts, across a single partition path. It also updates the list of existing keys. | ||
| */ | ||
| public List<HoodieRecord<T>> generateInsertsOnPartition(String commitTime, Integer n, String partitionPath) { | ||
| return generateInsertsStreamOnPartition(commitTime, n, partitionPath).collect(Collectors.toList()); | ||
| } | ||
|
|
||
| /** | ||
| * Generates new inserts, across a single partition path. It also updates the list of existing keys. | ||
| */ | ||
| public Stream<HoodieRecord<T>> generateInsertsStreamOnPartition(String commitTime, Integer n, String partitionPath) { | ||
| int currSize = getNumExistingKeys(); | ||
|
|
||
| return IntStream.range(0, n).boxed().map(i -> { | ||
| HoodieKey key = new HoodieKey(UUID.randomUUID().toString(), partitionPath); | ||
| KeyPartition kp = new KeyPartition(); | ||
| kp.key = key; | ||
| kp.partitionPath = partitionPath; | ||
| existingKeys.put(currSize + i, kp); | ||
| numExistingKeys++; | ||
| return new HoodieAvroRecord<>(key, generateRandomValue(key, commitTime)); | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Generates new updates, randomly distributed across the keys above. There can be duplicates within the returned | ||
| * list | ||
| * | ||
| * @param commitTime Commit Timestamp | ||
| * @param n Number of updates (including dups) | ||
| * @return list of hoodie record updates | ||
| */ | ||
| public List<HoodieRecord<T>> generateUpdates(String commitTime, Integer n) { | ||
| List<HoodieRecord<T>> updates = new ArrayList<>(); | ||
| for (int i = 0; i < n; i++) { | ||
| KeyPartition kp = existingKeys.get(RAND.nextInt(numExistingKeys - 1)); | ||
| HoodieRecord<T> record = generateUpdateRecord(kp.key, commitTime); | ||
| updates.add(record); | ||
| } | ||
| return updates; | ||
| } | ||
|
|
||
| /** | ||
| * Generates new updates, one for each of the keys above | ||
| * list | ||
| * | ||
| * @param commitTime Commit Timestamp | ||
| * @return list of hoodie record updates | ||
| */ | ||
| public List<HoodieRecord<T>> generateUniqueUpdates(String commitTime) { | ||
| List<HoodieRecord<T>> updates = new ArrayList<>(); | ||
| for (int i = 0; i < numExistingKeys; i++) { | ||
| KeyPartition kp = existingKeys.get(i); | ||
| HoodieRecord<T> record = generateUpdateRecord(kp.key, commitTime); | ||
| updates.add(record); | ||
| } | ||
| return updates; | ||
| } | ||
|
|
||
| public HoodieRecord<T> generateUpdateRecord(HoodieKey key, String commitTime) { | ||
| return new HoodieAvroRecord<>(key, generateRandomValue(key, commitTime)); | ||
| } | ||
|
|
||
| public int getNumExistingKeys() { | ||
| return numExistingKeys; | ||
| } | ||
|
|
||
| public HoodieDataGenerator<T> setPartitionPaths(String[] partitionPaths) { | ||
| this.partitionPaths = partitionPaths; | ||
| return this; | ||
| } | ||
|
|
||
| public static class KeyPartition implements Serializable { | ||
|
|
||
| HoodieKey key; | ||
| String partitionPath; | ||
| } | ||
|
|
||
| public void close() { | ||
| existingKeys.clear(); | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@parisni : has this change been tested with real glue and emr setup?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not yet. Do you have insight why hadoop/hive depts were added ?