Class ProjectionChecker

java.lang.Object
org.apache.drill.exec.physical.resultSet.project.ProjectionChecker

public class ProjectionChecker extends Object
Utility class 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.

  • Method Details

    • isConsistent

      public static boolean isConsistent(RequestedTuple tuple, ColumnMetadata readCol)
      Check if the given read column is consistent with the projection requested for a tuple. This form handles wildcard projection and unprojected columns; cases where there is no column-level projection information.
      Parameters:
      tuple - the tuple-level projection description
      readCol - 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 returns true if the column is not projected, as any type of column can be ignored
    • isConsistent

      public static boolean isConsistent(RequestedColumn colReq, ColumnMetadata readCol)
      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 description
      readCol - 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 returns true if the column is not projected, as any type of column can be ignored
    • validateProjection

      public static void validateProjection(RequestedColumn colReq, ColumnMetadata readCol)
    • validateProjection

      public static void validateProjection(RequestedColumn colReq, ColumnMetadata readCol, CustomErrorContext errorContext)
      Perform the column-level projection as described in isConsistent(RequestedColumn, ColumnMetadata), and raise a UserException if the column is not consistent with projection.
      Parameters:
      colReq - the column-level projection description
      readCol - metadata for the column which the reader has actually produced
      errorContext - 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