-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[HUDI-4098]Support HMS for flink HudiCatalog #6082
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 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
50eac6a
[HUDI-4098]Support HMS for flink HudiCatalog
cuibo01 017b443
[HUDI-4098]Support HMS for flink HudiCatalog
cuibo01 bd62a2b
[HUDI-4098]Support HMS for flink HudiCatalog
cuibo01 86cf2a5
[HUDI-4098]Support HMS for flink HudiCatalog
cuibo01 de5edc0
[HUDI-4098]Support HMS for flink HudiCatalog
cuibo01 06a19cc
Merge branch 'master' into hudiCatalog4
cuibo01 253a097
[HUDI-4098]Support HMS for flink HudiCatalog
cuibo01 b8b56bc
[HUDI-4098]Support HMS for flink HudiCatalog
cuibo01 688f54d
[HUDI-4098]Support HMS for flink HudiCatalog
cuibo01 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
42 changes: 42 additions & 0 deletions
42
hudi-common/src/main/java/org/apache/hudi/exception/HoodieCatalogException.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,42 @@ | ||
| /* | ||
| * 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.exception; | ||
|
|
||
| /** | ||
| * Exception thrown for Hoodie Catalog errors. | ||
| */ | ||
| public class HoodieCatalogException extends RuntimeException { | ||
|
|
||
| public HoodieCatalogException() { | ||
| super(); | ||
| } | ||
|
|
||
| public HoodieCatalogException(String message) { | ||
| super(message); | ||
| } | ||
|
|
||
| public HoodieCatalogException(String message, Throwable t) { | ||
| super(message, t); | ||
| } | ||
|
|
||
| public HoodieCatalogException(Throwable t) { | ||
| super(t); | ||
| } | ||
|
|
||
| } | ||
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
203 changes: 203 additions & 0 deletions
203
...nk-datasource/hudi-flink/src/main/java/org/apache/hudi/table/catalog/HiveSchemaUtils.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,203 @@ | ||
| /* | ||
| * 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.table.catalog; | ||
|
|
||
| import org.apache.hudi.common.util.StringUtils; | ||
|
|
||
| import org.apache.flink.table.api.DataTypes; | ||
| import org.apache.flink.table.api.TableSchema; | ||
| import org.apache.flink.table.types.DataType; | ||
| import org.apache.flink.table.types.logical.LogicalType; | ||
| import org.apache.hadoop.hive.metastore.api.FieldSchema; | ||
| import org.apache.hadoop.hive.metastore.api.Table; | ||
| import org.apache.hadoop.hive.serde2.typeinfo.CharTypeInfo; | ||
| import org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo; | ||
| import org.apache.hadoop.hive.serde2.typeinfo.ListTypeInfo; | ||
| import org.apache.hadoop.hive.serde2.typeinfo.MapTypeInfo; | ||
| import org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo; | ||
| import org.apache.hadoop.hive.serde2.typeinfo.StructTypeInfo; | ||
| import org.apache.hadoop.hive.serde2.typeinfo.TypeInfo; | ||
| import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoUtils; | ||
| import org.apache.hadoop.hive.serde2.typeinfo.VarcharTypeInfo; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| import static org.apache.flink.util.Preconditions.checkNotNull; | ||
|
|
||
| /** | ||
| * Utilities for Hive field schema. | ||
| */ | ||
| public class HiveSchemaUtils { | ||
| /** Get field names from field schemas. */ | ||
| public static List<String> getFieldNames(List<FieldSchema> fieldSchemas) { | ||
| List<String> names = new ArrayList<>(fieldSchemas.size()); | ||
| for (FieldSchema fs : fieldSchemas) { | ||
| names.add(fs.getName()); | ||
| } | ||
| return names; | ||
| } | ||
|
|
||
| public static org.apache.flink.table.api.Schema convertTableSchema(Table hiveTable) { | ||
| List<FieldSchema> allCols = new ArrayList<>(hiveTable.getSd().getCols()); | ||
| allCols.addAll(hiveTable.getPartitionKeys()); | ||
|
|
||
| String pkConstraintName = hiveTable.getParameters().get(TableOptionProperties.PK_CONSTRAINT_NAME); | ||
| List<String> primaryColNames = StringUtils.isNullOrEmpty(pkConstraintName) | ||
| ? Collections.EMPTY_LIST | ||
| : StringUtils.split(hiveTable.getParameters().get(TableOptionProperties.PK_COLUMNS),","); | ||
|
|
||
| String[] colNames = new String[allCols.size()]; | ||
| DataType[] colTypes = new DataType[allCols.size()]; | ||
|
|
||
| for (int i = 0; i < allCols.size(); i++) { | ||
| FieldSchema fs = allCols.get(i); | ||
|
|
||
| colNames[i] = fs.getName(); | ||
| colTypes[i] = | ||
| toFlinkType(TypeInfoUtils.getTypeInfoFromTypeString(fs.getType())); | ||
| if (primaryColNames.contains(colNames[i])) { | ||
| colTypes[i] = colTypes[i].notNull(); | ||
| } | ||
| } | ||
|
|
||
| org.apache.flink.table.api.Schema.Builder builder = org.apache.flink.table.api.Schema.newBuilder().fromFields(colNames, colTypes); | ||
| if (!StringUtils.isNullOrEmpty(pkConstraintName)) { | ||
| builder.primaryKeyNamed(pkConstraintName, primaryColNames); | ||
| } | ||
|
|
||
| return builder.build(); | ||
| } | ||
|
|
||
| /** | ||
| * Convert Hive data type to a Flink data type. | ||
| * | ||
| * @param hiveType a Hive data type | ||
| * @return the corresponding Flink data type | ||
| */ | ||
| public static DataType toFlinkType(TypeInfo hiveType) { | ||
| checkNotNull(hiveType, "hiveType cannot be null"); | ||
|
|
||
| switch (hiveType.getCategory()) { | ||
| case PRIMITIVE: | ||
| return toFlinkPrimitiveType((PrimitiveTypeInfo) hiveType); | ||
| case LIST: | ||
| ListTypeInfo listTypeInfo = (ListTypeInfo) hiveType; | ||
| return DataTypes.ARRAY(toFlinkType(listTypeInfo.getListElementTypeInfo())); | ||
| case MAP: | ||
| MapTypeInfo mapTypeInfo = (MapTypeInfo) hiveType; | ||
| return DataTypes.MAP( | ||
| toFlinkType(mapTypeInfo.getMapKeyTypeInfo()), | ||
| toFlinkType(mapTypeInfo.getMapValueTypeInfo())); | ||
| case STRUCT: | ||
| StructTypeInfo structTypeInfo = (StructTypeInfo) hiveType; | ||
|
|
||
| List<String> names = structTypeInfo.getAllStructFieldNames(); | ||
| List<TypeInfo> typeInfos = structTypeInfo.getAllStructFieldTypeInfos(); | ||
|
|
||
| DataTypes.Field[] fields = new DataTypes.Field[names.size()]; | ||
|
|
||
| for (int i = 0; i < fields.length; i++) { | ||
| fields[i] = DataTypes.FIELD(names.get(i), toFlinkType(typeInfos.get(i))); | ||
| } | ||
|
|
||
| return DataTypes.ROW(fields); | ||
| default: | ||
| throw new UnsupportedOperationException( | ||
| String.format("Flink doesn't support Hive data type %s yet.", hiveType)); | ||
| } | ||
| } | ||
|
|
||
| private static DataType toFlinkPrimitiveType(PrimitiveTypeInfo hiveType) { | ||
| checkNotNull(hiveType, "hiveType cannot be null"); | ||
|
|
||
| switch (hiveType.getPrimitiveCategory()) { | ||
| case CHAR: | ||
| return DataTypes.CHAR(((CharTypeInfo) hiveType).getLength()); | ||
| case VARCHAR: | ||
| return DataTypes.VARCHAR(((VarcharTypeInfo) hiveType).getLength()); | ||
| case STRING: | ||
| return DataTypes.STRING(); | ||
| case BOOLEAN: | ||
| return DataTypes.BOOLEAN(); | ||
| case BYTE: | ||
| return DataTypes.TINYINT(); | ||
| case SHORT: | ||
| return DataTypes.SMALLINT(); | ||
| case INT: | ||
| return DataTypes.INT(); | ||
| case LONG: | ||
| return DataTypes.BIGINT(); | ||
| case FLOAT: | ||
| return DataTypes.FLOAT(); | ||
| case DOUBLE: | ||
| return DataTypes.DOUBLE(); | ||
| case DATE: | ||
| return DataTypes.DATE(); | ||
| case TIMESTAMP: | ||
| return DataTypes.TIMESTAMP(9); | ||
| case BINARY: | ||
| return DataTypes.BYTES(); | ||
| case DECIMAL: | ||
| DecimalTypeInfo decimalTypeInfo = (DecimalTypeInfo) hiveType; | ||
| return DataTypes.DECIMAL( | ||
| decimalTypeInfo.getPrecision(), decimalTypeInfo.getScale()); | ||
| default: | ||
| throw new UnsupportedOperationException( | ||
| String.format( | ||
| "Flink doesn't support Hive primitive type %s yet", hiveType)); | ||
| } | ||
| } | ||
|
|
||
| /** Create Hive columns from Flink TableSchema. */ | ||
| public static List<FieldSchema> createHiveColumns(TableSchema schema) { | ||
| String[] fieldNames = schema.getFieldNames(); | ||
| DataType[] fieldTypes = schema.getFieldDataTypes(); | ||
|
|
||
| List<FieldSchema> columns = new ArrayList<>(fieldNames.length); | ||
|
|
||
| for (int i = 0; i < fieldNames.length; i++) { | ||
| columns.add( | ||
| new FieldSchema( | ||
| fieldNames[i], | ||
| toHiveTypeInfo(fieldTypes[i], true).getTypeName(), | ||
| null)); | ||
| } | ||
|
|
||
| return columns; | ||
| } | ||
|
|
||
| /** | ||
| * Convert Flink DataType to Hive TypeInfo. For types with a precision parameter, e.g. | ||
| * timestamp, the supported precisions in Hive and Flink can be different. Therefore the | ||
| * conversion will fail for those types if the precision is not supported by Hive and | ||
| * checkPrecision is true. | ||
| * | ||
| * @param dataType a Flink DataType | ||
| * @param checkPrecision whether to fail the conversion if the precision of the DataType is not | ||
| * supported by Hive | ||
| * @return the corresponding Hive data type | ||
| */ | ||
| public static TypeInfo toHiveTypeInfo(DataType dataType, boolean checkPrecision) { | ||
| checkNotNull(dataType, "type cannot be null"); | ||
| LogicalType logicalType = dataType.getLogicalType(); | ||
| return logicalType.accept(new TypeInfoLogicalTypeVisitor(dataType, checkPrecision)); | ||
| } | ||
| } |
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.