Class PhysTypeImpl

java.lang.Object
org.apache.calcite.adapter.enumerable.PhysTypeImpl
All Implemented Interfaces:
PhysType

public class PhysTypeImpl extends Object implements PhysType
Implementation of PhysType.
  • Method Details

    • of

      public static PhysType of(JavaTypeFactory typeFactory, RelDataType rowType, JavaRowFormat format)
    • of

      public static PhysType of(JavaTypeFactory typeFactory, RelDataType rowType, JavaRowFormat format, boolean optimize)
    • getFormat

      public JavaRowFormat getFormat()
      Description copied from interface: PhysType
      Returns the format.
      Specified by:
      getFormat in interface PhysType
    • getTypeFactory

      public JavaTypeFactory getTypeFactory()
      Description copied from interface: PhysType
      Returns the type factory.
      Specified by:
      getTypeFactory in interface PhysType
    • project

      public PhysType project(List<Integer> integers, JavaRowFormat format)
      Description copied from interface: PhysType
      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.
      Specified by:
      project in interface PhysType
    • project

      public PhysType project(List<Integer> integers, boolean indicator, JavaRowFormat format)
      Description copied from interface: PhysType
      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.

      Specified by:
      project in interface PhysType
    • generateSelector

      public Expression generateSelector(ParameterExpression parameter, List<Integer> fields)
      Description copied from interface: PhysType
      Generates a selector for the given fields from an expression, with the default row format.
      Specified by:
      generateSelector in interface PhysType
    • generateSelector

      public Expression generateSelector(ParameterExpression parameter, List<Integer> fields, JavaRowFormat targetFormat)
      Description copied from interface: PhysType
      Generates a lambda expression that is a selector for the given fields from an expression.
      Specified by:
      generateSelector in interface PhysType
    • generateSelector

      public Expression generateSelector(ParameterExpression parameter, List<Integer> fields, List<Integer> usedFields, JavaRowFormat targetFormat)
      Description copied from interface: PhysType
      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.

      Specified by:
      generateSelector in interface PhysType
    • selector

      public Pair<Type,List<Expression>> selector(ParameterExpression parameter, List<Integer> fields, JavaRowFormat targetFormat)
      Description copied from interface: PhysType
      Generates a selector for the given fields from an expression. Only used by EnumerableWindow.
      Specified by:
      selector in interface PhysType
    • accessors

      public List<Expression> accessors(Expression v1, List<Integer> argList)
      Specified by:
      accessors in interface PhysType
    • makeNullable

      public PhysType makeNullable(boolean nullable)
      Description copied from interface: PhysType
      Returns a copy of this type that allows nulls if nullable is true.
      Specified by:
      makeNullable in interface PhysType
    • convertTo

      public Expression convertTo(Expression exp, PhysType targetPhysType)
      Description copied from interface: PhysType
      Converts an enumerable of this physical type to an enumerable that uses a given physical type for its rows.
      Specified by:
      convertTo in interface PhysType
    • convertTo

      public Expression convertTo(Expression exp, JavaRowFormat targetFormat)
      Description copied from interface: PhysType
      Converts an enumerable of this physical type to an enumerable that uses the targetFormat for representing its rows.
      Specified by:
      convertTo in interface PhysType
    • generateCollationKey

      public Pair<Expression,Expression> generateCollationKey(List<RelFieldCollation> collations)
      Description copied from interface: PhysType
      Returns a lambda to create a collation key and a comparator. The comparator is sometimes null.
      Specified by:
      generateCollationKey in interface PhysType
    • generateComparator

      public Expression generateComparator(RelCollation collation)
      Description copied from interface: PhysType
      Returns a comparator. Unlike the comparator returned by PhysType.generateCollationKey(java.util.List), this comparator acts on the whole element.
      Specified by:
      generateComparator in interface PhysType
    • generateMergeJoinComparator

      public Expression generateMergeJoinComparator(RelCollation collation)
      Description copied from interface: PhysType
      Similar to PhysType.generateComparator(RelCollation), but with some specificities for MergeJoin algorithm: it will not consider two null values as equal.
      Specified by:
      generateMergeJoinComparator in interface PhysType
      See Also:
    • getRowType

      public RelDataType getRowType()
      Description copied from interface: PhysType
      Returns the SQL row type.
      Specified by:
      getRowType in interface PhysType
    • record

      public Expression record(List<Expression> expressions)
      Description copied from interface: PhysType
      Generates an expression that creates a record for a row, initializing its fields with the given expressions. There must be one expression per field.
      Specified by:
      record in interface PhysType
      Parameters:
      expressions - Expression to initialize each field
      Returns:
      Expression to create a row
    • getJavaRowType

      public Type getJavaRowType()
      Description copied from interface: PhysType
      Returns the Java type (often a Class) that represents a row. For example, in one row format, always returns Object[].class.
      Specified by:
      getJavaRowType in interface PhysType
    • getJavaFieldType

      public Type getJavaFieldType(int index)
      Description copied from interface: PhysType
      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.

      Specified by:
      getJavaFieldType in interface PhysType
    • component

      public PhysType component(int fieldOrdinal)
      Description copied from interface: PhysType
      Returns the physical type of a given field's component type.
      Specified by:
      component in interface PhysType
    • field

      public PhysType field(int ordinal)
      Description copied from interface: PhysType
      Returns the physical type of a field.
      Specified by:
      field in interface PhysType
    • comparer

      public @Nullable Expression comparer()
      Description copied from interface: PhysType
      Returns a expression that yields a comparer, or null if this type is comparable.
      Specified by:
      comparer in interface PhysType
    • fieldClass

      public Class fieldClass(int field)
      Description copied from interface: PhysType
      Returns the Java class of the field with the given ordinal.
      Specified by:
      fieldClass in interface PhysType
    • fieldNullable

      public boolean fieldNullable(int field)
      Description copied from interface: PhysType
      Returns whether a given field allows null values.
      Specified by:
      fieldNullable in interface PhysType
    • generateAccessor

      public Expression generateAccessor(List<Integer> fields)
      Description copied from interface: PhysType
      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>);
          }
       }
      Specified by:
      generateAccessor in interface PhysType
    • generateAccessorWithoutNulls

      public Expression generateAccessorWithoutNulls(List<Integer> fields)
      Description copied from interface: PhysType
      Similar to PhysType.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>);
          }
       }
      Specified by:
      generateAccessorWithoutNulls in interface PhysType
    • fieldReference

      public Expression fieldReference(Expression expression, int field)
      Description copied from interface: PhysType
      Generates a reference to a given field in an expression.

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

      employee.deptno
      Specified by:
      fieldReference in interface PhysType
      Parameters:
      expression - Expression
      field - Ordinal of field
      Returns:
      Expression to access the field of the expression
    • fieldReference

      public Expression fieldReference(Expression expression, int field, @Nullable Type storageType)
      Description copied from interface: PhysType
      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
      Specified by:
      fieldReference in interface PhysType
      Parameters:
      expression - Expression
      field - Ordinal of field
      storageType - optional hint for storage class
      Returns:
      Expression to access the field of the expression