Class Projection


  • @PublicEvolving
    public abstract class Projection
    extends Object
    Projection represents a list of (possibly nested) indexes that can be used to project data types. A row projection includes both reducing the accessible fields and reordering them.
    • Method Detail

      • project

        public abstract DataType project​(DataType dataType)
        Projects a (possibly nested) row data type by returning a new data type that only includes fields of the given index paths.

        When extracting nested fields, the name of the resulting fields is the full path of the field separated by _. For example, the field b inside the row field a of the root DataType is named a_b in the result DataType. In case of naming conflicts the postfix notation '_$%d' is used, where %d is an arbitrary number, in order to generate a unique field name. For example if the root DataType includes both a field a_b and a nested row a with field b, the result DataType will contain one field named a_b and the other named a_b_1.

      • isNested

        public abstract boolean isNested()
        Returns:
        true whether this projection is nested or not.
      • difference

        public abstract Projection difference​(Projection other)
        Perform a difference of this Projection with another Projection. The result of this operation is a new Projection retaining the same ordering of this instance but with the indexes from other removed. For example:
         
         [4, 1, 0, 3, 2] - [4, 2] = [1, 0, 2]
         
         

        Note how the index 3 in the minuend becomes 2 because it's rescaled to project correctly a RowData or arity 3.

        Parameters:
        other - the subtrahend
        Throws:
        IllegalArgumentException - when other is nested.
      • complement

        public abstract Projection complement​(int fieldsNumber)
        Complement this projection. The returned projection is an ordered projection of fields from 0 to fieldsNumber except the indexes in this Projection. For example:
         
         [4, 2].complement(5) = [0, 1, 3]
         
         
        Parameters:
        fieldsNumber - the size of the universe
        Throws:
        IllegalStateException - if this projection is nested.
      • toTopLevelIndexes

        public abstract int[] toTopLevelIndexes()
        Convert this instance to a projection of top level indexes. The array represents the mapping of the fields of the original DataType. For example, [0, 2, 1] specifies to include in the following order the 1st field, the 3rd field and the 2nd field of the row.
        Throws:
        IllegalStateException - if this projection is nested.
      • toNestedIndexes

        public abstract int[][] toNestedIndexes()
        Convert this instance to a nested projection index paths. The array represents the mapping of the fields of the original DataType, including nested rows. For example, [[0, 2, 1], ...] specifies to include the 2nd field of the 3rd field of the 1st field in the top-level row.
      • empty

        public static Projection empty()
        Create an empty Projection, that is a projection that projects no fields, returning an empty DataType.
      • fromFieldNames

        public static Projection fromFieldNames​(DataType dataType,
                                                List<String> projectedFields)
        Create a Projection of the provided dataType using the provided projectedFields.
      • range

        public static Projection range​(int startInclusive,
                                       int endExclusive)
        Create a Projection of a field range.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object