-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[Minor] fix multi deser avro payload #7021
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
Changes from 3 commits
543f954
311bace
06cbb49
cd9d505
c258773
81888ad
f634430
8246920
a63d515
a357703
18e31f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /* | ||
| * 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.IndexedRecord; | ||
| import org.apache.hudi.common.util.Option; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| /** | ||
| * Default payload used in HoodieAvroRecord. We dont need to serialize/deserialize avro record in payload multiple times. | ||
| */ | ||
| public class HoodieAvroInsertValuePayload implements HoodieRecordPayload<RewriteAvroPayload> { | ||
|
|
||
| private Option<IndexedRecord> record; | ||
|
|
||
| public HoodieAvroInsertValuePayload(Option<IndexedRecord> record) { | ||
| this.record = record; | ||
| } | ||
|
|
||
| @Override | ||
| public RewriteAvroPayload preCombine(RewriteAvroPayload another) { | ||
| throw new UnsupportedOperationException("precombine is not expected for HoodieAvroInsertValuePayload"); | ||
| } | ||
|
|
||
| @Override | ||
| public Option<IndexedRecord> combineAndGetUpdateValue(IndexedRecord currentValue, Schema schema) throws IOException { | ||
| throw new UnsupportedOperationException("combineAndGetUpdateValue is not expected for HoodieAvroInsertValuePayload"); | ||
| } | ||
|
|
||
| @Override | ||
| public Option<IndexedRecord> getInsertValue(Schema schema) throws IOException { | ||
| return record; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ | |
| import org.apache.hudi.common.util.Option; | ||
| import org.apache.hudi.common.util.StringUtils; | ||
| import org.apache.hudi.common.util.collection.Pair; | ||
| import org.apache.hudi.exception.HoodieException; | ||
| import org.apache.hudi.keygen.BaseKeyGenerator; | ||
|
|
||
| import org.apache.avro.Schema; | ||
|
|
@@ -51,6 +52,15 @@ public HoodieAvroRecord(HoodieRecord<T> record) { | |
| super(record); | ||
| } | ||
|
|
||
| public HoodieAvroRecord( | ||
| HoodieKey key, | ||
| T data, | ||
| HoodieOperation operation, | ||
| HoodieRecordLocation currentLocation, | ||
| HoodieRecordLocation newLocation) { | ||
| super(key, data, operation, currentLocation, newLocation); | ||
| } | ||
|
|
||
| public HoodieAvroRecord() { | ||
| } | ||
|
|
||
|
|
@@ -113,14 +123,14 @@ public HoodieRecord rewriteRecord(Schema recordSchema, Properties props, Schema | |
| Option<IndexedRecord> avroRecordPayloadOpt = getData().getInsertValue(recordSchema, props); | ||
| GenericRecord avroPayloadInNewSchema = | ||
| HoodieAvroUtils.rewriteRecord((GenericRecord) avroRecordPayloadOpt.get(), targetSchema); | ||
| return new HoodieAvroRecord<>(getKey(), new RewriteAvroPayload(avroPayloadInNewSchema), getOperation()); | ||
| return new HoodieAvroRecord<>(getKey(), new RewriteAvroPayload(avroPayloadInNewSchema), getOperation(), this.currentLocation, this.newLocation); | ||
| } | ||
|
|
||
| @Override | ||
| public HoodieRecord rewriteRecordWithNewSchema(Schema recordSchema, Properties props, Schema newSchema, Map<String, String> renameCols) throws IOException { | ||
| GenericRecord oldRecord = (GenericRecord) getData().getInsertValue(recordSchema, props).get(); | ||
| GenericRecord rewriteRecord = HoodieAvroUtils.rewriteRecordWithNewSchema(oldRecord, newSchema, renameCols); | ||
| return new HoodieAvroRecord<>(getKey(), new RewriteAvroPayload(rewriteRecord), getOperation()); | ||
| return new HoodieAvroRecord<>(getKey(), new RewriteAvroPayload(rewriteRecord), getOperation(), this.currentLocation, this.newLocation); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -133,23 +143,29 @@ public HoodieRecord updateMetadataValues(Schema recordSchema, Properties props, | |
| } | ||
| }); | ||
|
|
||
| return new HoodieAvroRecord<>(getKey(), new RewriteAvroPayload(avroRecordPayload), getOperation()); | ||
| return new HoodieAvroRecord<>(getKey(), new RewriteAvroPayload(avroRecordPayload), getOperation(), this.currentLocation, this.newLocation); | ||
| } | ||
|
|
||
| @Override | ||
| public HoodieRecord truncateRecordKey(Schema recordSchema, Properties props, String keyFieldName) throws IOException { | ||
| GenericRecord avroRecordPayload = (GenericRecord) getData().getInsertValue(recordSchema, props).get(); | ||
| avroRecordPayload.put(keyFieldName, StringUtils.EMPTY_STRING); | ||
| return new HoodieAvroRecord<>(getKey(), new RewriteAvroPayload(avroRecordPayload), getOperation()); | ||
| return new HoodieAvroRecord<>(getKey(), new RewriteAvroPayload(avroRecordPayload), getOperation(), this.currentLocation, this.newLocation); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isDelete(Schema recordSchema, Properties props) throws IOException { | ||
| if (!(data instanceof HoodieAvroInsertValuePayload) && !(data instanceof RewriteAvroPayload)) { | ||
| throw new HoodieException("We should deserialization before calling isDelete"); | ||
|
Contributor
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. Why do we want to enforce this?
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. HoodieAvroRecord#isDelete or shouldIgnore will deserialize HoodiePayload. And we will deserialize it again when we write it to the file. So we should call deserialization before calling them. |
||
| } | ||
| return !getData().getInsertValue(recordSchema, props).isPresent(); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean shouldIgnore(Schema recordSchema, Properties props) throws IOException { | ||
| if (!(data instanceof HoodieAvroInsertValuePayload) && !(data instanceof RewriteAvroPayload)) { | ||
| throw new HoodieException("We should deserialization before calling shouldIgnore"); | ||
| } | ||
| Option<IndexedRecord> insertRecord = getData().getInsertValue(recordSchema, props); | ||
| // just skip the ignored record | ||
| if (insertRecord.isPresent() && insertRecord.get().equals(SENTINEL)) { | ||
|
|
@@ -197,6 +213,15 @@ public Option<HoodieAvroIndexedRecord> toIndexedRecord(Schema recordSchema, Prop | |
| } | ||
| } | ||
|
|
||
| @Override | ||
| public HoodieRecord deserialization(Schema recordSchema, Properties props) throws IOException { | ||
| if (this.data instanceof RewriteAvroPayload || this.data instanceof HoodieAvroInsertValuePayload) { | ||
| return this; | ||
| } | ||
| Option<IndexedRecord> data = this.data.getInsertValue(recordSchema, props); | ||
| return new HoodieAvroRecord<>(getKey(), new HoodieAvroInsertValuePayload(data), getOperation(), this.currentLocation, this.newLocation); | ||
| } | ||
|
|
||
| @Override | ||
| protected final void writeRecordPayload(T payload, Kryo kryo, Output output) { | ||
| // NOTE: Since [[orderingVal]] is polymorphic we have to write out its class | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.