/** * Looks up a field with a given name, returning null if not found. * * @param rowType Row type * @param columnName Field name * @return Field, or null if not found */ public static RelDataTypeField lookupField( boolean caseSensitive, final RelDataType rowType, String columnName) { RelDataTypeField field = rowType.getField(columnName, caseSensitive); if (field != null) { return field; } // If record type is flagged as having "any field you ask for", // return a type. (TODO: Better way to mark accommodating types.) RelDataTypeField extra = RelDataTypeImpl.extra(rowType); if (extra != null) { return new RelDataTypeFieldImpl(columnName, -1, extra.getType()); } return null; }
public static RelDataType createTypeFromProjection( RelDataType type, List<String> columnNameList, RelDataTypeFactory typeFactory, boolean caseSensitive) { // If the names in columnNameList and type have case-sensitive differences, // the resulting type will use those from type. These are presumably more // canonical. final List<RelDataTypeField> fields = new ArrayList<RelDataTypeField>(columnNameList.size()); for (String name : columnNameList) { RelDataTypeField field = type.getField(name, caseSensitive); fields.add(type.getFieldList().get(field.getIndex())); } return typeFactory.createStructType(fields); }