Package org.apache.flink.table.connector
Class Projection
- java.lang.Object
-
- org.apache.flink.table.connector.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 Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static Projection
all(DataType dataType)
Create aProjection
of all the fields in the provideddataType
.abstract Projection
complement(int fieldsNumber)
Complement this projection.Projection
complement(DataType dataType)
Likecomplement(int)
, using thedataType
fields count.abstract Projection
difference(Projection other)
Perform a difference of thisProjection
with anotherProjection
.static Projection
empty()
Create an emptyProjection
, that is a projection that projects no fields, returning an emptyDataType
.boolean
equals(Object o)
static Projection
fromFieldNames(DataType dataType, List<String> projectedFields)
int
hashCode()
abstract boolean
isNested()
static Projection
of(int[] indexes)
Create aProjection
of the providedindexes
.static Projection
of(int[][] indexes)
Create aProjection
of the providedindexes
.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.LogicalType
project(LogicalType logicalType)
Same asproject(DataType)
, but accepting and returningLogicalType
.static Projection
range(int startInclusive, int endExclusive)
Create aProjection
of a field range.abstract int[][]
toNestedIndexes()
Convert this instance to a nested projection index paths.String
toString()
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 fieldb
inside the row fielda
of the rootDataType
is nameda_b
in the resultDataType
. 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 rootDataType
includes both a fielda_b
and a nested rowa
with fieldb
, the resultDataType
will contain one field nameda_b
and the other nameda_b_1
.
-
project
public LogicalType project(LogicalType logicalType)
Same asproject(DataType)
, but accepting and returningLogicalType
.
-
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 thisProjection
with anotherProjection
. The result of this operation is a newProjection
retaining the same ordering of this instance but with the indexes fromother
removed. For example:[4, 1, 0, 3, 2] - [4, 2] = [1, 0, 2]
Note how the index
3
in the minuend becomes2
because it's rescaled to project correctly aRowData
or arity 3.- Parameters:
other
- the subtrahend- Throws:
IllegalArgumentException
- whenother
is nested.
-
complement
public abstract Projection complement(int fieldsNumber)
Complement this projection. The returned projection is an ordered projection of fields from 0 tofieldsNumber
except 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 thedataType
fields 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 aProjection
of the providedindexes
.- See Also:
toTopLevelIndexes()
-
of
public static Projection of(int[][] indexes)
Create aProjection
of the providedindexes
.- See Also:
toNestedIndexes()
-
fromFieldNames
public static Projection fromFieldNames(DataType dataType, List<String> projectedFields)
-
all
public static Projection all(DataType dataType)
Create aProjection
of all the fields in the provideddataType
.
-
range
public static Projection range(int startInclusive, int endExclusive)
Create aProjection
of a field range.
-
-