org.apache.calcite.sql.SqlFunction Java Examples

The following examples show how to use org.apache.calcite.sql.SqlFunction. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClassRowTypeCache.java    From mat-calcite-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public RexNode apply(RexBuilderContext context) {
	RelOptCluster cluster = context.getCluster();
	RelDataTypeFactory typeFactory = cluster.getTypeFactory();
	final SqlFunction UDF =
			new SqlUserDefinedFunction(
					new SqlIdentifier("RESOLVE_SIMPLE", SqlParserPos.ZERO),
					ReturnTypes.explicit(typeFactory.createJavaType(Object.class)),
					null,
					OperandTypes.ANY_ANY,
					ImmutableList.of(typeFactory.createTypeWithNullability(typeFactory.createJavaType(IObject.class), false),
							typeFactory.createJavaType(int.class)),
					ScalarFunctionImpl.create(IObjectMethods.class, "resolveSimpleValue"));
	RexBuilder b = context.getBuilder();
	RexNode rexNode = b.makeCall(UDF, context.getIObject(), b.makeLiteral(name));
	return b.makeCast(dataType, rexNode);
}
 
Example #2
Source File: ClassRowTypeCache.java    From mat-calcite-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public RexNode apply(RexBuilderContext context) {
	RelOptCluster cluster = context.getCluster();
	RelDataTypeFactory typeFactory = cluster.getTypeFactory();
	final SqlFunction UDF =
			new SqlUserDefinedFunction(
					new SqlIdentifier("RESOLVE_REFERENCE", SqlParserPos.ZERO),
					ReturnTypes.explicit(typeFactory.createJavaType(HeapReference.class)),
					null,
					OperandTypes.ANY_ANY,
					ImmutableList.of(typeFactory.createTypeWithNullability(typeFactory.createJavaType(IObject.class), false),
							typeFactory.createJavaType(String.class)),
					ScalarFunctionImpl.create(IObjectMethods.class, "resolveReferenceValue"));
	RexBuilder b = context.getBuilder();
	return b.makeCall(UDF, context.getIObject(), b.makeLiteral(name));
}
 
Example #3
Source File: ExecutionRexBuilderContext.java    From mat-calcite-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public RexNode getSnapshot() {
    if (snapshot == null) {
        RelDataTypeFactory typeFactory = getCluster().getTypeFactory();
        RexBuilder b = getBuilder();
        final SqlFunction UDF =
                new SqlUserDefinedFunction(
                        new SqlIdentifier("GET_SNAPSHOT", SqlParserPos.ZERO),
                        ReturnTypes.explicit(typeFactory.createTypeWithNullability(typeFactory.createJavaType(ISnapshot.class), false)),
                        null,
                        OperandTypes.NUMERIC,
                        ImmutableList.of(typeFactory.createJavaType(Integer.class)),
                        ScalarFunctionImpl.create(SnapshotHolder.class, "get"));
        snapshot = b.makeCall(UDF, b.makeLiteral(snapshotId, typeFactory.createSqlType(SqlTypeName.INTEGER), false));
    }
    return snapshot;
}
 
Example #4
Source File: RexBuilderContext.java    From mat-calcite-plugin with Apache License 2.0 6 votes vote down vote up
public RexNode getIObject() {
    if (object == null) {
        RelDataTypeFactory typeFactory = getCluster().getTypeFactory();
        RexBuilder b = getBuilder();
        final SqlFunction GET_IOBJECT =
                new SqlUserDefinedFunction(
                        new SqlIdentifier("GET_IOBJECT", SqlParserPos.ZERO),
                        ReturnTypes.explicit(typeFactory.createTypeWithNullability(typeFactory.createJavaType(IObject.class), false)),
                        null,
                        OperandTypes.ANY_ANY,
                        ImmutableList.of(typeFactory.createTypeWithNullability(typeFactory.createJavaType(ISnapshot.class), false),
                                typeFactory.createJavaType(int.class)),
                        ScalarFunctionImpl.create(ISnapshotMethods.class, "getIObject"));
        object = b.makeCall(GET_IOBJECT, getSnapshot(), getIObjectId());
    }
    return object;
}
 
