Interface PhysType

All Known Implementing Classes:
PhysTypeImpl

public interface PhysType
Physical type of a row.

Consists of the SQL row type (returned by getRowType()), the Java type of the row (returned by getJavaRowType()), and methods to generate expressions to access fields, generate records, and so forth. Together, the records encapsulate how the logical type maps onto the physical type.

  • Method Details

    • getJavaRowType

      Type getJavaRowType()
      Returns the Java type (often a Class) that represents a row. For example, in one row format, always returns Object[].class.
    • getJavaFieldType

      Type getJavaFieldType(int field)
      Returns the Java class that is used to store the field with the given ordinal.

      For instance, when the java row type is Object[], the java field type is Object even if the field is not nullable.

    • getTypeFactory

      JavaTypeFactory getTypeFactory()
      Returns the type factory.
    • field

      PhysType field(int ordinal)
      Returns the physical type of a field.
    • component

      PhysType component(int field)
      Returns the physical type of a given field's component type.
    • getRowType

      RelDataType getRowType()
      Returns the SQL row type.
    • fieldClass

      Class fieldClass(int field)
      Returns the Java class of the field with the given ordinal.
    • fieldNullable

      boolean fieldNullable(int index)
      Returns whether a given field allows null values.
    • fieldReference

      Expression fieldReference(Expression expression, int field)
      Generates a reference to a given field in an expression.

      For example given expression=employee and field=2, generates

      employee.deptno
      Parameters:
      expression - Expression
      field - Ordinal of field
      Returns:
      Expression to access the field of the expression
    • fieldReference

      Expression fieldReference(Expression expression, int field, @Nullable Type storageType)
      Generates a reference to a given field in an expression.

      This method optimizes for the target storage type (i.e. avoids casts).

      For example given expression=employee and field=2, generates

      employee.deptno
      Parameters:
      expression - Expression
      field - Ordinal of field
      storageType - optional hint for storage class
      Returns:
      Expression to access the field of the expression
    • generateAccessor

      Expression generateAccessor(List<Integer> fields)
      Generates an accessor function for a given list of fields. The resulting object is a List (implementing Object.hashCode() and Object.equals(Object) per that interface) and also implements Comparable.

      For example:

       new Function1<Employee, Object[]> {
          public Object[] apply(Employee v1) {
              return FlatLists.of(v1.<fieldN>, v1.<fieldM>);
          }
       }
    • generateAccessorWithoutNulls

      Expression generateAccessorWithoutNulls(List<Integer> fields)
      Similar to generateAccessor(List), but if one of the fields is null, it will return null.

      For example:

       new Function1<Employee, Object[]> {
          public Object[] apply(Employee v1) {
              return v1.<fieldN> == null
                  ? null
                  : v1.<fieldM> == null
                      ? null
                      : FlatLists.of(v1.<fieldN>, v1.<fieldM>);
          }
       }
    • generateSelector

      Expression generateSelector(ParameterExpression parameter, List<Integer> fields)
      Generates a selector for the given fields from an expression, with the default row format.
    • generateSelector

      Expression generateSelector(ParameterExpression parameter, List<Integer> fields, JavaRowFormat targetFormat)
      Generates a lambda expression that is a selector for the given fields from an expression.
    • generateSelector

      Expression generateSelector(ParameterExpression parameter, List<Integer> fields, List<Integer> usedFields, JavaRowFormat targetFormat)
      Generates a lambda expression that is a selector for the given fields from an expression.

      usedFields must be a subset of fields. For each field, there is a corresponding indicator field. If a field is used, its value is assigned and its indicator is left false. If a field is not used, its value is not assigned and its indicator is set to true; This will become a value of 1 when GROUPING(field) is called.

    • selector

      Pair<Type,List<Expression>> selector(ParameterExpression parameter, List<Integer> fields, JavaRowFormat targetFormat)
      Generates a selector for the given fields from an expression. Only used by EnumerableWindow.
    • project

      PhysType project(List<Integer> integers, JavaRowFormat format)
      Projects a given collection of fields from this input record, into a particular preferred output format. The output format is optimized if there are 0 or 1 fields.
    • project

      PhysType project(List<Integer> integers, boolean indicator, JavaRowFormat format)
      Projects a given collection of fields from this input record, optionally with indicator fields, into a particular preferred output format.

      The output format is optimized if there are 0 or 1 fields and indicators are disabled.

    • generateCollationKey

      Pair<Expression,Expression> generateCollationKey(List<RelFieldCollation> collations)
      Returns a lambda to create a collation key and a comparator. The comparator is sometimes null.
    • generateComparator

      Expression generateComparator(RelCollation collation)
      Returns a comparator. Unlike the comparator returned by generateCollationKey(java.util.List), this comparator acts on the whole element.
    • generateMergeJoinComparator

      Expression generateMergeJoinComparator(RelCollation collation)
      Similar to generateComparator(RelCollation), but with some specificities for MergeJoin algorithm: it will not consider two null values as equal.
      See Also:
    • comparer

      @Nullable Expression comparer()
      Returns a expression that yields a comparer, or null if this type is comparable.
    • record

      Expression record(List<Expression> expressions)
      Generates an expression that creates a record for a row, initializing its fields with the given expressions. There must be one expression per field.
      Parameters:
      expressions - Expression to initialize each field
      Returns:
      Expression to create a row
    • getFormat

      JavaRowFormat getFormat()
      Returns the format.
    • accessors

      List<Expression> accessors(Expression parameter, List<Integer> argList)
    • makeNullable

      PhysType makeNullable(boolean nullable)
      Returns a copy of this type that allows nulls if nullable is true.
    • convertTo

      @Deprecated Expression convertTo(Expression expression, PhysType targetPhysType)
      Deprecated.
      Use convertTo(Expression, JavaRowFormat). The use of PhysType as a second parameter is misleading since only the row format of the expression is affected by the conversion. Moreover it requires to have at hand a PhysType object which is not really necessary for achieving the desired result.
      Converts an enumerable of this physical type to an enumerable that uses a given physical type for its rows.
    • convertTo

      Expression convertTo(Expression expression, JavaRowFormat targetFormat)
      Converts an enumerable of this physical type to an enumerable that uses the targetFormat for representing its rows.