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 2019/06/20 17:25:15 UTC

[GitHub] [flink] xuefuz commented on a change in pull request #8798: [FLINK-12659][hive] Integrate Flink with Hive GenericUDTF

xuefuz commented on a change in pull request #8798: [FLINK-12659][hive] Integrate Flink with Hive GenericUDTF
URL: https://github.com/apache/flink/pull/8798#discussion_r295913775
 
 

 ##########
 File path: flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/functions/hive/HiveGenericUDTF.java
 ##########
 @@ -0,0 +1,150 @@
+/*
+ * 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.table.functions.hive;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.table.catalog.hive.util.HiveTypeUtil;
+import org.apache.flink.table.functions.FunctionContext;
+import org.apache.flink.table.functions.TableFunction;
+import org.apache.flink.table.functions.hive.conversion.HiveInspectors;
+import org.apache.flink.table.functions.hive.conversion.HiveObjectConversion;
+import org.apache.flink.table.functions.hive.conversion.IdentityConversion;
+import org.apache.flink.table.functions.hive.util.HiveFunctionUtil;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.utils.LegacyTypeInfoDataTypeConverter;
+import org.apache.flink.types.Row;
+
+import org.apache.hadoop.hive.ql.exec.UDFArgumentException;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.ql.udf.generic.Collector;
+import org.apache.hadoop.hive.ql.udf.generic.GenericUDTF;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Arrays;
+
+import static org.apache.flink.util.Preconditions.checkArgument;
+
+/**
+ * A TableFunction implementation that calls Hive's {@link GenericUDTF}.
+ */
+@Internal
+public class HiveGenericUDTF extends TableFunction<Row> implements HiveFunction {
+	private static final Logger LOG = LoggerFactory.getLogger(HiveGenericUDTF.class);
+
+	private final HiveFunctionWrapper<GenericUDTF> hiveFunctionWrapper;
+
+	private Object[] constantArguments;
+	private DataType[] argTypes;
+
+	private transient GenericUDTF function;
+	private transient StructObjectInspector returnInspector;
+	private transient boolean isArgsSingleArray;
+
+	private transient boolean allIdentityConverter;
+	private transient HiveObjectConversion[] conversions;
+
+	public HiveGenericUDTF(HiveFunctionWrapper<GenericUDTF> hiveFunctionWrapper) {
+		this.hiveFunctionWrapper = hiveFunctionWrapper;
+	}
+
+	@Override
+	public void open(FunctionContext context) throws Exception {
+		function = hiveFunctionWrapper.createFunction();
+
+		function.setCollector(input -> {
+			Row row = (Row) HiveInspectors.toFlinkObject(returnInspector, input);
+			HiveGenericUDTF.this.collect(row);
+		});
+
+		ObjectInspector[] argumentInspectors = HiveInspectors.toInspectors(constantArguments, argTypes);
+		returnInspector = function.initialize(argumentInspectors);
+
+		isArgsSingleArray = HiveFunctionUtil.isSingleBoxedArray(argTypes);
+
+		conversions = new HiveObjectConversion[argumentInspectors.length];
+		for (int i = 0; i < argumentInspectors.length; i++) {
+			conversions[i] = HiveInspectors.getConversion(argumentInspectors[i], argTypes[i]);
+		}
+
+		allIdentityConverter = Arrays.stream(conversions)
+			.allMatch(conv -> conv instanceof IdentityConversion);
+	}
+
+	// Will on take effect after calling open()
 
 Review comment:
   on -> not?

----------------------------------------------------------------
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


With regards,
Apache Git Services