You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2020/05/18 03:04:47 UTC

[GitHub] [flink] lirui-apache commented on a change in pull request #12206: [FLINK-14255][hive] Integrate hive to streaming file sink with parquet and orc

lirui-apache commented on a change in pull request #12206:
URL: https://github.com/apache/flink/pull/12206#discussion_r426342495



##########
File path: flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/connectors/hive/HiveRowDataPartitionComputer.java
##########
@@ -0,0 +1,77 @@
+/*
+ * 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.flink.connectors.hive;
+
+import org.apache.flink.table.catalog.hive.client.HiveShim;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.data.util.DataFormatConverters;
+import org.apache.flink.table.filesystem.RowDataPartitionComputer;
+import org.apache.flink.table.functions.hive.conversion.HiveInspectors;
+import org.apache.flink.table.functions.hive.conversion.HiveObjectConversion;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.utils.TypeConversions;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+
+import java.util.Arrays;
+import java.util.LinkedHashMap;
+
+/**
+ * A {@link RowDataPartitionComputer} that converts Flink objects to Hive objects before computing the partition value strings.
+ */
+public class HiveRowDataPartitionComputer extends RowDataPartitionComputer {

Review comment:
       Perhaps we should rename the old `HivePartitionComputer` to `HiveRowPartitionComputer`?

##########
File path: flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/connectors/hive/write/HiveOutputFormatFactory.java
##########
@@ -0,0 +1,81 @@
+/*
+ * 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.flink.connectors.hive.write;
+
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.core.fs.Path;
+import org.apache.flink.runtime.fs.hdfs.HadoopFileSystem;
+import org.apache.flink.table.filesystem.OutputFormatFactory;
+import org.apache.flink.types.Row;
+
+import org.apache.hadoop.hive.ql.exec.FileSinkOperator.RecordWriter;
+import org.apache.hadoop.io.Writable;
+
+import java.io.IOException;
+import java.util.function.Function;
+
+/**
+ * Hive {@link OutputFormatFactory}, use {@link RecordWriter} to write record.
+ */
+public class HiveOutputFormatFactory implements OutputFormatFactory<Row> {

Review comment:
       I think we already have a `HiveOutputFormatFactory`, what's the difference between them?

##########
File path: flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/connectors/hive/HiveTableSink.java
##########
@@ -143,21 +206,51 @@ public HiveTableSink(JobConf jobConf, ObjectPath tablePath, CatalogTable table)
 		}
 	}
 
-	@Override
-	public TableSink<Row> configure(String[] fieldNames, TypeInformation<?>[] fieldTypes) {
-		return new HiveTableSink(jobConf, tablePath, catalogTable);
+	private BulkWriter.Factory<RowData> createBulkWriterFactory(String[] partitionColumns,
+			StorageDescriptor sd) {
+		String serLib = sd.getSerdeInfo().getSerializationLib().toLowerCase();
+		int formatFieldCount = tableSchema.getFieldCount() - partitionColumns.length;
+		String[] formatNames = new String[formatFieldCount];
+		LogicalType[] formatTypes = new LogicalType[formatFieldCount];
+		for (int i = 0; i < formatFieldCount; i++) {
+			formatNames[i] = tableSchema.getFieldName(i).get();
+			formatTypes[i] = tableSchema.getFieldDataType(i).get().getLogicalType();
+		}
+		RowType formatType = RowType.of(formatTypes, formatNames);
+		Configuration formatConf = new Configuration(jobConf);
+		sd.getSerdeInfo().getParameters().forEach(formatConf::set);
+		BulkWriter.Factory<RowData> bulkFactory;
+		if (serLib.contains("parquet")) {

Review comment:
       We have already get the output format class. I think it's more reliable to check the class to decide whether the table is stored as orc or parquet.

##########
File path: flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/catalog/hive/client/HiveShim.java
##########
@@ -205,4 +208,10 @@ SimpleGenericUDAFParameterInfo createUDAFParameterInfo(ObjectInspector[] params,
 	 */
 	void createTableWithConstraints(IMetaStoreClient client, Table table, Configuration conf,
 			UniqueConstraint pk, List<Byte> pkTraits, List<String> notNullCols, List<Byte> nnTraits);
+
+	/**
+	 * Create orc {@link BulkWriter.Factory} for different hive versions.
+	 */
+	BulkWriter.Factory<RowData> createOrcBulkWriterFactory(

Review comment:
       Shouldn't this method be placed in `OrcShim`? It's strange that HiveShim needs to understand how flink-orc works.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org