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
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcopyMapProperties(ProjectedColumn source, ColumnMetadata dest) static ColumnMetadatagetColumnMetadata(String name, org.apache.calcite.rel.type.RelDataType relDataType) Converts specifiedRelDataType relDataTypeintoColumnMetadata.static Stringstatic booleanisConsistent(ProjectedColumn colReq, ColumnMetadata readCol) Check if the given read column is consistent with the projection requested for that column.static booleanstatic booleanisImplicit(ColumnMetadata col) static booleanisProjectAll(TupleMetadata tuple) static booleanisProjectNone(TupleMetadata tuple) static booleanisStrict(TupleMetadata schema) static voidmarkAsPartition(ColumnMetadata col, int level) static voidstatic voidmarkImplicit(ColumnMetadata col, String value) static voidstatic voidmarkStrict(TupleMetadata schema) static voidmergeColProperties(ColumnMetadata existing, ColumnMetadata revised) static voidmergeProperties(Propertied existing, Propertied revised) static voidverifyCompatibility(ProjectedColumn colReq, ColumnMetadata actual, String source, CustomErrorContext errorContext) Perform the column-level projection as described inisConsistent(ProjectedColumn, ColumnMetadata), and raise aUserExceptionif the column is not consistent with projection.static voidverifyConsistency(ColumnMetadata existing, ColumnMetadata revised, String source, CustomErrorContext errorContext) static voidverifyProjection(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:
trueif the column is consistent with projection (or if the column is too complex to check),falseif the column is not consistent and represents an error case. Also returnstrueif 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 aUserExceptionif 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 relDataTypeintoColumnMetadata. For the case when specified relDataType is struct, map with recursively converted children will be created.- Parameters:
name- filed namerelDataType- filed type- Returns:
ColumnMetadatawhich corresponds to specifiedRelDataType relDataType
-