-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[HUDI-5189] Make HiveAvroSerializer compatible with hive3 #7173
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
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
105 changes: 105 additions & 0 deletions
105
hudi-hadoop-mr/src/main/java/org/apache/hudi/hadoop/avro/HoodieAvroParquetReader.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,105 @@ | ||
| /* | ||
| * 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.hadoop.avro; | ||
|
|
||
| import org.apache.avro.Schema; | ||
| import org.apache.avro.generic.GenericData; | ||
| import org.apache.avro.generic.GenericRecord; | ||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.io.ArrayWritable; | ||
| import org.apache.hadoop.mapreduce.InputSplit; | ||
| import org.apache.hadoop.mapreduce.RecordReader; | ||
| import org.apache.hadoop.mapreduce.TaskAttemptContext; | ||
| import org.apache.hudi.hadoop.HoodieColumnProjectionUtils; | ||
| import org.apache.hudi.hadoop.utils.HoodieRealtimeRecordReaderUtils; | ||
| import org.apache.parquet.avro.AvroReadSupport; | ||
| import org.apache.parquet.avro.AvroSchemaConverter; | ||
| import org.apache.parquet.format.converter.ParquetMetadataConverter; | ||
| import org.apache.parquet.hadoop.ParquetFileReader; | ||
| import org.apache.parquet.hadoop.ParquetInputSplit; | ||
| import org.apache.parquet.hadoop.ParquetRecordReader; | ||
| import org.apache.parquet.hadoop.metadata.ParquetMetadata; | ||
| import org.apache.parquet.schema.MessageType; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import static org.apache.parquet.hadoop.ParquetInputFormat.getFilter; | ||
|
|
||
| public class HoodieAvroParquetReader extends RecordReader<Void, ArrayWritable> { | ||
|
|
||
| private final ParquetRecordReader<GenericData.Record> parquetRecordReader; | ||
| private Schema baseSchema; | ||
|
|
||
| public HoodieAvroParquetReader(InputSplit inputSplit, Configuration conf) throws IOException { | ||
| AvroReadSupport avroReadSupport = new AvroReadSupport<>(); | ||
| // if exists read columns, we need to filter columns. | ||
| List<String> readColNames = Arrays.asList(HoodieColumnProjectionUtils.getReadColumnNames(conf)); | ||
| if (!readColNames.isEmpty()) { | ||
| // get base schema | ||
| ParquetMetadata fileFooter = | ||
| ParquetFileReader.readFooter(conf, ((ParquetInputSplit) inputSplit).getPath(), ParquetMetadataConverter.NO_FILTER); | ||
| MessageType messageType = fileFooter.getFileMetaData().getSchema(); | ||
| baseSchema = new AvroSchemaConverter(conf).convert(messageType); | ||
| // filter schema for reading | ||
| final Schema filterSchema = Schema.createRecord(baseSchema.getName(), | ||
| baseSchema.getDoc(), baseSchema.getNamespace(), baseSchema.isError(), | ||
| baseSchema.getFields().stream() | ||
| .filter(f -> readColNames.contains(f.name())) | ||
| .map(f -> new Schema.Field(f.name(), f.schema(), f.doc(), f.defaultVal())) | ||
| .collect(Collectors.toList())); | ||
| avroReadSupport.setAvroReadSchema(conf, filterSchema); | ||
| avroReadSupport.setRequestedProjection(conf, filterSchema); | ||
| } | ||
| parquetRecordReader = new ParquetRecordReader<>(avroReadSupport, getFilter(conf)); | ||
| } | ||
|
|
||
| @Override | ||
| public void initialize(InputSplit split, TaskAttemptContext context) throws IOException, InterruptedException { | ||
| parquetRecordReader.initialize(split, context); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean nextKeyValue() throws IOException, InterruptedException { | ||
| return parquetRecordReader.nextKeyValue(); | ||
| } | ||
|
|
||
| @Override | ||
| public Void getCurrentKey() throws IOException, InterruptedException { | ||
| return parquetRecordReader.getCurrentKey(); | ||
| } | ||
|
|
||
| @Override | ||
| public ArrayWritable getCurrentValue() throws IOException, InterruptedException { | ||
| GenericRecord record = parquetRecordReader.getCurrentValue(); | ||
| return (ArrayWritable) HoodieRealtimeRecordReaderUtils.avroToArrayWritable(record, baseSchema, true); | ||
| } | ||
|
|
||
| @Override | ||
| public float getProgress() throws IOException, InterruptedException { | ||
| return parquetRecordReader.getProgress(); | ||
| } | ||
|
|
||
| @Override | ||
| public void close() throws IOException { | ||
| parquetRecordReader.close(); | ||
| } | ||
| } |
44 changes: 44 additions & 0 deletions
44
...-mr/src/main/java/org/apache/hudi/hadoop/avro/HoodieTimestampAwareParquetInputFormat.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,44 @@ | ||
| /* | ||
| * 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.hadoop.avro; | ||
|
|
||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.io.ArrayWritable; | ||
| import org.apache.hadoop.mapreduce.InputSplit; | ||
| import org.apache.hadoop.mapreduce.RecordReader; | ||
| import org.apache.hadoop.mapreduce.TaskAttemptContext; | ||
| import org.apache.parquet.hadoop.ParquetInputFormat; | ||
| import org.apache.parquet.hadoop.util.ContextUtil; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| /** | ||
| * To resolve issue <a href="https://issues.apache.org/jira/browse/HUDI-83">Fix Timestamp/Date type read by Hive3</a>, | ||
| * we need to handle timestamp types separately based on the parquet-avro approach. | ||
| */ | ||
| public class HoodieTimestampAwareParquetInputFormat extends ParquetInputFormat<ArrayWritable> { | ||
|
|
||
| @Override | ||
| public RecordReader<Void, ArrayWritable> createRecordReader( | ||
| InputSplit inputSplit, | ||
| TaskAttemptContext taskAttemptContext) throws IOException { | ||
| Configuration conf = ContextUtil.getConfiguration(taskAttemptContext); | ||
| return new HoodieAvroParquetReader(inputSplit, conf); | ||
| } | ||
| } |
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
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.
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.
when will
supportAvroReadbe false? I add a pr for it~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.
@Zouxxyy You can read the comments. This is to address compatibility issues with spark
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.
yeal, but it always be true now
Uh oh!
There was an error while loading. Please reload this page.
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.
@Zouxxyy
In my impression, hive2 and spark3 have the same processing method and constructor, but there is a difference in hive3.
You can try switching hive to version 3 for verification
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.
We should revisit this method, the name
ParquetInputFormat.class.getName()in hive2 is the same as hive3.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.
This is for compatibility with spark,do you mean hive on spark? @cdmikechen