Example #5
Source File: FunctionCatalogOperatorTable.java    From flink with Apache License 2.0 6 votes vote down vote up
private Optional<SqlFunction> convertToSqlFunction(
		SqlFunctionCategory category,
		String name,
		FunctionDefinition functionDefinition) {
	if (functionDefinition instanceof AggregateFunctionDefinition) {
		return convertAggregateFunction(name, (AggregateFunctionDefinition) functionDefinition);
	} else if (functionDefinition instanceof ScalarFunctionDefinition) {
		return convertScalarFunction(name, (ScalarFunctionDefinition) functionDefinition);
	} else if (functionDefinition instanceof TableFunctionDefinition &&
			category != null &&
			category.isTableFunction()) {
		return convertTableFunction(name, (TableFunctionDefinition) functionDefinition);
	}

	return Optional.empty();
}
 
Example #6
Source File: LegacyScalarFunctionConvertRule.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public Optional<RexNode> convert(CallExpression call, ConvertContext context) {
	FunctionDefinition def = call.getFunctionDefinition();
	if (def instanceof ScalarFunctionDefinition) {
		ScalarFunction scalaFunc = ((ScalarFunctionDefinition) def).getScalarFunction();
		FunctionIdentifier identifier = call.getFunctionIdentifier()
			.orElse(FunctionIdentifier.of(scalaFunc.functionIdentifier()));
		SqlFunction sqlFunction = UserDefinedFunctionUtils.createScalarSqlFunction(
			identifier,
			scalaFunc.toString(),
			scalaFunc,
			context.getTypeFactory());
		return Optional.of(context.getRelBuilder()
			.call(sqlFunction, toRexNodes(context, call.getChildren())));
	}
	return Optional.empty();
}
 
Example #7
Source File: DocumentationTest.java    From calcite with Apache License 2.0 6 votes vote down vote up
private void addOperators(Map<String, PatternOp> map, String prefix,
    List<SqlOperator> operatorList) {
  for (SqlOperator op : operatorList) {
    final String name = op.getName().equals("TRANSLATE3") ? "TRANSLATE"
        : op.getName();
    if (op instanceof SqlSpecialOperator
        || !name.matches("^[a-zA-Z][a-zA-Z0-9_]*$")) {
      continue;
    }
    final String regex;
    if (op instanceof SqlOverlapsOperator) {
      regex = "[ ]*<td>period1 " + name + " period2</td>";
    } else if (op instanceof SqlFunction
        && (op.getOperandTypeChecker() == null
            || op.getOperandTypeChecker().getOperandCountRange().getMin()
                != 0)) {
      regex = prefix + "\\| .*" + name + "\\(.*";
    } else {
      regex = prefix + "\\| .*" + name + ".*";
    }
    map.put(regex, new PatternOp(Pattern.compile(regex), name));
  }
}
 
Example #8
Source File: SqlFloorFunction.java    From calcite with Apache License 2.0 6 votes vote down vote up
/**
 * Most dialects that natively support datetime floor will use this.
 * In those cases the call will look like TRUNC(datetime, 'year').
 *
 * @param writer SqlWriter
 * @param call SqlCall
 * @param funName Name of the sql function to call
 * @param datetimeFirst Specify the order of the datetime &amp; timeUnit
 * arguments
 */
public static void unparseDatetimeFunction(SqlWriter writer, SqlCall call,
    String funName, Boolean datetimeFirst) {
  SqlFunction func = new SqlFunction(funName, SqlKind.OTHER_FUNCTION,
      ReturnTypes.ARG0_NULLABLE_VARYING, null, null,
      SqlFunctionCategory.STRING);

  SqlCall call1;
  if (datetimeFirst) {
    call1 = call;
  } else {
    // switch order of operands
    SqlNode op1 = call.operand(0);
    SqlNode op2 = call.operand(1);

    call1 = call.getOperator().createCall(call.getParserPosition(), op2, op1);
  }

  SqlUtil.unparseFunctionSyntax(func, writer, call1);
}
 
Example #9
Source File: SqlFloorFunction.java    From Bats with Apache License 2.0 6 votes vote down vote up
/**
 * Most dialects that natively support datetime floor will use this.
 * In those cases the call will look like TRUNC(datetime, 'year').
 *
 * @param writer SqlWriter
 * @param call SqlCall
 * @param funName Name of the sql function to call
 * @param datetimeFirst Specify the order of the datetime &amp; timeUnit
 * arguments
 */
