Search in sources :

Example 1 with JavaRecordType

use of org.apache.calcite.jdbc.JavaRecordType 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));
}
Also used : Field(java.lang.reflect.Field) RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) RelDataType(org.apache.calcite.rel.type.RelDataType) RelRecordType(org.apache.calcite.rel.type.RelRecordType) Type(java.lang.reflect.Type) JavaRecordType(org.apache.calcite.jdbc.JavaRecordType) JavaRecordType(org.apache.calcite.jdbc.JavaRecordType) ArrayList(java.util.ArrayList) RelDataTypeFieldImpl(org.apache.calcite.rel.type.RelDataTypeFieldImpl)

Aggregations

Field (java.lang.reflect.Field)1 Type (java.lang.reflect.Type)1 ArrayList (java.util.ArrayList)1 JavaRecordType (org.apache.calcite.jdbc.JavaRecordType)1 RelDataType (org.apache.calcite.rel.type.RelDataType)1 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)1 RelDataTypeFieldImpl (org.apache.calcite.rel.type.RelDataTypeFieldImpl)1 RelRecordType (org.apache.calcite.rel.type.RelRecordType)1