final SqlUserDefinedTableMacro udf = (SqlUserDefinedTableMacro) operator; final TranslatableTable table = udf.getTable(typeFactory, call.getOperandList()); final RelDataType rowType = table.getRowType(typeFactory);
/** Returns the table in this UDF, or null if there is no table. */ public TranslatableTable getTable(RelDataTypeFactory typeFactory, List<SqlNode> operandList) { List<Object> arguments = convertArguments(typeFactory, operandList, tableMacro, getNameAsId(), true); return tableMacro.apply(arguments); }
/** * Returns the record type of the table yielded by this function when * applied to given arguments. Only literal arguments are passed, * non-literal are replaced with default values (null, 0, false, etc). * * @param typeFactory Type factory * @param operandList arguments of a function call (only literal arguments * are passed, nulls for non-literal ones) * @return row type of the table */ public RelDataType getRowType(RelDataTypeFactory typeFactory, List<SqlNode> operandList) { List<Object> arguments = SqlUserDefinedTableMacro.convertArguments(typeFactory, operandList, function, getNameAsId(), false); return getFunction().getRowType(typeFactory, arguments); }
} else if (SqlUtil.isLiteral(pair.right)) { final Object o = ((SqlLiteral) pair.right).getValue(); final Object o2 = coerce(o, pair.left.getType(typeFactory)); arguments.add(o2); } else {
OperandTypes.family(typeFamilies), (AggregateFunction) function); } else if (function instanceof TableMacro) { return new SqlUserDefinedTableMacro(name, ReturnTypes.CURSOR, InferTypes.explicit(argTypes), OperandTypes.family(typeFamilies),
/** * Returns the row type of the table yielded by this function when * applied to given arguments. Only literal arguments are passed, * non-literal are replaced with default values (null, 0, false, etc). * * @param operandList arguments of a function call (only literal arguments * are passed, nulls for non-literal ones) * @return element type of the table (e.g. {@code Object[].class}) */ public Type getElementType(RelDataTypeFactory typeFactory, List<SqlNode> operandList) { List<Object> arguments = SqlUserDefinedTableMacro.convertArguments(typeFactory, operandList, function, getNameAsId(), false); return getFunction().getElementType(arguments); } }
public RelDataType validateImpl() { validator.inferUnknownTypes(validator.unknownType, scope, call); final RelDataType type = validator.deriveTypeImpl(scope, call); final SqlOperator operator = call.getOperator(); if (operator instanceof SqlUserDefinedTableFunction) { assert type.getSqlTypeName() == SqlTypeName.CURSOR : "User-defined table function should have CURSOR type, not " + type; final SqlUserDefinedTableFunction udf = (SqlUserDefinedTableFunction) operator; return udf.getRowType(validator.typeFactory, call.getOperandList()); } else if (operator instanceof SqlUserDefinedTableMacro) { assert type.getSqlTypeName() == SqlTypeName.CURSOR : "User-defined table macro should have CURSOR type, not " + type; final SqlUserDefinedTableMacro udf = (SqlUserDefinedTableMacro) operator; return udf.getTable(validator.typeFactory, call.getOperandList()) .getRowType(validator.typeFactory); } return type; }
final SqlUserDefinedTableMacro udf = (SqlUserDefinedTableMacro) operator; final TranslatableTable table = udf.getTable(typeFactory, call.getOperandList()); final RelDataType rowType = table.getRowType(typeFactory);