-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[feature](hudi) Step2: Support query hudi external table(include cow and mor table) #9752
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
8 commits
Select commit
Hold shift + click to select a range
86ae20a
support query hudi external table
dujl 5a4dade
fix style
dujl 2cb1bba
refractor brokerFileGroup
dujl f0b44a1
set string column as non-key column
dujl d75db54
set src column type as varchar because parquet reader convert column …
dujl d562342
fileformat
dujl 1771753
do not change database's table cache
dujl f129d01
style
dujl 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
183 changes: 183 additions & 0 deletions
183
fe/fe-core/src/main/java/org/apache/doris/external/hive/util/HiveUtil.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,183 @@ | ||
| // 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.doris.external.hive.util; | ||
|
|
||
| import org.apache.doris.catalog.ArrayType; | ||
| import org.apache.doris.catalog.Column; | ||
| import org.apache.doris.catalog.Type; | ||
| import org.apache.doris.common.AnalysisException; | ||
| import org.apache.doris.common.UserException; | ||
|
|
||
| import com.google.common.collect.Lists; | ||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.hive.metastore.api.FieldSchema; | ||
| import org.apache.hadoop.hive.ql.io.SymlinkTextInputFormat; | ||
| import org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat; | ||
| import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; | ||
| import org.apache.hadoop.hive.serde2.typeinfo.ListTypeInfo; | ||
| import org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo; | ||
| import org.apache.hadoop.hive.serde2.typeinfo.TypeInfo; | ||
| import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoUtils; | ||
| import org.apache.hadoop.mapred.InputFormat; | ||
| import org.apache.hadoop.mapred.JobConf; | ||
| import org.apache.hadoop.mapred.TextInputFormat; | ||
| import org.apache.hadoop.util.ReflectionUtils; | ||
| import org.apache.logging.log4j.LogManager; | ||
| import org.apache.logging.log4j.Logger; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Hive util for create or query hive table. | ||
| */ | ||
| public final class HiveUtil { | ||
| private static final Logger LOG = LogManager.getLogger(HiveUtil.class); | ||
|
|
||
| private HiveUtil() { | ||
| } | ||
|
|
||
| /** | ||
| * get input format class from inputFormatName. | ||
| * | ||
| * @param configuration jobConf used when getInputFormatClass | ||
| * @param inputFormatName inputFormat class name | ||
| * @param symlinkTarget use target inputFormat class when inputFormat is SymlinkTextInputFormat | ||
| * @return a class of inputFormat. | ||
| * @throws UserException when class not found. | ||
| */ | ||
| public static InputFormat<?, ?> getInputFormat(Configuration configuration, | ||
| String inputFormatName, boolean symlinkTarget) throws UserException { | ||
| try { | ||
| JobConf jobConf = new JobConf(configuration); | ||
|
|
||
| Class<? extends InputFormat<?, ?>> inputFormatClass = getInputFormatClass(jobConf, inputFormatName); | ||
| if (symlinkTarget && (inputFormatClass == SymlinkTextInputFormat.class)) { | ||
| // symlink targets are always TextInputFormat | ||
| inputFormatClass = TextInputFormat.class; | ||
| } | ||
|
|
||
| return ReflectionUtils.newInstance(inputFormatClass, jobConf); | ||
| } catch (ClassNotFoundException | RuntimeException e) { | ||
| throw new UserException("Unable to create input format " + inputFormatName, e); | ||
| } | ||
| } | ||
|
|
||
| @SuppressWarnings({"unchecked", "RedundantCast"}) | ||
| private static Class<? extends InputFormat<?, ?>> getInputFormatClass(JobConf conf, String inputFormatName) | ||
| throws ClassNotFoundException { | ||
| // CDH uses different names for Parquet | ||
| if ("parquet.hive.DeprecatedParquetInputFormat".equals(inputFormatName) | ||
| || "parquet.hive.MapredParquetInputFormat".equals(inputFormatName)) { | ||
| return MapredParquetInputFormat.class; | ||
| } | ||
|
|
||
| Class<?> clazz = conf.getClassByName(inputFormatName); | ||
| return (Class<? extends InputFormat<?, ?>>) clazz.asSubclass(InputFormat.class); | ||
| } | ||
|
|
||
| /** | ||
| * transform hiveSchema to Doris schema. | ||
| * | ||
| * @param hiveSchema hive schema | ||
| * @return doris schema | ||
| * @throws AnalysisException when transform failed. | ||
| */ | ||
| public static List<Column> transformHiveSchema(List<FieldSchema> hiveSchema) throws AnalysisException { | ||
| List<Column> newSchema = Lists.newArrayList(); | ||
| for (FieldSchema hiveColumn : hiveSchema) { | ||
| try { | ||
| newSchema.add(HiveUtil.transformHiveField(hiveColumn)); | ||
| } catch (UnsupportedOperationException e) { | ||
| LOG.warn("Unsupported data type in Doris, ignore column[{}], with error: {}", | ||
| hiveColumn.getName(), e.getMessage()); | ||
| throw e; | ||
| } | ||
| } | ||
| return newSchema; | ||
| } | ||
|
|
||
| /** | ||
| * tranform hive field to doris column. | ||
| * | ||
| * @param field hive field to be transformed | ||
| * @return doris column | ||
| */ | ||
| public static Column transformHiveField(FieldSchema field) { | ||
| TypeInfo hiveTypeInfo = TypeInfoUtils.getTypeInfoFromTypeString(field.getType()); | ||
| Type type = convertHiveTypeToiveDoris(hiveTypeInfo); | ||
| return new Column(field.getName(), type, false, null, true, null, field.getComment()); | ||
| } | ||
|
|
||
| private static Type convertHiveTypeToiveDoris(TypeInfo hiveTypeInfo) { | ||
|
|
||
| switch (hiveTypeInfo.getCategory()) { | ||
| case PRIMITIVE: { | ||
| PrimitiveTypeInfo primitiveTypeInfo = (PrimitiveTypeInfo) hiveTypeInfo; | ||
| switch (primitiveTypeInfo.getPrimitiveCategory()) { | ||
| case VOID: | ||
| return Type.NULL; | ||
| case BOOLEAN: | ||
| return Type.BOOLEAN; | ||
| case BYTE: | ||
| return Type.TINYINT; | ||
| case SHORT: | ||
| return Type.SMALLINT; | ||
| case INT: | ||
| return Type.INT; | ||
| case LONG: | ||
| return Type.BIGINT; | ||
| case FLOAT: | ||
| return Type.FLOAT; | ||
| case DOUBLE: | ||
| return Type.DOUBLE; | ||
| case STRING: | ||
| return Type.STRING; | ||
| case CHAR: | ||
| return Type.CHAR; | ||
| case VARCHAR: | ||
| return Type.VARCHAR; | ||
| case DATE: | ||
| return Type.DATE; | ||
| case TIMESTAMP: | ||
| return Type.DATETIME; | ||
| case DECIMAL: | ||
| return Type.DECIMALV2; | ||
| default: | ||
| throw new UnsupportedOperationException("Unsupported type: " | ||
| + primitiveTypeInfo.getPrimitiveCategory()); | ||
| } | ||
| } | ||
| case LIST: | ||
| TypeInfo elementTypeInfo = ((ListTypeInfo) hiveTypeInfo) | ||
| .getListElementTypeInfo(); | ||
| Type newType = null; | ||
| if (elementTypeInfo.getCategory() == ObjectInspector.Category.PRIMITIVE) { | ||
| newType = convertHiveTypeToiveDoris(elementTypeInfo); | ||
| } else { | ||
| throw new UnsupportedOperationException("Unsupported type: " + hiveTypeInfo.toString()); | ||
| } | ||
| return new ArrayType(newType); | ||
| case MAP: | ||
| case STRUCT: | ||
| case UNION: | ||
| default: | ||
| throw new UnsupportedOperationException("Unsupported type: " + hiveTypeInfo.toString()); | ||
| } | ||
| } | ||
|
|
||
| } |
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.