Search in sources :

Example 1 with RelDataTypeFieldImpl

use of org.apache.calcite.rel.type.RelDataTypeFieldImpl 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)

Example 2 with RelDataTypeFieldImpl

use of org.apache.calcite.rel.type.RelDataTypeFieldImpl in project calcite by apache.

the class SqlTypeUtil method flattenFields.

private static boolean flattenFields(RelDataTypeFactory typeFactory, RelDataType type, List<RelDataTypeField> list, int[] flatteningMap) {
    boolean nested = false;
    if (needsNullIndicator(type)) {
        // NOTE jvs 9-Mar-2005:  other code
        // (e.g. RelStructuredTypeFlattener) relies on the
        // null indicator field coming first.
        RelDataType indicatorType = typeFactory.createSqlType(SqlTypeName.BOOLEAN);
        if (type.isNullable()) {
            indicatorType = typeFactory.createTypeWithNullability(indicatorType, true);
        }
        RelDataTypeField nullIndicatorField = new RelDataTypeFieldImpl("NULL_VALUE", 0, indicatorType);
        list.add(nullIndicatorField);
        nested = true;
    }
    for (RelDataTypeField field : type.getFieldList()) {
        if (flatteningMap != null) {
            flatteningMap[field.getIndex()] = list.size();
        }
        if (field.getType().isStruct()) {
            nested = true;
            flattenFields(typeFactory, field.getType(), list, null);
        } else if (field.getType().getComponentType() != null) {
            nested = true;
            // TODO jvs 14-Feb-2005:  generalize to any kind of
            // collection type
            RelDataType flattenedCollectionType = typeFactory.createMultisetType(flattenRecordType(typeFactory, field.getType().getComponentType(), null), -1);
            field = new RelDataTypeFieldImpl(field.getName(), field.getIndex(), flattenedCollectionType);
            list.add(field);
        } else {
            list.add(field);
        }
    }
    return nested;
}
Also used : RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) RelDataType(org.apache.calcite.rel.type.RelDataType) RelDataTypeFieldImpl(org.apache.calcite.rel.type.RelDataTypeFieldImpl)

Example 3 with RelDataTypeFieldImpl

use of org.apache.calcite.rel.type.RelDataTypeFieldImpl in project drill by axbaretto.

the class ExtendableRelDataTypeHolder method getField.

/**
 * Returns RelDataTypeField field with specified name.
 * If field is implicit and absent in the fields list, it will be added.
 *
 * @param typeFactory RelDataTypeFactory which will be used
 *                    for the creation of RelDataType for new fields.
 * @param fieldName   name of the field.
 * @return RelDataTypeField field
 */
public RelDataTypeField getField(RelDataTypeFactory typeFactory, String fieldName) {
    /* First check if this field name exists in our field list */
    for (RelDataTypeField f : fields) {
        if (fieldName.equalsIgnoreCase(f.getName())) {
            return f;
        }
    }
    RelDataTypeField newField = null;
    if (isImplicitField(fieldName)) {
        // This implicit field does not exist in our field list, add it
        newField = new RelDataTypeFieldImpl(fieldName, fields.size(), typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.VARCHAR), true));
        fields.add(newField);
    }
    return newField;
}
Also used : RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) RelDataTypeFieldImpl(org.apache.calcite.rel.type.RelDataTypeFieldImpl)

Example 4 with RelDataTypeFieldImpl

use of org.apache.calcite.rel.type.RelDataTypeFieldImpl in project drill by axbaretto.

the class RelDataTypeHolder method getField.

public RelDataTypeField getField(RelDataTypeFactory typeFactory, String fieldName) {
    /* First check if this field name exists in our field list */
    for (RelDataTypeField f : fields) {
        if (fieldName.equalsIgnoreCase(f.getName())) {
            return f;
        }
    }
    /* This field does not exist in our field list add it */
    final SqlTypeName typeName = DynamicRecordType.isDynamicStarColName(fieldName) ? SqlTypeName.DYNAMIC_STAR : SqlTypeName.ANY;
    // This field does not exist in our field list add it
    RelDataTypeField newField = new RelDataTypeFieldImpl(fieldName, fields.size(), typeFactory.createTypeWithNullability(typeFactory.createSqlType(typeName), true));
    /* Add the name to our list of field names */
    fields.add(newField);
    return newField;
}
Also used : RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) SqlTypeName(org.apache.calcite.sql.type.SqlTypeName) RelDataTypeFieldImpl(org.apache.calcite.rel.type.RelDataTypeFieldImpl)

Example 5 with RelDataTypeFieldImpl

use of org.apache.calcite.rel.type.RelDataTypeFieldImpl in project drill by apache.

the class RelDataTypeHolder method getField.

public RelDataTypeField getField(RelDataTypeFactory typeFactory, String fieldName) {
    /* First check if this field name exists in our field list */
    for (RelDataTypeField f : fields) {
        if (fieldName.equalsIgnoreCase(f.getName())) {
            return f;
        }
    }
    /* This field does not exist in our field list add it */
    final SqlTypeName typeName = DynamicRecordType.isDynamicStarColName(fieldName) ? SqlTypeName.DYNAMIC_STAR : SqlTypeName.ANY;
    // This field does not exist in our field list add it
    RelDataTypeField newField = new RelDataTypeFieldImpl(fieldName, fields.size(), typeFactory.createTypeWithNullability(typeFactory.createSqlType(typeName), true));
    /* Add the name to our list of field names */
    fields.add(newField);
    return newField;
}
Also used : RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) SqlTypeName(org.apache.calcite.sql.type.SqlTypeName) RelDataTypeFieldImpl(org.apache.calcite.rel.type.RelDataTypeFieldImpl)

Aggregations

RelDataTypeFieldImpl (org.apache.calcite.rel.type.RelDataTypeFieldImpl)26 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)25 RelRecordType (org.apache.calcite.rel.type.RelRecordType)15 ArrayList (java.util.ArrayList)14 RelDataType (org.apache.calcite.rel.type.RelDataType)8 RexNode (org.apache.calcite.rex.RexNode)8 RelNode (org.apache.calcite.rel.RelNode)6 Type (java.lang.reflect.Type)4 RexInputRef (org.apache.calcite.rex.RexInputRef)4 ImmutableList (com.google.common.collect.ImmutableList)3 JavaRecordType (org.apache.calcite.jdbc.JavaRecordType)3 Field (java.lang.reflect.Field)2 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)2 SqlTypeName (org.apache.calcite.sql.type.SqlTypeName)2 NlsString (org.apache.calcite.util.NlsString)2 LogicalExpression (org.apache.drill.common.expression.LogicalExpression)2 SchemaPath (org.apache.drill.common.expression.SchemaPath)2 NamedExpression (org.apache.drill.common.logical.data.NamedExpression)2 DbGroupScan (org.apache.drill.exec.physical.base.DbGroupScan)2 Prel (org.apache.drill.exec.planner.physical.Prel)2