Ejemplo n.º 1
0
 /**
  * Creates an expression accessing a given named field from a record.
  *
  * <p>NOTE: Be careful choosing the value of {@code caseSensitive}. If the field name was supplied
  * by an end-user (e.g. as a column alias in SQL), use your session's case-sensitivity setting.
  * Only hard-code {@code true} if you are sure that the field name is internally generated.
  * Hard-coding {@code false} is almost certainly wrong.
  *
  * @param expr Expression yielding a record
  * @param fieldName Name of field in record
  * @param caseSensitive Whether match is case-sensitive
  * @return Expression accessing a given named field
  */
 public RexNode makeFieldAccess(RexNode expr, String fieldName, boolean caseSensitive) {
   final RelDataType type = expr.getType();
   final RelDataTypeField field = type.getField(fieldName, caseSensitive, false);
   if (field == null) {
     throw Util.newInternal("Type '" + type + "' has no field '" + fieldName + "'");
   }
   return makeFieldAccessInternal(expr, field);
 }
Ejemplo n.º 2
0
 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<>(columnNameList.size());
   for (String name : columnNameList) {
     RelDataTypeField field = type.getField(name, caseSensitive, false);
     fields.add(type.getFieldList().get(field.getIndex()));
   }
   return typeFactory.createStructType(fields);
 }
Ejemplo n.º 3
0
 /**
  * Looks up a field with a given name, returning null if not found.
  *
  * @param caseSensitive Whether match is case-sensitive
  * @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) {
   return rowType.getField(columnName, caseSensitive, false);
 }