public static void unparseDatetimeFunction(SqlWriter writer, SqlCall call,
    String funName, Boolean datetimeFirst) {
  SqlFunction func = new SqlFunction(funName, SqlKind.OTHER_FUNCTION,
      ReturnTypes.ARG0_NULLABLE_VARYING, null, null,
      SqlFunctionCategory.STRING);

  SqlCall call1;
  if (datetimeFirst) {
    call1 = call;
  } else {
    // switch order of operands
    SqlNode op1 = call.operand(0);
    SqlNode op2 = call.operand(1);

    call1 = call.getOperator().createCall(call.getParserPosition(), op2, op1);
  }

  SqlUtil.unparseFunctionSyntax(func, writer, call1);
}
 
Example #10
Source File: TypeCoercionImpl.java    From calcite with Apache License 2.0 6 votes vote down vote up
/**
 * Type coercion for user defined functions(UDFs).
 */
public boolean userDefinedFunctionCoercion(SqlValidatorScope scope,
    SqlCall call, SqlFunction function) {
  final List<RelDataType> paramTypes = function.getParamTypes();
  assert paramTypes != null;
  boolean coerced = false;
  for (int i = 0; i < call.operandCount(); i++) {
    SqlNode operand = call.operand(i);
    if (operand.getKind() == SqlKind.ARGUMENT_ASSIGNMENT) {
      final List<SqlNode> operandList = ((SqlCall) operand).getOperandList();
      String name = ((SqlIdentifier) operandList.get(1)).getSimple();
      int formalIndex = function.getParamNames().indexOf(name);
      if (formalIndex < 0) {
        return false;
      }
      // Column list operand type is not supported now.
      coerced = coerceOperandType(scope, (SqlCall) operand, 0,
          paramTypes.get(formalIndex)) || coerced;
    } else {
      coerced = coerceOperandType(scope, call, i, paramTypes.get(i)) || coerced;
    }
  }
  return coerced;
}
 
Example #11
Source File: StandardConvertletTable.java    From Bats with Apache License 2.0 6 votes vote down vote up
public RexNode convertFunction(
    SqlRexContext cx,
    SqlFunction fun,
    SqlCall call) {
  final List<SqlNode> operands = call.getOperandList();
  final List<RexNode> exprs = convertExpressionList(cx, operands,
      SqlOperandTypeChecker.Consistency.NONE);
  if (fun.getFunctionType() == SqlFunctionCategory.USER_DEFINED_CONSTRUCTOR) {
    return makeConstructorCall(cx, fun, exprs);
  }
  RelDataType returnType =
      cx.getValidator().getValidatedNodeTypeIfKnown(call);
  if (returnType == null) {
    returnType = cx.getRexBuilder().deriveReturnType(fun, exprs);
  }
  return cx.getRexBuilder().makeCall(returnType, fun, exprs);
}
 
Example #12
Source File: StandardConvertletTable.java    From calcite with Apache License 2.0 6 votes vote down vote up
public RexNode convertFunction(
    SqlRexContext cx,
    SqlFunction fun,
    SqlCall call) {
  final List<SqlNode> operands = call.getOperandList();
  final List<RexNode> exprs = convertExpressionList(cx, operands,
      SqlOperandTypeChecker.Consistency.NONE);
  if (fun.getFunctionType() == SqlFunctionCategory.USER_DEFINED_CONSTRUCTOR) {
    return makeConstructorCall(cx, fun, exprs);
  }
  RelDataType returnType =
      cx.getValidator().getValidatedNodeTypeIfKnown(call);
  if (returnType == null) {
    returnType = cx.getRexBuilder().deriveReturnType(fun, exprs);
  }
  return cx.getRexBuilder().makeCall(returnType, fun, exprs);
}
 
Example #13
Source File: FunctionCatalogOperatorTable.java    From flink with Apache License 2.0 5 votes vote down vote up
private Optional<SqlFunction> convertScalarFunction(FunctionIdentifier identifier, ScalarFunctionDefinition functionDefinition) {
	SqlFunction scalarFunction = UserDefinedFunctionUtils.createScalarSqlFunction(
		identifier,
		identifier.toString(),
		functionDefinition.getScalarFunction(),
		typeFactory
	);
	return Optional.of(scalarFunction);
}
 
