use of org.apache.beam.vendor.calcite.v1_28_0.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));
}
use of org.apache.beam.vendor.calcite.v1_28_0.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;
}
use of org.apache.beam.vendor.calcite.v1_28_0.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;
}
use of org.apache.beam.vendor.calcite.v1_28_0.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;
}
use of org.apache.beam.vendor.calcite.v1_28_0.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;
}
Aggregations