vinothchandar commented on a change in pull request #1678: URL: https://github.com/apache/hudi/pull/1678#discussion_r439521898
########## File path: hudi-client/src/main/java/org/apache/hudi/keygen/KeyGenUtils.java ########## @@ -0,0 +1,110 @@ +/* + * 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.keygen; + +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.util.List; +import org.apache.avro.generic.GenericRecord; +import org.apache.hudi.avro.HoodieAvroUtils; +import org.apache.hudi.exception.HoodieException; +import org.apache.hudi.exception.HoodieKeyException; + +public class KeyGenUtils { Review comment: this is similar to the some work pratyaksh was doing as well.. We need to probably reconcile these at some point ########## File path: hudi-client/src/main/java/org/apache/hudi/config/HoodieBootstrapConfig.java ########## @@ -0,0 +1,135 @@ +/* + * 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.config; + +import org.apache.hudi.client.bootstrap.BootstrapMode; +import org.apache.hudi.client.bootstrap.selector.MetadataOnlyBootstrapModeSelector; +import org.apache.hudi.client.bootstrap.translator.IdentityBootstrapPathTranslator; +import org.apache.hudi.common.config.DefaultHoodieConfig; + +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.Properties; + +/** + * Bootstrap specific configs. + */ +public class HoodieBootstrapConfig extends DefaultHoodieConfig { + + public static final String SOURCE_BASE_PATH_PROP = "hoodie.bootstrap.source.base.path"; Review comment: Do we need the ‘.source’? Just call this bootstrap.basepath? ########## File path: hudi-client/src/main/java/org/apache/hudi/config/HoodieWriteConfig.java ########## @@ -835,18 +892,25 @@ public HoodieWriteConfig build() { setDefaultOnCondition(props, !isCompactionConfigSet, HoodieCompactionConfig.newBuilder().fromProperties(props).build()); setDefaultOnCondition(props, !isMetricsConfigSet, HoodieMetricsConfig.newBuilder().fromProperties(props).build()); + setDefaultOnCondition(props, !isBootstrapConfigSet, + HoodieBootstrapConfig.newBuilder().fromProperties(props).build()); setDefaultOnCondition(props, !isMemoryConfigSet, HoodieMemoryConfig.newBuilder().fromProperties(props).build()); setDefaultOnCondition(props, !isViewConfigSet, FileSystemViewStorageConfig.newBuilder().fromProperties(props).build()); setDefaultOnCondition(props, !isConsistencyGuardSet, ConsistencyGuardConfig.newBuilder().fromProperties(props).build()); + setDefaultOnCondition(props, !props.containsKey(EXTERNAL_RECORD_AND_SCHEMA_TRANSFORMATION), + EXTERNAL_RECORD_AND_SCHEMA_TRANSFORMATION, DEFAULT_EXTERNAL_RECORD_AND_SCHEMA_TRANSFORMATION); setDefaultOnCondition(props, !props.containsKey(TIMELINE_LAYOUT_VERSION), TIMELINE_LAYOUT_VERSION, String.valueOf(TimelineLayoutVersion.CURR_VERSION)); String layoutVersion = props.getProperty(TIMELINE_LAYOUT_VERSION); // Ensure Layout Version is good new TimelineLayoutVersion(Integer.parseInt(layoutVersion)); Review comment: should probably also break validation into its own method? ########## File path: hudi-client/src/main/java/org/apache/hudi/keygen/KeyGenerator.java ########## @@ -0,0 +1,93 @@ +/* + * 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.keygen; + +import java.util.List; +import java.util.stream.Collectors; +import org.apache.hudi.common.config.TypedProperties; +import org.apache.hudi.common.model.HoodieKey; + +import org.apache.avro.generic.GenericRecord; + +import java.io.Serializable; +import org.apache.hudi.exception.HoodieKeyException; + +/** + * Abstract class to extend for plugging in extraction of {@link HoodieKey} from an Avro record. + */ +public abstract class KeyGenerator implements Serializable { + + protected transient TypedProperties config; + + protected KeyGenerator(TypedProperties config) { + this.config = config; + } + + /** + * Generate a record Key out of provided generic record. + */ + public abstract String getRecordKey(GenericRecord record); + + /** + * Generate a partition path out of provided generic record. + */ + public abstract String getPartitionPath(GenericRecord record); + + /** + * Generate a Hoodie Key out of provided generic record. + */ + public final HoodieKey getKey(GenericRecord record) { + if (getRecordKeyFields() == null || getPartitionPathFields() == null) { + throw new HoodieKeyException("Unable to find field names for record key or partition path in cfg"); + } + return new HoodieKey(getRecordKey(record), getPartitionPath(record)); + } + + /** + * Used by Metadata bootstrap. + * @return + */ + public final List<String> getTopLevelRecordKeyFields() { + // For nested columns, pick top level column name + return getRecordKeyFields().stream().map(k -> { + int idx = k.indexOf('.'); + return idx > 0 ? k.substring(0, idx) : k; + }).collect(Collectors.toList()); + } + + /** + * Return fields that constitute record key. Used by Metadata bootstrap. + * Have a base implementation inorder to prevent forcing custom KeyGenerator implementation + * to implement this method + * @return list of record key fields + */ + public List<String> getRecordKeyFields() { Review comment: so the custom KeyGenerators out there will break for bootstrap until they implement these methods? its best to avoid that ########## File path: hudi-client/src/main/java/org/apache/hudi/config/HoodieBootstrapConfig.java ########## @@ -0,0 +1,135 @@ +/* + * 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.config; + +import org.apache.hudi.client.bootstrap.BootstrapMode; +import org.apache.hudi.client.bootstrap.selector.MetadataOnlyBootstrapModeSelector; +import org.apache.hudi.client.bootstrap.translator.IdentityBootstrapPathTranslator; +import org.apache.hudi.common.config.DefaultHoodieConfig; + +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.Properties; + +/** + * Bootstrap specific configs. + */ +public class HoodieBootstrapConfig extends DefaultHoodieConfig { + + public static final String SOURCE_BASE_PATH_PROP = "hoodie.bootstrap.source.base.path"; + public static final String BOOTSTRAP_MODE_SELECTOR = "hoodie.bootstrap.mode.selector"; + public static final String FULL_BOOTRAP_INPUT_PROVIDER = "hoodie.bootstrap.full.input.provider"; + public static final String BOOTSTRAP_KEYGEN_CLASS = "hoodie.bootstrap.keygen.class"; Review comment: Then, why not re-use the keygen supplied for regular upsert? ########## File path: hudi-client/src/main/java/org/apache/hudi/keygen/KeyGenerator.java ########## @@ -0,0 +1,93 @@ +/* + * 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.keygen; + +import java.util.List; +import java.util.stream.Collectors; +import org.apache.hudi.common.config.TypedProperties; +import org.apache.hudi.common.model.HoodieKey; + +import org.apache.avro.generic.GenericRecord; + +import java.io.Serializable; +import org.apache.hudi.exception.HoodieKeyException; + +/** + * Abstract class to extend for plugging in extraction of {@link HoodieKey} from an Avro record. + */ +public abstract class KeyGenerator implements Serializable { + + protected transient TypedProperties config; + + protected KeyGenerator(TypedProperties config) { + this.config = config; + } + + /** + * Generate a record Key out of provided generic record. + */ + public abstract String getRecordKey(GenericRecord record); + + /** + * Generate a partition path out of provided generic record. + */ + public abstract String getPartitionPath(GenericRecord record); + + /** + * Generate a Hoodie Key out of provided generic record. + */ + public final HoodieKey getKey(GenericRecord record) { + if (getRecordKeyFields() == null || getPartitionPathFields() == null) { + throw new HoodieKeyException("Unable to find field names for record key or partition path in cfg"); + } + return new HoodieKey(getRecordKey(record), getPartitionPath(record)); + } + + /** + * Used by Metadata bootstrap. + * @return + */ + public final List<String> getTopLevelRecordKeyFields() { Review comment: lets move this to some place else? better to avoid such feature specific methods in a external facing class ########## File path: hudi-client/src/main/java/org/apache/hudi/keygen/KeyGenerator.java ########## @@ -0,0 +1,93 @@ +/* + * 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.keygen; + +import java.util.List; +import java.util.stream.Collectors; +import org.apache.hudi.common.config.TypedProperties; +import org.apache.hudi.common.model.HoodieKey; + +import org.apache.avro.generic.GenericRecord; + +import java.io.Serializable; +import org.apache.hudi.exception.HoodieKeyException; + +/** + * Abstract class to extend for plugging in extraction of {@link HoodieKey} from an Avro record. + */ +public abstract class KeyGenerator implements Serializable { + + protected transient TypedProperties config; + + protected KeyGenerator(TypedProperties config) { + this.config = config; + } + + /** + * Generate a record Key out of provided generic record. + */ + public abstract String getRecordKey(GenericRecord record); Review comment: this is a problem.. it will break every KeyGenerator out there.. because they don't implement these methods.. we cannot have these two methods be `abstract`.. Why can we just get teh key/pp after calling getKey() ########## File path: hudi-client/src/main/java/org/apache/hudi/io/HoodieWriteHandle.java ########## @@ -59,18 +60,31 @@ public HoodieWriteHandle(HoodieWriteConfig config, String instantTime, String partitionPath, String fileId, HoodieTable<T> hoodieTable, SparkTaskContextSupplier sparkTaskContextSupplier) { + this(config, instantTime, partitionPath, fileId, hoodieTable, generateOriginalAndHoodieWriteSchema(config), + sparkTaskContextSupplier); + } + + protected HoodieWriteHandle(HoodieWriteConfig config, String instantTime, String partitionPath, String fileId, + HoodieTable<T> hoodieTable, Pair<Schema, Schema> originalAndHoodieSchema, + SparkTaskContextSupplier sparkTaskContextSupplier) { super(config, instantTime, hoodieTable); this.partitionPath = partitionPath; this.fileId = fileId; - this.originalSchema = new Schema.Parser().parse(config.getSchema()); - this.writerSchema = HoodieAvroUtils.createHoodieWriteSchema(originalSchema); + this.originalSchema = originalAndHoodieSchema.getKey(); + this.writerSchema = originalAndHoodieSchema.getValue(); this.timer = new HoodieTimer().startTimer(); this.writeStatus = (WriteStatus) ReflectionUtils.loadClass(config.getWriteStatusClassName(), !hoodieTable.getIndex().isImplicitWithStorage(), config.getWriteStatusFailureFraction()); this.sparkTaskContextSupplier = sparkTaskContextSupplier; this.writeToken = makeWriteToken(); } + protected static Pair<Schema, Schema> generateOriginalAndHoodieWriteSchema(HoodieWriteConfig config) { + Schema originalSchema = new Schema.Parser().parse(config.getSchema()); + Schema hoodieSchema = HoodieAvroUtils.addMetadataFields(originalSchema); Review comment: why don't we just call these : writerSchema , writeSchemaWithMetaFields? ########## File path: hudi-client/src/main/java/org/apache/hudi/io/HoodieBootstrapHandle.java ########## @@ -0,0 +1,42 @@ +/* + * 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.io; + +import org.apache.hudi.avro.HoodieAvroUtils; +import org.apache.hudi.client.SparkTaskContextSupplier; +import org.apache.hudi.common.model.HoodieRecord; +import org.apache.hudi.common.model.HoodieRecordPayload; +import org.apache.hudi.common.util.collection.Pair; +import org.apache.hudi.config.HoodieWriteConfig; +import org.apache.hudi.table.HoodieTable; + +public class HoodieBootstrapHandle<T extends HoodieRecordPayload> extends HoodieCreateHandle<T> { Review comment: its not obvious looking at this class, what it does.. may be more comments? for e,g why have `canWrite()` always return true ########## File path: hudi-client/src/main/java/org/apache/hudi/io/HoodieCreateHandle.java ########## @@ -57,7 +59,14 @@ public HoodieCreateHandle(HoodieWriteConfig config, String instantTime, HoodieTable<T> hoodieTable, String partitionPath, String fileId, SparkTaskContextSupplier sparkTaskContextSupplier) { - super(config, instantTime, partitionPath, fileId, hoodieTable, sparkTaskContextSupplier); + this(config, instantTime, hoodieTable, partitionPath, fileId, generateOriginalAndHoodieWriteSchema(config), Review comment: if possible, can we rename `original` to be something more meaningful.. it does not really tell me what that schema is.. is it the schema the prev version of the file was written with ########## File path: hudi-client/src/main/java/org/apache/hudi/client/utils/MergingParquetIterator.java ########## @@ -0,0 +1,48 @@ +/* + * 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.client.utils; + +import java.util.Iterator; +import java.util.function.Function; +import org.apache.avro.generic.GenericRecord; +import org.apache.hudi.common.util.collection.Pair; + +public class MergingParquetIterator<T extends GenericRecord> implements Iterator<T> { + + private final ParquetReaderIterator<T> leftFileReader; + private final ParquetReaderIterator<T> rightFileReader; + private final Function<Pair<T,T>, T> mergeFunction; + + public MergingParquetIterator(ParquetReaderIterator<T> leftFileReader, + ParquetReaderIterator<T> rightFileReader, Function<Pair<T,T>, T> mergeFunction) { + this.leftFileReader = leftFileReader; + this.rightFileReader = rightFileReader; + this.mergeFunction = mergeFunction; + } + + @Override + public boolean hasNext() { + return leftFileReader.hasNext(); Review comment: Why is it ok to just base this on left ########## File path: hudi-client/src/main/java/org/apache/hudi/config/HoodieBootstrapConfig.java ########## @@ -0,0 +1,135 @@ +/* + * 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.config; + +import org.apache.hudi.client.bootstrap.BootstrapMode; +import org.apache.hudi.client.bootstrap.selector.MetadataOnlyBootstrapModeSelector; +import org.apache.hudi.client.bootstrap.translator.IdentityBootstrapPathTranslator; +import org.apache.hudi.common.config.DefaultHoodieConfig; + +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.Properties; + +/** + * Bootstrap specific configs. + */ +public class HoodieBootstrapConfig extends DefaultHoodieConfig { + + public static final String SOURCE_BASE_PATH_PROP = "hoodie.bootstrap.source.base.path"; + public static final String BOOTSTRAP_MODE_SELECTOR = "hoodie.bootstrap.mode.selector"; + public static final String FULL_BOOTRAP_INPUT_PROVIDER = "hoodie.bootstrap.full.input.provider"; Review comment: this is. fine I think.. something to think about is : we should be able to add support for bootstrapping from another hudi table even, easily. Imagine a scenario where someone wants to change from bloom index to hbase index.. are the abstractions setup to support something. like that? ---------------------------------------------------------------- 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]