Example #14
Source File: SqlValidatorImpl.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public void validateCall(
	SqlCall call,
	SqlValidatorScope scope) {
	final SqlOperator operator = call.getOperator();
	if ((call.operandCount() == 0)
		&& (operator.getSyntax() == SqlSyntax.FUNCTION_ID)
		&& !call.isExpanded()
		&& !conformance.allowNiladicParentheses()) {
		// For example, "LOCALTIME()" is illegal. (It should be
		// "LOCALTIME", which would have been handled as a
		// SqlIdentifier.)
		throw handleUnresolvedFunction(call, (SqlFunction) operator,
			ImmutableList.of(), null);
	}

	SqlValidatorScope operandScope = scope.getOperandScope(call);

	if (operator instanceof SqlFunction
		&& ((SqlFunction) operator).getFunctionType()
		== SqlFunctionCategory.MATCH_RECOGNIZE
		&& !(operandScope instanceof MatchRecognizeScope)) {
		throw newValidationError(call,
			Static.RESOURCE.functionMatchRecognizeOnly(call.toString()));
	}
	// Delegate validation to the operator.
	operator.validateCall(call, this, scope, operandScope);
}
 
Example #15
Source File: SqlParseUtil.java    From alchemy with Apache License 2.0 5 votes vote down vote up
private static void parseFunction(SqlNode sqlNode, List<String> udfs) {
    if (sqlNode instanceof SqlBasicCall) {
        SqlBasicCall sqlBasicCall = (SqlBasicCall)sqlNode;
        SqlOperator operator = sqlBasicCall.getOperator();
        if (operator instanceof SqlFunction) {
            SqlFunction sqlFunction = (SqlFunction)operator;
            SqlFunctionCategory category = sqlFunction.getFunctionType();
            switch (category) {
                case USER_DEFINED_FUNCTION:
                case USER_DEFINED_SPECIFIC_FUNCTION:
                case USER_DEFINED_TABLE_FUNCTION:
                case USER_DEFINED_TABLE_SPECIFIC_FUNCTION:
                    addUdf(udfs, sqlFunction.getName());
                    break;
                default:
            }
        } else {
            parseFunction(sqlBasicCall.operand(0), udfs);
        }
        // 查询嵌套的函数
        SqlNode[] nodes = sqlBasicCall.getOperands();
        if(nodes != null && nodes.length > 0){
            for(SqlNode node : nodes){
                parseFunction(node, udfs);
            }
        }
    }
}
 
Example #16
Source File: RexNodeConverter.java    From flink with Apache License 2.0 5 votes vote down vote up
private RexNode visit(UnresolvedCallExpression call) {
	FunctionDefinition func = call.getFunctionDefinition();
	switch (func.getKind()) {
		case SCALAR:
			if (func instanceof ScalarFunctionDefinition) {
				ScalarFunction scalaFunc = ((ScalarFunctionDefinition) func).getScalarFunction();
				List<RexNode> child = convertCallChildren(call.getChildren());
				SqlFunction sqlFunction = UserDefinedFunctionUtils.createScalarSqlFunction(
						scalaFunc.functionIdentifier(),
						scalaFunc.toString(),
						scalaFunc,
						typeFactory);
				return relBuilder.call(sqlFunction, child);
			} else {
				FunctionDefinition def = call.getFunctionDefinition();
				if (conversionsOfBuiltInFunc.containsKey(def)) {
					RexNodeConversion conversion = conversionsOfBuiltInFunc.get(def);
					return conversion.convert(call);
				} else {
					throw new UnsupportedOperationException(def.toString());
				}
			}

		default:
			throw new UnsupportedOperationException();
	}
}
 
Example #17
Source File: FunctionCatalogOperatorTable.java    From flink with Apache License 2.0 5 votes vote down vote up
private Optional<SqlFunction> convertTableFunction(String name, TableFunctionDefinition functionDefinition) {
	SqlFunction tableFunction = UserDefinedFunctionUtils.createTableSqlFunction(
		name,
		name,
		functionDefinition.getTableFunction(),
		TypeConversions.fromLegacyInfoToDataType(functionDefinition.getResultType()),
		typeFactory
	);
	return Optional.of(tableFunction);
}
 
Example #18
Source File: FunctionCatalogOperatorTable.java    From flink with Apache License 2.0 5 votes vote down vote up
private Optional<SqlFunction> convertAggregateFunction(
		String name,
		AggregateFunctionDefinition functionDefinition) {
	SqlFunction aggregateFunction = UserDefinedFunctionUtils.createAggregateSqlFunction(
		name,
		name,
		functionDefinition.getAggregateFunction(),
		TypeConversions.fromLegacyInfoToDataType(functionDefinition.getResultTypeInfo()),
		TypeConversions.fromLegacyInfoToDataType(functionDefinition.getAccumulatorTypeInfo()),
		typeFactory
	);
	return Optional.of(aggregateFunction);
}
 
