bvaradar commented on a change in pull request #929: [HUDI-271] Create QuickstartUtils class towards simplifying quickstar… URL: https://github.com/apache/incubator-hudi/pull/929#discussion_r329309323
########## File path: hudi-spark/src/main/java/org/apache/hudi/QuickstartUtils.java ########## @@ -0,0 +1,319 @@ +/* + * 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; + +import com.fasterxml.jackson.databind.ObjectMapper; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +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; +import java.util.zip.Deflater; +import java.util.zip.DeflaterOutputStream; +import java.util.zip.InflaterInputStream; +import org.apache.avro.Schema; +import org.apache.avro.generic.GenericData; +import org.apache.avro.generic.GenericRecord; +import org.apache.avro.generic.IndexedRecord; +import org.apache.hudi.avro.MercifulJsonConverter; +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.FileIOUtils; +import org.apache.hudi.common.util.Option; +import org.apache.hudi.exception.HoodieIOException; + +/** + * Class to be used in quickstart guide for generating inserts and updates against a corpus. + * <p> + * Test data uses a toy Uber trips, data model. + * + */ +public class QuickstartUtils { + + public static class DataGenerator { + private static final String DEFAULT_FIRST_PARTITION_PATH = "2019/09/15"; + private static final String DEFAULT_SECOND_PARTITION_PATH = "2018/09/16"; + private static final String DEFAULT_THIRD_PARTITION_PATH = "2018/09/17"; + + private static final String[] DEFAULT_PARTITION_PATHS = { + DEFAULT_FIRST_PARTITION_PATH, + DEFAULT_SECOND_PARTITION_PATH, + DEFAULT_THIRD_PARTITION_PATH + }; + static String TRIP_EXAMPLE_SCHEMA = "{\"type\": \"record\"," + "\"name\": \"triprec\"," + "\"fields\": [ " + + "{\"name\": \"ts\",\"type\": \"double\"}," + + "{\"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\"}]}"; + static Schema avroSchema = new Schema.Parser().parse(TRIP_EXAMPLE_SCHEMA); + + private static Random rand = new Random(46474747); + + private final Map<Integer, KeyPartition> existingKeys; + private final String[] partitionPaths; + private int numExistingKeys; + + public DataGenerator() { + this(DEFAULT_PARTITION_PATHS, new HashMap<>()); + } + + private DataGenerator(String[] partitionPaths, Map<Integer, KeyPartition> keyPartitionMap) { + this.partitionPaths = Arrays.copyOf(partitionPaths, partitionPaths.length); + this.existingKeys = keyPartitionMap; + } + + private static String generateRandomCommitMsg() { Review comment: Minor: The word commit here is confusing with Hudi commit time. As we are not using instantTime here, can you rename it to getRandomString ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
