Search in sources :

Example 1 with FunctionContext

use of org.apache.flink.table.functions.FunctionContext in project flink by apache.

the class HiveGenericUDTF method open.

@Override
public void open(FunctionContext context) throws Exception {
    function = hiveFunctionWrapper.createFunction();
    function.setCollector(input -> {
        Row row = (Row) HiveInspectors.toFlinkObject(returnInspector, input, hiveShim);
        HiveGenericUDTF.this.collect(row);
    });
    ObjectInspector[] argumentInspectors = HiveInspectors.toInspectors(hiveShim, 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].getLogicalType(), hiveShim);
    }
    allIdentityConverter = Arrays.stream(conversions).allMatch(conv -> conv instanceof IdentityConversion);
}
Also used : TableFunction(org.apache.flink.table.functions.TableFunction) DataType(org.apache.flink.table.types.DataType) UDFArgumentException(org.apache.hadoop.hive.ql.exec.UDFArgumentException) Arrays(java.util.Arrays) Logger(org.slf4j.Logger) GenericUDTF(org.apache.hadoop.hive.ql.udf.generic.GenericUDTF) HiveTypeUtil(org.apache.flink.table.catalog.hive.util.HiveTypeUtil) TypeInfoLogicalTypeConverter(org.apache.flink.table.runtime.types.TypeInfoLogicalTypeConverter) IdentityConversion(org.apache.flink.table.functions.hive.conversion.IdentityConversion) LoggerFactory(org.slf4j.LoggerFactory) StructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector) HiveShim(org.apache.flink.table.catalog.hive.client.HiveShim) Collector(org.apache.hadoop.hive.ql.udf.generic.Collector) VisibleForTesting(org.apache.flink.annotation.VisibleForTesting) HiveInspectors(org.apache.flink.table.functions.hive.conversion.HiveInspectors) Preconditions.checkArgument(org.apache.flink.util.Preconditions.checkArgument) HiveObjectConversion(org.apache.flink.table.functions.hive.conversion.HiveObjectConversion) HiveFunctionUtil(org.apache.flink.table.functions.hive.util.HiveFunctionUtil) Internal(org.apache.flink.annotation.Internal) Row(org.apache.flink.types.Row) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) TypeInformation(org.apache.flink.api.common.typeinfo.TypeInformation) FunctionContext(org.apache.flink.table.functions.FunctionContext) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) StructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) IdentityConversion(org.apache.flink.table.functions.hive.conversion.IdentityConversion) Row(org.apache.flink.types.Row)

Aggregations

Arrays (java.util.Arrays)1 Internal (org.apache.flink.annotation.Internal)1 VisibleForTesting (org.apache.flink.annotation.VisibleForTesting)1 TypeInformation (org.apache.flink.api.common.typeinfo.TypeInformation)1 HiveShim (org.apache.flink.table.catalog.hive.client.HiveShim)1 HiveTypeUtil (org.apache.flink.table.catalog.hive.util.HiveTypeUtil)1 FunctionContext (org.apache.flink.table.functions.FunctionContext)1 TableFunction (org.apache.flink.table.functions.TableFunction)1 HiveInspectors (org.apache.flink.table.functions.hive.conversion.HiveInspectors)1 HiveObjectConversion (org.apache.flink.table.functions.hive.conversion.HiveObjectConversion)1 IdentityConversion (org.apache.flink.table.functions.hive.conversion.IdentityConversion)1 HiveFunctionUtil (org.apache.flink.table.functions.hive.util.HiveFunctionUtil)1 TypeInfoLogicalTypeConverter (org.apache.flink.table.runtime.types.TypeInfoLogicalTypeConverter)1 DataType (org.apache.flink.table.types.DataType)1 Row (org.apache.flink.types.Row)1 Preconditions.checkArgument (org.apache.flink.util.Preconditions.checkArgument)1 UDFArgumentException (org.apache.hadoop.hive.ql.exec.UDFArgumentException)1 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)1 Collector (org.apache.hadoop.hive.ql.udf.generic.Collector)1 GenericUDTF (org.apache.hadoop.hive.ql.udf.generic.GenericUDTF)1