Example #19
Source File: ExpressionGenerator.java    From streamline with Apache License 2.0 5 votes vote down vote up
@Override
public Expression visit(SqlCall call) {
    SqlOperator sqlOperator = call.getOperator();
    if (sqlOperator instanceof SqlBinaryOperator) {
        return visitBinaryOperator((SqlBinaryOperator) sqlOperator, call.getOperandList().get(0),
                call.getOperandList().get(1));
    } else if (sqlOperator instanceof SqlSpecialOperator) {
        return visitSqlSpecialOperator((SqlSpecialOperator) sqlOperator, call.getOperandList());
    } else if (sqlOperator instanceof SqlFunction) {
        SqlFunction sqlFunction = (SqlFunction) sqlOperator;
        if (sqlFunction instanceof SqlAggFunction) {
            return visitAggregateFunction(sqlFunction.getName(), call.getOperandList());
        } else if (sqlFunction instanceof SqlUnresolvedFunction) {
            String udfName = sqlFunction.getName().toUpperCase();
            if (catalogUdfs.containsKey(udfName)) {
                Udf udfInfo = catalogUdfs.get(udfName);
                if (udfInfo.isAggregate()) {
                    return visitUserDefinedAggregateFunction(udfInfo, call.getOperandList());
                } else {
                    return visitUserDefinedFunction(udfInfo, call.getOperandList());
                }
            } else {
                throw new UnsupportedOperationException("Unknown built-in or User defined function '" + udfName + "'");
            }
        } else {
            return visitFunction(sqlFunction.getName(), call.getOperandList());
        }
    } else {
        throw new UnsupportedOperationException("Operator " + sqlOperator.getName() + " is not supported");
    }
}
 
Example #20
Source File: FunctionCatalogOperatorTable.java    From flink with Apache License 2.0 5 votes vote down vote up
private Optional<SqlFunction> convertTableFunction(FunctionIdentifier identifier, TableFunctionDefinition functionDefinition) {
	SqlFunction tableFunction = UserDefinedFunctionUtils.createTableSqlFunction(
		identifier,
		identifier.toString(),
		functionDefinition.getTableFunction(),
		TypeConversions.fromLegacyInfoToDataType(functionDefinition.getResultType()),
		typeFactory
	);
	return Optional.of(tableFunction);
}
 
Example #21
Source File: FunctionCatalogOperatorTable.java    From flink with Apache License 2.0 5 votes vote down vote up
private Optional<SqlFunction> convertTableFunction(String name, TableFunctionDefinition functionDefinition) {
	SqlFunction tableFunction = UserDefinedFunctionUtils.createTableSqlFunction(
		name,
		name,
		functionDefinition.getTableFunction(),
		functionDefinition.getResultType(),
		typeFactory
	);
	return Optional.of(tableFunction);
}
 
Example #22
Source File: FunctionCatalogOperatorTable.java    From flink with Apache License 2.0 5 votes vote down vote up
private Optional<SqlFunction> convertScalarFunction(String name, ScalarFunctionDefinition functionDefinition) {
	SqlFunction scalarFunction = UserDefinedFunctionUtils.createScalarSqlFunction(
		name,
		name,
		functionDefinition.getScalarFunction(),
		typeFactory
	);
	return Optional.of(scalarFunction);
}
 
Example #23
Source File: FunctionCatalogOperatorTable.java    From flink with Apache License 2.0 5 votes vote down vote up
private Optional<SqlFunction> convertScalarFunction(String name, ScalarFunctionDefinition functionDefinition) {
	SqlFunction scalarFunction = UserDefinedFunctionUtils.createScalarSqlFunction(
		name,
		name,
		functionDefinition.getScalarFunction(),
		typeFactory
	);
	return Optional.of(scalarFunction);
}
 
Example #24
Source File: FunctionCatalogOperatorTable.java    From flink with Apache License 2.0 5 votes vote down vote up
private Optional<SqlFunction> convertAggregateFunction(
		String name,
		AggregateFunctionDefinition functionDefinition) {
	SqlFunction aggregateFunction = UserDefinedFunctionUtils.createAggregateSqlFunction(
		name,
		name,
		functionDefinition.getAggregateFunction(),
		functionDefinition.getResultTypeInfo(),
		functionDefinition.getAccumulatorTypeInfo(),
		typeFactory
	);
	return Optional.of(aggregateFunction);
}
 
