use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataTypeFactory in project beam by apache.
the class UdafImpl method getParameters.
@Override
public List<FunctionParameter> getParameters() {
List<FunctionParameter> para = new ArrayList<>();
para.add(new FunctionParameter() {
@Override
public int getOrdinal() {
// up to one parameter is supported in UDAF.
return 0;
}
@Override
public String getName() {
// not used as Beam SQL uses its own execution engine
return null;
}
@Override
public RelDataType getType(RelDataTypeFactory typeFactory) {
Type inputType = getInputType();
if (inputType instanceof TypeVariable) {
throw new IllegalArgumentException("Unable to infer SQL type from type variable " + inputType + ". This usually means you are trying to use a generic type whose type information " + "is not known at runtime. You can wrap your CombineFn into typed subclass" + " by 'new TypedCombineFnDelegate<...>(combineFn) {}'");
}
return CalciteUtils.sqlTypeWithAutoCast(typeFactory, inputType);
}
@Override
public boolean isOptional() {
// not used as Beam SQL uses its own execution engine
return false;
}
});
return para;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataTypeFactory in project apex-malhar by apache.
the class CSVMessageFormat method getRowType.
@Override
public RelDataType getRowType(RelDataTypeFactory typeFactory) {
String schema = (String) operands.get(CSV_SCHEMA);
RelDataTypeFactory.FieldInfoBuilder builder = typeFactory.builder();
DelimitedSchema delimitedSchema = new DelimitedSchema(schema);
for (DelimitedSchema.Field field : delimitedSchema.getFields()) {
builder.add(field.getName(), convertField(typeFactory, field.getType()));
}
return builder.build();
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataTypeFactory in project beam by apache.
the class ZetaSqlUnnest method deriveUncollectRowType.
/**
* Returns the row type returned by applying the 'UNNEST' operation to a relational expression.
*
* <p>Each column in the relational expression must be a multiset of structs or an array. The
* return type is the type of that column, plus an ORDINALITY column if {@code withOrdinality}.
*/
public static RelDataType deriveUncollectRowType(RelNode rel, boolean withOrdinality) {
RelDataType inputType = rel.getRowType();
assert inputType.isStruct() : inputType + " is not a struct";
final List<RelDataTypeField> fields = inputType.getFieldList();
final RelDataTypeFactory typeFactory = rel.getCluster().getTypeFactory();
final RelDataTypeFactory.Builder builder = typeFactory.builder();
if (fields.size() == 1 && fields.get(0).getType().getSqlTypeName() == SqlTypeName.ANY) {
// and Any type.
return builder.add(fields.get(0).getName(), SqlTypeName.ANY).nullable(true).build();
}
for (RelDataTypeField field : fields) {
if (field.getType() instanceof MapSqlType) {
builder.add(SqlUnnestOperator.MAP_KEY_COLUMN_NAME, Preconditions.checkArgumentNotNull(field.getType().getKeyType(), "Encountered MAP type with null key type in field %s", field));
builder.add(SqlUnnestOperator.MAP_VALUE_COLUMN_NAME, Preconditions.checkArgumentNotNull(field.getType().getValueType(), "Encountered MAP type with null value type in field %s", field));
} else {
assert field.getType() instanceof ArraySqlType;
RelDataType ret = Preconditions.checkArgumentNotNull(field.getType().getComponentType(), "Encountered ARRAY type with null component type in field %s", field);
// Only difference than Uncollect.java: treats record type and scalar type equally
builder.add(SqlUtil.deriveAliasFromOrdinal(field.getIndex()), ret);
}
}
if (withOrdinality) {
builder.add(SqlUnnestOperator.ORDINALITY_COLUMN_NAME, SqlTypeName.INTEGER);
}
return builder.build();
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataTypeFactory in project beam by apache.
the class LazyAggregateCombineFnTest method nonparameterizedGetUdafImpl_throwsIllegalStateException.
@Test
public void nonparameterizedGetUdafImpl_throwsIllegalStateException() {
LazyAggregateCombineFn<?, ?, ?> combiner = new LazyAggregateCombineFn<>(new NonParameterizedAggregateFn());
AggregateFunction aggregateFunction = combiner.getUdafImpl();
RelDataTypeFactory typeFactory = new JavaTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
exceptions.expect(IllegalStateException.class);
List<FunctionParameter> params = aggregateFunction.getParameters();
params.get(0).getType(typeFactory);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataTypeFactory in project flink by apache.
the class HiveParserUtils method toAggCall.
public static AggregateCall toAggCall(HiveParserBaseSemanticAnalyzer.AggInfo aggInfo, HiveParserRexNodeConverter converter, Map<String, Integer> rexNodeToPos, int groupCount, RelNode input, RelOptCluster cluster, SqlFunctionConverter funcConverter) throws SemanticException {
// 1. Get agg fn ret type in Calcite
RelDataType aggFnRetType = HiveParserUtils.toRelDataType(aggInfo.getReturnType(), cluster.getTypeFactory());
// 2. Convert Agg Fn args and type of args to Calcite
// TODO: Does HQL allows expressions as aggregate args or can it only be projections from
// child?
List<Integer> argIndices = new ArrayList<>();
RelDataTypeFactory typeFactory = cluster.getTypeFactory();
List<RelDataType> calciteArgTypes = new ArrayList<>();
for (ExprNodeDesc expr : aggInfo.getAggParams()) {
RexNode paramRex = converter.convert(expr).accept(funcConverter);
Integer argIndex = Preconditions.checkNotNull(rexNodeToPos.get(paramRex.toString()));
argIndices.add(argIndex);
// TODO: does arg need type cast?
calciteArgTypes.add(HiveParserUtils.toRelDataType(expr.getTypeInfo(), typeFactory));
}
// 3. Get Aggregation FN from Calcite given name, ret type and input arg type
final SqlAggFunction aggFunc = HiveParserSqlFunctionConverter.getCalciteAggFn(aggInfo.getUdfName(), aggInfo.isDistinct(), calciteArgTypes, aggFnRetType);
// If we have input arguments, set type to null (instead of aggFnRetType) to let
// AggregateCall
// infer the type, so as to avoid nullability mismatch
RelDataType type = null;
if (aggInfo.isAllColumns() && argIndices.isEmpty()) {
type = aggFnRetType;
}
return AggregateCall.create((SqlAggFunction) funcConverter.convertOperator(aggFunc), aggInfo.isDistinct(), false, false, argIndices, -1, RelCollations.EMPTY, groupCount, input, type, aggInfo.getAlias());
}
Aggregations