Package org.apache.flink.table.connector
Class Projection
- java.lang.Object
-
- org.apache.flink.table.connector.Projection
-
@PublicEvolving public abstract class Projection extends Object
Projectionrepresents 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 Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static Projectionall(DataType dataType)Create aProjectionof all the fields in the provideddataType.abstract Projectioncomplement(int fieldsNumber)Complement this projection.Projectioncomplement(DataType dataType)Likecomplement(int), using thedataTypefields count.abstract Projectiondifference(Projection other)Perform a difference of thisProjectionwith anotherProjection.static Projectionempty()Create an emptyProjection, that is a projection that projects no fields, returning an emptyDataType.booleanequals(Object o)static ProjectionfromFieldNames(DataType dataType, List<String> projectedFields)inthashCode()abstract booleanisNested()static Projectionof(int[] indexes)Create aProjectionof the providedindexes.static Projectionof(int[][] indexes)Create aProjectionof the providedindexes.abstract DataTypeproject(DataType dataType)Projects a (possibly nested) row data type by returning a new data type that only includes fields of the given index paths.LogicalTypeproject(LogicalType logicalType)Same asproject(DataType), but accepting and returningLogicalType.static Projectionrange(int startInclusive, int endExclusive)Create aProjectionof a field range.abstract int[][]toNestedIndexes()Convert this instance to a nested projection index paths.StringtoString()abstract int[]toTopLevelIndexes()Convert this instance to a projection of top level indexes.
-
-
-
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 fieldbinside the row fieldaof the rootDataTypeis nameda_bin the resultDataType. In case of naming conflicts the postfix notation '_$%d' is used, where%dis an arbitrary number, in order to generate a unique field name. For example if the rootDataTypeincludes both a fielda_band a nested rowawith fieldb, the resultDataTypewill contain one field nameda_band the other nameda_b_1.
-
project
public LogicalType project(LogicalType logicalType)
Same asproject(DataType), but accepting and returningLogicalType.
-
isNested
public abstract boolean isNested()
- Returns:
truewhether this projection is nested or not.
-
difference
public abstract Projection difference(Projection other)
Perform a difference of thisProjectionwith anotherProjection. The result of this operation is a newProjectionretaining the same ordering of this instance but with the indexes fromotherremoved. For example:[4, 1, 0, 3, 2] - [4, 2] = [1, 0, 2]Note how the index
3in the minuend becomes2because it's rescaled to project correctly aRowDataor arity 3.- Parameters:
other- the subtrahend- Throws:
IllegalArgumentException- whenotheris nested.
-
complement
public abstract Projection complement(int fieldsNumber)
Complement this projection. The returned projection is an ordered projection of fields from 0 tofieldsNumberexcept the indexes in thisProjection. For example:[4, 2].complement(5) = [0, 1, 3]- Parameters:
fieldsNumber- the size of the universe- Throws:
IllegalStateException- if this projection is nested.
-
complement
public Projection complement(DataType dataType)
Likecomplement(int), using thedataTypefields count.
-
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 originalDataType. 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 originalDataType, 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 emptyProjection, that is a projection that projects no fields, returning an emptyDataType.
-
of
public static Projection of(int[] indexes)
Create aProjectionof the providedindexes.- See Also:
toTopLevelIndexes()
-
of
public static Projection of(int[][] indexes)
Create aProjectionof the providedindexes.- See Also:
toNestedIndexes()
-
fromFieldNames
public static Projection fromFieldNames(DataType dataType, List<String> projectedFields)
-
all
public static Projection all(DataType dataType)
Create aProjectionof all the fields in the provideddataType.
-
range
public static Projection range(int startInclusive, int endExclusive)
Create aProjectionof a field range.
-
-