Example #25
Source File: FunctionCatalogOperatorTable.java    From flink with Apache License 2.0 5 votes vote down vote up
private Optional<SqlFunction> convertAggregateFunction(
		String name,
		AggregateFunctionDefinition functionDefinition) {
	SqlFunction aggregateFunction = UserDefinedFunctionUtils.createAggregateSqlFunction(
		name,
		name,
		functionDefinition.getAggregateFunction(),
		functionDefinition.getResultTypeInfo(),
		functionDefinition.getAccumulatorTypeInfo(),
		typeFactory
	);
	return Optional.of(aggregateFunction);
}
 
Example #26
Source File: ClassRowTypeCache.java    From mat-calcite-plugin with Apache License 2.0 5 votes vote down vote up
public RexNode apply(RexBuilderContext context) {
	RelOptCluster cluster = context.getCluster();
	RelDataTypeFactory typeFactory = cluster.getTypeFactory();
	final SqlFunction UDF =
			new SqlUserDefinedFunction(
					new SqlIdentifier("TO_REFERENCE", SqlParserPos.ZERO),
					ReturnTypes.explicit(typeFactory.createJavaType(HeapReference.class)),
					null,
					OperandTypes.ANY,
					ImmutableList.of(typeFactory.createTypeWithNullability(typeFactory.createJavaType(IObject.class), false)),
					ScalarFunctionImpl.create(ISnapshotMethods.class, "toReference")
			);
	return context.getBuilder().makeCall(UDF, context.getIObject());
}
 
Example #27
Source File: SqlValidatorImpl.java    From flink with Apache License 2.0 5 votes vote down vote up
public void validateCall(
	SqlCall call,
	SqlValidatorScope scope) {
	final SqlOperator operator = call.getOperator();
	if ((call.operandCount() == 0)
		&& (operator.getSyntax() == SqlSyntax.FUNCTION_ID)
		&& !call.isExpanded()
		&& !conformance.allowNiladicParentheses()) {
		// For example, "LOCALTIME()" is illegal. (It should be
		// "LOCALTIME", which would have been handled as a
		// SqlIdentifier.)
		throw handleUnresolvedFunction(call, (SqlFunction) operator,
			ImmutableList.of(), null);
	}

	SqlValidatorScope operandScope = scope.getOperandScope(call);

	if (operator instanceof SqlFunction
		&& ((SqlFunction) operator).getFunctionType()
		== SqlFunctionCategory.MATCH_RECOGNIZE
		&& !(operandScope instanceof MatchRecognizeScope)) {
		throw newValidationError(call,
			Static.RESOURCE.functionMatchRecognizeOnly(call.toString()));
	}
	// Delegate validation to the operator.
	operator.validateCall(call, this, scope, operandScope);
}
 
Example #28
Source File: FunctionCatalogOperatorTable.java    From flink with Apache License 2.0 5 votes vote down vote up
private Optional<SqlFunction> convertScalarFunction(String name, ScalarFunctionDefinition functionDefinition) {
	SqlFunction scalarFunction = UserDefinedFunctionUtils.createScalarSqlFunction(
		name,
		name,
		functionDefinition.getScalarFunction(),
		typeFactory
	);
	return Optional.of(scalarFunction);
}
 
Example #29
Source File: FunctionCatalogOperatorTable.java    From flink with Apache License 2.0 5 votes vote down vote up
private Optional<SqlFunction> convertTableFunction(String name, TableFunctionDefinition functionDefinition) {
	SqlFunction tableFunction = UserDefinedFunctionUtils.createTableSqlFunction(
		name,
		name,
		functionDefinition.getTableFunction(),
		functionDefinition.getResultType(),
		typeFactory
	);
	return Optional.of(tableFunction);
}
 
Example #30
Source File: FunctionCatalogOperatorTable.java    From flink with Apache License 2.0 5 votes vote down vote up
private Optional<SqlFunction> convertAggregateFunction(
		FunctionIdentifier identifier,
		AggregateFunctionDefinition functionDefinition) {
	SqlFunction aggregateFunction = UserDefinedFunctionUtils.createAggregateSqlFunction(
		identifier,
		identifier.toString(),
		functionDefinition.getAggregateFunction(),
		TypeConversions.fromLegacyInfoToDataType(functionDefinition.getResultTypeInfo()),
		TypeConversions.fromLegacyInfoToDataType(functionDefinition.getAccumulatorTypeInfo()),
		typeFactory
	);
	return Optional.of(aggregateFunction);
}