Class RequestedTupleImpl
java.lang.Object
org.apache.drill.exec.physical.resultSet.project.RequestedTupleImpl
- All Implemented Interfaces:
RequestedTuple
Represents an explicit projection at some tuple level. A tuple is the
top-level row or a map.
A column is projected if it is explicitly listed in the selection list.
If a column is a map, then the projection for the map's columns is based on two rules:
- If the projection list includes at least one explicit mention of a map member, then include only those columns explicitly listed.
- If the projection at the parent level lists only the map column itself (which the projection can't know is a map), then assume this implies all columns, as if the entry where "map.*".
Examples:
m
If m
turns out to be a map, project all members of
m
.
m.a
Column m
must be a map. Project only column a
.
m, m.a
Tricky case. We interpret this as projecting only the "a" element of map m.
The projection set is built from a list of columns, represented as
SchemaPath
objects, provided by the physical plan. The structure of
SchemaPath is a bit awkward:
- SchemaPath> is a wrapper for a column which directly holds the NameSegment for the top-level column.
- NameSegment holds a name. This can be a top name such as `a`, or parts of a compound name such as `a`.`b`. Each NameSegment has a "child" that points to the option following parts of the name.
- <PathSegment is the base class for the parts of a name.
- ArraySegment is the other kind of name part and represents an array index such as the "[1]" in `columns`[1].
-
The parser considers names and array indexes. Example:
a
a.b
a[2]
a[2].b
a[1][2][3]
a[1][2][3].b.c
a['foo'][0].b['bar']
Usage
The projection information is a pattern which supports queries of the form "is this column projected", and "if projected, is the projection consistent with such-and-so concrete type?" Clients should not try to work out the meaning of the pattern: doing so is very complex. Instead, do the following:
String colName = ...;
ColumnMetadata colDef = ...;
InputTupleProjection tupleProj = ...
if (tupleProj.isProjected(colName)) {
if (!tupleProj.isComsistentWith(colDef)) {
// Raise an error
}
// Handle a projected column.
}
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.drill.exec.physical.resultSet.project.RequestedTuple
RequestedTuple.TupleProjectionType
-
Field Summary
-
Constructor Summary
ConstructorDescription -
Method Summary
Modifier and TypeMethodDescriptionvoid
buildName
(StringBuilder buf) boolean
enforceProjection
(ColumnMetadata columnSchema, CustomErrorContext errorContext) get
(int i) protected RequestedColumnImpl
boolean
isEmpty()
Report if the projection is empty as occurs inSELECT COUNT(*) FROM ...
.boolean
isProjected
(String colName) boolean
isProjected
(ColumnMetadata columnSchema) mapProjection
(String colName) protected RequestedColumn
int
size()
toString()
type()
Tuple projection type.
-
Field Details
-
projectionType
-
-
Constructor Details
-
RequestedTupleImpl
public RequestedTupleImpl() -
RequestedTupleImpl
-
RequestedTupleImpl
-
-
Method Details
-
size
public int size()- Specified by:
size
in interfaceRequestedTuple
-
get
- Specified by:
get
in interfaceRequestedTuple
-
get
- Specified by:
get
in interfaceRequestedTuple
-
getImpl
-
project
-
projections
- Specified by:
projections
in interfaceRequestedTuple
-
buildName
- Specified by:
buildName
in interfaceRequestedTuple
-
type
Tuple projection type. This is a rough approximation. A scan-level projection may include both a wildcard and implicit columns. This form is best used in testing where such ambiguities do not apply.- Specified by:
type
in interfaceRequestedTuple
-
isProjected
- Specified by:
isProjected
in interfaceRequestedTuple
-
isProjected
- Specified by:
isProjected
in interfaceRequestedTuple
-
enforceProjection
- Specified by:
enforceProjection
in interfaceRequestedTuple
-
mapProjection
- Specified by:
mapProjection
in interfaceRequestedTuple
-
toString
-
isEmpty
public boolean isEmpty()Description copied from interface:RequestedTuple
Report if the projection is empty as occurs inSELECT COUNT(*) FROM ...
. This is not the same as asking if this tuple is unprojected, as that concept does not apply to tuples, only to the column that contains the tuple.- Specified by:
isEmpty
in interfaceRequestedTuple
- Returns:
true
if the projection set is empty
-