use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataTypeField in project calcite by apache.
the class GeodeUtils method handleStructEntry.
private static Object handleStructEntry(List<RelDataTypeField> relDataTypeFields, Object obj) {
Struct struct = (Struct) obj;
Object[] values = new Object[relDataTypeFields.size()];
int index = 0;
for (RelDataTypeField relDataTypeField : relDataTypeFields) {
Type javaType = JAVA_TYPE_FACTORY.getJavaClass(relDataTypeField.getType());
Object rawValue;
try {
rawValue = struct.get(relDataTypeField.getName());
} catch (IllegalArgumentException e) {
rawValue = "<error>";
System.err.println("Could find field : " + relDataTypeField.getName());
e.printStackTrace();
}
values[index++] = convert(rawValue, (Class) javaType);
}
if (values.length == 1) {
return values[0];
}
return values;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataTypeField in project calcite by apache.
the class JavaTypeFactoryExtImpl method createPdxType2.
// Experimental flattering the nested structures.
public RelDataType createPdxType2(PdxInstance pdxInstance) {
final List<RelDataTypeField> list = new ArrayList<>();
recursiveCreatePdxType(pdxInstance, list, "");
return canonize(new RelRecordType(list));
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataTypeField in project calcite by apache.
the class JavaTypeFactoryExtImpl method createStructType.
/**
* See <a href="http://stackoverflow.com/questions/16966629/what-is-the-difference-between-getfields-and-getdeclaredfields-in-java-reflectio">
* the difference between fields and declared fields</a>.
*/
@Override
public RelDataType createStructType(Class type) {
final List<RelDataTypeField> list = new ArrayList<>();
for (Field field : type.getDeclaredFields()) {
if (!Modifier.isStatic(field.getModifiers())) {
// FIXME: watch out for recursion
final Type fieldType = field.getType();
list.add(new RelDataTypeFieldImpl(field.getName(), list.size(), createType(fieldType)));
}
}
return canonize(new JavaRecordType(list, type));
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataTypeField in project calcite by apache.
the class PhysTypeImpl method field.
public PhysType field(int ordinal) {
final RelDataTypeField field = rowType.getFieldList().get(ordinal);
final RelDataType type = field.getType();
return PhysTypeImpl.of(typeFactory, toStruct(type), format, false);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataTypeField 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