-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[HUDI-1234] Insert new records to data files without merging for "Insert" operation. #2111
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
Merged
nsivabalan
merged 10 commits into
apache:master
from
SteNicholas:upsert-partitioner-insert
Jan 27, 2021
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f7d52e7
[HUDI-1234] Insert new records regardless of small file when using in…
SteNicholas 7f742ee
[HUDI-1234] Insert new records regardless of small file when using in…
SteNicholas dde11ef
[HUDI-1234] Insert new records regardless of small file when using in…
SteNicholas c466a22
Adding a config flag to route inserts to new files ignoring small fil…
nsivabalan 591e97e
Adding HoodieConcatHandle to insert records w/o merging with "Insert"…
nsivabalan 39123ef
Reverting some of previous changes
nsivabalan 09fcaa1
Fixing tests in TestHoodieClientOnCopyOnWriteStorage.java
nsivabalan 4c5d84c
Minor fixes
nsivabalan 1eec9b1
Addressing comments
nsivabalan 287a016
Fetching and rebasing with master
nsivabalan 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
94 changes: 94 additions & 0 deletions
94
...lient/hudi-client-common/src/main/java/org/apache/hudi/io/storage/HoodieConcatHandle.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,94 @@ | ||
| /* | ||
| * 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.storage; | ||
|
|
||
| import org.apache.hudi.common.engine.TaskContextSupplier; | ||
| import org.apache.hudi.common.model.HoodieBaseFile; | ||
| import org.apache.hudi.common.model.HoodieRecord; | ||
| import org.apache.hudi.common.model.HoodieRecordPayload; | ||
| import org.apache.hudi.config.HoodieWriteConfig; | ||
| import org.apache.hudi.exception.HoodieUpsertException; | ||
| import org.apache.hudi.io.HoodieMergeHandle; | ||
| import org.apache.hudi.table.HoodieTable; | ||
|
|
||
| import org.apache.avro.generic.GenericRecord; | ||
| import org.apache.log4j.LogManager; | ||
| import org.apache.log4j.Logger; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Iterator; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * Handle to concatenate new records to old records w/o any merging. If Operation is set to Inserts, and if {{@link HoodieWriteConfig#allowDuplicateInserts()}} | ||
| * is set, this handle will be used instead of {@link HoodieMergeHandle}. | ||
| * | ||
| * Simplified Logic: | ||
| * For every existing record | ||
| * Write the record as is | ||
| * For all incoming records, write to file as is. | ||
| * | ||
| * Illustration with simple data. | ||
| * Incoming data: | ||
| * rec1_2, rec4_2, rec5_1, rec6_1 | ||
| * Existing data: | ||
| * rec1_1, rec2_1, rec3_1, rec4_1 | ||
| * | ||
| * For every existing record, write to storage as is. | ||
| * => rec1_1, rec2_1, rec3_1 and rec4_1 is written to storage | ||
| * Write all records from incoming set to storage | ||
| * => rec1_2, rec4_2, rec5_1 and rec6_1 | ||
| * | ||
| * Final snapshot in storage | ||
| * rec1_1, rec2_1, rec3_1, rec4_1, rec1_2, rec4_2, rec5_1, rec6_1 | ||
| * | ||
| * Users should ensure there are no duplicates when "insert" operation is used and if the respective config is enabled. So, above scenario should not | ||
| * happen and every batch should have new records to be inserted. Above example is for illustration purposes only. | ||
| */ | ||
| public class HoodieConcatHandle<T extends HoodieRecordPayload, I, K, O> extends HoodieMergeHandle<T, I, K, O> { | ||
|
|
||
| private static final Logger LOG = LogManager.getLogger(HoodieConcatHandle.class); | ||
|
|
||
| public HoodieConcatHandle(HoodieWriteConfig config, String instantTime, HoodieTable hoodieTable, Iterator recordItr, | ||
| String partitionPath, String fileId, TaskContextSupplier taskContextSupplier) { | ||
| super(config, instantTime, hoodieTable, recordItr, partitionPath, fileId, taskContextSupplier); | ||
| } | ||
|
|
||
| public HoodieConcatHandle(HoodieWriteConfig config, String instantTime, HoodieTable hoodieTable, Map keyToNewRecords, String partitionPath, String fileId, | ||
| HoodieBaseFile dataFileToBeMerged, TaskContextSupplier taskContextSupplier) { | ||
| super(config, instantTime, hoodieTable, keyToNewRecords, partitionPath, fileId, dataFileToBeMerged, taskContextSupplier); | ||
| } | ||
|
|
||
| /** | ||
| * Write old record as is w/o merging with incoming record. | ||
| */ | ||
| @Override | ||
| public void write(GenericRecord oldRecord) { | ||
| String key = oldRecord.get(HoodieRecord.RECORD_KEY_METADATA_FIELD).toString(); | ||
| try { | ||
| fileWriter.writeAvro(key, oldRecord); | ||
| } catch (IOException | RuntimeException e) { | ||
| String errMsg = String.format("Failed to write old record into new file for key %s from old file %s to new file %s with writerSchema %s", | ||
| key, getOldFilePath(), newFilePath, writerSchemaWithMetafields.toString(true)); | ||
| LOG.debug("Old record is " + oldRecord); | ||
| throw new HoodieUpsertException(errMsg, e); | ||
| } | ||
| recordsWritten++; | ||
| } | ||
| } | ||
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
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.
@vinothchandar : Have added this new handle and tested that it works as expected. But would like to call out that any new records would just get appended. For instance, if records to be deleted (with "_hoodie_is_deleted" set to true) are sent via "Insert" operation, this handle will just append and may not recognize the deleted records as we don't do any combineAndUpdate.