use of org.apache.calcite.runtime.SqlFunctions.FlatProductInputType in project calcite by apache.
the class EnumerableUncollect method implement.
public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
final BlockBuilder builder = new BlockBuilder();
final EnumerableRel child = (EnumerableRel) getInput();
final Result result = implementor.visitChild(this, 0, child, pref);
final PhysType physType = PhysTypeImpl.of(implementor.getTypeFactory(), getRowType(), JavaRowFormat.LIST);
// final Enumerable<List<Employee>> child = <<child adapter>>;
// return child.selectMany(FLAT_PRODUCT);
final Expression child_ = builder.append("child", result.block);
final List<Integer> fieldCounts = new ArrayList<>();
final List<FlatProductInputType> inputTypes = new ArrayList<>();
for (RelDataTypeField field : child.getRowType().getFieldList()) {
final RelDataType type = field.getType();
if (type instanceof MapSqlType) {
fieldCounts.add(2);
inputTypes.add(FlatProductInputType.MAP);
} else {
final RelDataType elementType = type.getComponentType();
if (elementType.isStruct()) {
fieldCounts.add(elementType.getFieldCount());
inputTypes.add(FlatProductInputType.LIST);
} else {
fieldCounts.add(-1);
inputTypes.add(FlatProductInputType.SCALAR);
}
}
}
final Expression lambda = Expressions.call(BuiltInMethod.FLAT_PRODUCT.method, Expressions.constant(Ints.toArray(fieldCounts)), Expressions.constant(withOrdinality), Expressions.constant(inputTypes.toArray(new FlatProductInputType[inputTypes.size()])));
builder.add(Expressions.return_(null, Expressions.call(child_, BuiltInMethod.SELECT_MANY.method, lambda)));
return implementor.result(physType, builder.toBlock());
}
Aggregations