Class SchemaUtils
Provides methods to check if a column is consistent with the projection
requested for a query. Used for scans: the reader offers certain columns
and the scan operator must decide whether to accept them, and if so,
if the column that has actually appeared is consistent with the projection
schema path provided by the planner. An obvious example is if projection
asks for a[0]
(and array), but the reader offer up a
as a non-array column.
Checks are reasonable, but not complete. Particularly in the DICT
case, projection depends on multiple factors, such as the type of the
key and values. This class does not (yet) handle that complexity.
Instead, the goal is no false negatives for the complex cases, while
catching the simple cases.
The Project operator or other consuming operator is the final arbitrator of whether a particular column satisfies a particular projection. This class tries to catch those errors early to provide better error messages.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
copyMapProperties
(ProjectedColumn source, ColumnMetadata dest) static ColumnMetadata
getColumnMetadata
(String name, org.apache.calcite.rel.type.RelDataType relDataType) Converts specifiedRelDataType relDataType
intoColumnMetadata
.static String
static boolean
isConsistent
(ProjectedColumn colReq, ColumnMetadata readCol) Check if the given read column is consistent with the projection requested for that column.static boolean
static boolean
isImplicit
(ColumnMetadata col) static boolean
isProjectAll
(TupleMetadata tuple) static boolean
isProjectNone
(TupleMetadata tuple) static boolean
isStrict
(TupleMetadata schema) static void
markAsPartition
(ColumnMetadata col, int level) static void
static void
markImplicit
(ColumnMetadata col, String value) static void
static void
markStrict
(TupleMetadata schema) static void
mergeColProperties
(ColumnMetadata existing, ColumnMetadata revised) static void
mergeProperties
(Propertied existing, Propertied revised) static void
verifyCompatibility
(ProjectedColumn colReq, ColumnMetadata actual, String source, CustomErrorContext errorContext) Perform the column-level projection as described inisConsistent(ProjectedColumn, ColumnMetadata)
, and raise aUserException
if the column is not consistent with projection.static void
verifyConsistency
(ColumnMetadata existing, ColumnMetadata revised, String source, CustomErrorContext errorContext) static void
verifyProjection
(ColumnMetadata existing, ColumnMetadata revised, String source, CustomErrorContext errorContext)
-
Field Details
-
logger
protected static final org.slf4j.Logger logger
-
-
Constructor Details
-
SchemaUtils
public SchemaUtils()
-
-
Method Details
-
isConsistent
Check if the given read column is consistent with the projection requested for that column. Does not handle subtleties such as DICT key types, actual types in a UNION, etc.- Parameters:
colReq
- the column-level projection descriptionreadCol
- metadata for the column which the reader has actually produced- Returns:
true
if the column is consistent with projection (or if the column is too complex to check),false
if the column is not consistent and represents an error case. Also returnstrue
if the column is not projected, as any type of column can be ignored
-
verifyCompatibility
public static void verifyCompatibility(ProjectedColumn colReq, ColumnMetadata actual, String source, CustomErrorContext errorContext) Perform the column-level projection as described inisConsistent(ProjectedColumn, ColumnMetadata)
, and raise aUserException
if the column is not consistent with projection.- Parameters:
colReq
- the column-level projection descriptionactual
- metadata for the column which the reader has actually producederrorContext
- additional error context to pass along in the exception- Throws:
UserException
- if the read column is not consistent with the projection description for the column
-
verifyConsistency
public static void verifyConsistency(ColumnMetadata existing, ColumnMetadata revised, String source, CustomErrorContext errorContext) -
verifyProjection
public static void verifyProjection(ColumnMetadata existing, ColumnMetadata revised, String source, CustomErrorContext errorContext) -
mergeColProperties
-
mergeProperties
-
isStrict
-
markStrict
-
implicitColType
-
isImplicit
-
markImplicit
-
markAsPartition
-
markExcludeFromWildcard
-
isExcludedFromWildcard
-
projectAll
-
markProjectAll
-
projectNone
-
isProjectAll
-
isProjectNone
-
copyMapProperties
-
getColumnMetadata
public static ColumnMetadata getColumnMetadata(String name, org.apache.calcite.rel.type.RelDataType relDataType) Converts specifiedRelDataType relDataType
intoColumnMetadata
. For the case when specified relDataType is struct, map with recursively converted children will be created.- Parameters:
name
- filed namerelDataType
- filed type- Returns:
ColumnMetadata
which corresponds to specifiedRelDataType relDataType
-