-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[HUDI-1284] preCombine all HoodieRecords and update all fields according to orderingVal #2106
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 24 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
6ddb4fc
t
Karl-WangSK 21f0d89
Description: feat: We met performance issue with foo module recently,…
Karl-WangSK c5f47c7
Merge remote-tracking branch 'update_stream/master'
Karl-WangSK 835fce8
feat: update preCombine
Karl-WangSK b548678
add test
Karl-WangSK e6efb8c
update
Karl-WangSK f9e3df9
preCombine all HoodieRecords and update all fields according to order…
Karl-WangSK ec6e8a2
update
Karl-WangSK a9d4831
update
Karl-WangSK de06b54
Merge branch 'master' into HUDI-1284
Karl-WangSK bf5f22b
update
Karl-WangSK ac7940d
Merge branch 'HUDI-1284' of github.com:Karl-WangSK/hudi into HUDI-1284
Karl-WangSK 54e2a08
update
Karl-WangSK 11323b2
Update DataSourceUtils.java
Karl-WangSK 94e9c5c
update
Karl-WangSK b574874
Merge branch 'master' into HUDI-1284
Karl-WangSK f678964
Update AbstractWriteHelper.java
Karl-WangSK cca47ce
update
Karl-WangSK 2e3e799
update
Karl-WangSK a6464f6
update
Karl-WangSK 02a2dfc
update
Karl-WangSK f142420
update
Karl-WangSK 1382b04
update
Karl-WangSK cf1de28
update
Karl-WangSK a75f293
add serializableSchema
Karl-WangSK c855aef
Merge branch 'master' into HUDI-1284
Karl-WangSK d8959f6
update
Karl-WangSK 10aa16c
Merge branch 'HUDI-1284' of github.com:Karl-WangSK/hudi into HUDI-1284
Karl-WangSK 427d0f3
update
Karl-WangSK bf9446f
update
Karl-WangSK d44f9e6
update
Karl-WangSK 2c8c08d
update
Karl-WangSK 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
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 |
|---|---|---|
|
|
@@ -18,10 +18,13 @@ | |
|
|
||
| package org.apache.hudi.table.action.commit; | ||
|
|
||
| import org.apache.avro.Schema; | ||
| import org.apache.hudi.client.WriteStatus; | ||
| 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.model.UpdatePrecombineAvroPayload; | ||
| import org.apache.hudi.common.util.Option; | ||
| import org.apache.hudi.index.HoodieIndex; | ||
|
|
||
| import org.apache.spark.api.java.JavaRDD; | ||
|
|
@@ -33,8 +36,8 @@ | |
| * | ||
| * @param <T> | ||
| */ | ||
| public class SparkWriteHelper<T extends HoodieRecordPayload,R> extends AbstractWriteHelper<T, JavaRDD<HoodieRecord<T>>, | ||
| JavaRDD<HoodieKey>, JavaRDD<WriteStatus>, R> { | ||
| public class SparkWriteHelper<T extends HoodieRecordPayload, R> extends AbstractWriteHelper<T, JavaRDD<HoodieRecord<T>>, | ||
| JavaRDD<HoodieKey>, JavaRDD<WriteStatus>, R> { | ||
| private SparkWriteHelper() { | ||
| } | ||
|
|
||
|
|
@@ -49,7 +52,7 @@ public static SparkWriteHelper newInstance() { | |
| @Override | ||
| public JavaRDD<HoodieRecord<T>> deduplicateRecords(JavaRDD<HoodieRecord<T>> records, | ||
| HoodieIndex<T, JavaRDD<HoodieRecord<T>>, JavaRDD<HoodieKey>, JavaRDD<WriteStatus>> index, | ||
| int parallelism) { | ||
| int parallelism, Option<String> schema) { | ||
| boolean isIndexingGlobal = index.isGlobal(); | ||
| return records.mapToPair(record -> { | ||
| HoodieKey hoodieKey = record.getKey(); | ||
|
|
@@ -58,7 +61,14 @@ public JavaRDD<HoodieRecord<T>> deduplicateRecords(JavaRDD<HoodieRecord<T>> reco | |
| return new Tuple2<>(key, record); | ||
| }).reduceByKey((rec1, rec2) -> { | ||
| @SuppressWarnings("unchecked") | ||
| T reducedData = (T) rec1.getData().preCombine(rec2.getData()); | ||
| T reducedData; | ||
| //To prevent every records from parsing schema | ||
| if (rec2.getData() instanceof UpdatePrecombineAvroPayload) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this prevent old payload impl from calling preCombine(_, schema) ? |
||
| reducedData = schema.isPresent() ? (T) rec1.getData().preCombine(rec2.getData(), new Schema.Parser().parse(schema.get())) | ||
| : (T) rec1.getData().preCombine(rec2.getData()); | ||
| } else { | ||
| reducedData = (T) rec1.getData().preCombine(rec2.getData()); | ||
| } | ||
| // we cannot allow the user to change the key or partitionPath, since that will affect | ||
| // everything | ||
| // so pick it from one of the records. | ||
|
|
||
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
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
69 changes: 69 additions & 0 deletions
69
hudi-common/src/main/java/org/apache/hudi/common/model/PartialAvroPayload.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,69 @@ | ||
| /* | ||
| * 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.common.model; | ||
|
|
||
| import org.apache.avro.Schema; | ||
| import org.apache.avro.generic.GenericRecord; | ||
| import org.apache.avro.generic.IndexedRecord; | ||
| import org.apache.hudi.common.util.Option; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * subclass of OverwriteWithLatestAvroPayload. | ||
| * | ||
| * Extract the function precombine of UpdatePrecombineAvroPayload and combineAndGetUpdateValue of OverwriteNonDefaultsWithLatestAvroPayload. | ||
| * Which means When more than one HoodieRecord have the same HoodieKey, this function will combine all fields(which is not null) | ||
| * Before attempting to insert/upsert And when insert/upsert into storage. | ||
| */ | ||
| public class PartialAvroPayload extends UpdatePrecombineAvroPayload { | ||
| public PartialAvroPayload(GenericRecord record, Comparable orderingVal) { | ||
| super(record, orderingVal); | ||
| } | ||
|
|
||
| public PartialAvroPayload(Option<GenericRecord> record) { | ||
| super(record); | ||
| } | ||
|
|
||
| @Override | ||
| public Option<IndexedRecord> combineAndGetUpdateValue(IndexedRecord currentValue, Schema schema) throws IOException { | ||
| Option<IndexedRecord> recordOption = getInsertValue(schema); | ||
| if (!recordOption.isPresent()) { | ||
| return Option.empty(); | ||
| } | ||
|
|
||
| GenericRecord insertRecord = (GenericRecord) recordOption.get(); | ||
| GenericRecord currentRecord = (GenericRecord) currentValue; | ||
|
|
||
| if (isDeleteRecord(insertRecord)) { | ||
| return Option.empty(); | ||
| } else { | ||
| List<Schema.Field> fields = schema.getFields(); | ||
| fields.forEach(field -> { | ||
| Object value = insertRecord.get(field.name()); | ||
| Object defaultValue = field.defaultVal(); | ||
| if (!overwriteField(value, defaultValue)) { | ||
| currentRecord.put(field.name(), value); | ||
| } | ||
| }); | ||
| return Option.of(currentRecord); | ||
| } | ||
| } | ||
| } |
84 changes: 84 additions & 0 deletions
84
hudi-common/src/main/java/org/apache/hudi/common/model/UpdatePrecombineAvroPayload.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,84 @@ | ||
| /* | ||
| * 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.common.model; | ||
|
|
||
| import org.apache.avro.Schema; | ||
| import org.apache.avro.generic.GenericRecord; | ||
| import org.apache.hudi.avro.HoodieAvroUtils; | ||
| import org.apache.hudi.common.util.Option; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * subclass of OverwriteWithLatestAvroPayload. | ||
| * | ||
| * <ol> | ||
| * <li>preCombine - When more than one HoodieRecord have the same HoodieKey, this function combines all fields(which is not null) | ||
| * before attempting to insert/upsert. | ||
| * eg: 1) | ||
| * Before: | ||
| * id name age ts | ||
| * 1 Karl null 0.0 | ||
| * 1 null 18 0.0 | ||
| * After: | ||
| * id name age ts | ||
| * 1 Karl 18 0.0 | ||
| * </ol> | ||
| */ | ||
| public class UpdatePrecombineAvroPayload extends OverwriteWithLatestAvroPayload { | ||
| public UpdatePrecombineAvroPayload(GenericRecord record, Comparable orderingVal) { | ||
| super(record, orderingVal); | ||
| } | ||
|
|
||
| public UpdatePrecombineAvroPayload(Option<GenericRecord> record) { | ||
| super(record); | ||
| } | ||
|
|
||
| @Override | ||
| public OverwriteWithLatestAvroPayload preCombine(OverwriteWithLatestAvroPayload another, Schema schema) throws IOException { | ||
| // pick the payload with greatest ordering value and aggregate all the fields,choosing the | ||
| // value that is not null | ||
| GenericRecord thisValue = HoodieAvroUtils.bytesToAvro(this.recordBytes, schema); | ||
| GenericRecord anotherValue = HoodieAvroUtils.bytesToAvro(another.recordBytes, schema); | ||
| List<Schema.Field> fields = schema.getFields(); | ||
|
|
||
| if (another.orderingVal.compareTo(orderingVal) > 0) { | ||
| GenericRecord anotherRoc = combineAllFields(fields, anotherValue, thisValue); | ||
| another.recordBytes = HoodieAvroUtils.avroToBytes(anotherRoc); | ||
| return another; | ||
| } else { | ||
| GenericRecord thisRoc = combineAllFields(fields, thisValue, anotherValue); | ||
| this.recordBytes = HoodieAvroUtils.avroToBytes(thisRoc); | ||
| return this; | ||
| } | ||
| } | ||
|
|
||
| public GenericRecord combineAllFields(List<Schema.Field> fields, GenericRecord priorRec, GenericRecord secPriorRoc) { | ||
| for (int i = 0; i < fields.size(); i++) { | ||
| Object priorValue = priorRec.get(fields.get(i).name()); | ||
| Object secPriorValue = secPriorRoc.get(fields.get(i).name()); | ||
| Object defaultVal = fields.get(i).defaultVal(); | ||
| if (overwriteField(priorValue, defaultVal) && !overwriteField(secPriorValue, defaultVal)) { | ||
| priorRec.put(fields.get(i).name(), secPriorValue); | ||
| } | ||
| } | ||
| return priorRec; | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.