Class CalciteKuduTable

  • All Implemented Interfaces:
    org.apache.calcite.schema.QueryableTable, org.apache.calcite.schema.Table, org.apache.calcite.schema.TranslatableTable, org.apache.calcite.schema.Wrapper
    Direct Known Subclasses:
    CalciteModifiableKuduTable

    public class CalciteKuduTable
    extends org.apache.calcite.adapter.java.AbstractQueryableTable
    implements org.apache.calcite.schema.TranslatableTable
    A CalciteKuduTable is responsible for returning rows of Objects back. It is responsible for calling the RPC layer of Kudu reparsing them into expected types for the RelTable used in the request. It requires a KuduTable to be opened and ready to be used.
    • Field Detail

      • EPOCH_DAY_FOR_REVERSE_SORT

        public static final Instant EPOCH_DAY_FOR_REVERSE_SORT
      • EPOCH_FOR_REVERSE_SORT_IN_MILLISECONDS

        public static final Long EPOCH_FOR_REVERSE_SORT_IN_MILLISECONDS
      • EPOCH_FOR_REVERSE_SORT_IN_MICROSECONDS

        public static final Long EPOCH_FOR_REVERSE_SORT_IN_MICROSECONDS
      • kuduTable

        protected final org.apache.kudu.client.KuduTable kuduTable
      • client

        protected final org.apache.kudu.client.AsyncKuduClient client
      • descendingOrderedColumnIndexes

        protected final List<Integer> descendingOrderedColumnIndexes
      • timestampColumnIndex

        protected final int timestampColumnIndex
      • tableType

        protected final TableType tableType
    • Constructor Detail

      • CalciteKuduTable

        public CalciteKuduTable​(org.apache.kudu.client.KuduTable kuduTable,
                                org.apache.kudu.client.AsyncKuduClient client,
                                List<Integer> descendingOrderColumnIndexes,
                                int timestampColumnIndex,
                                List<CalciteKuduTable> cubeTables,
                                TableType tableType,
                                CubeTableInfo.EventTimeAggregationType eventTimeAggregationType)
        Create the CalciteKuduTable for a physical scan over the providedKuduTable. KuduTable must exist and be opened. Use CalciteKuduTableBuilder to build a table instead of this constructor
        Parameters:
        kuduTable - the opened kudu table
        client - kudu client that is used to write mutations
        descendingOrderColumnIndexes - indexes of columns that are stored in descending order
        timestampColumnIndex - column index that represents the single timestamp
        cubeTables - the list of cube tables (if this is a fact table)
        tableType - type of this table
        eventTimeAggregationType - How the table is aggregated across time ranges
    • Method Detail

      • getStatistic

        public org.apache.calcite.schema.Statistic getStatistic()
        Specified by:
        getStatistic in interface org.apache.calcite.schema.Table
        Overrides:
        getStatistic in class org.apache.calcite.schema.impl.AbstractTable
      • getRowType

        public org.apache.calcite.rel.type.RelDataType getRowType​(org.apache.calcite.rel.type.RelDataTypeFactory typeFactory)
        Builds a mapping from Kudu Schema into relational schema names
        Specified by:
        getRowType in interface org.apache.calcite.schema.Table
      • toRel

        public org.apache.calcite.rel.RelNode toRel​(org.apache.calcite.plan.RelOptTable.ToRelContext context,
                                                    org.apache.calcite.plan.RelOptTable relOptTable)
        Specified by:
        toRel in interface org.apache.calcite.schema.TranslatableTable
      • executeQuery

        public KuduEnumerable executeQuery​(List<List<CalciteKuduPredicate>> predicates,
                                           List<Integer> columnIndices,
                                           long limit,
                                           long offset,
                                           boolean sorted,
                                           boolean groupByLimited,
                                           KuduScanStats scanStats,
                                           AtomicBoolean cancelFlag,
                                           org.apache.calcite.linq4j.function.Function1<Object,​Object> projection,
                                           org.apache.calcite.linq4j.function.Predicate1<Object> filterFunction,
                                           boolean isSingleObject)
        Run the query against the kudu table kuduTable. KuduPredicate are the filters to apply to the query, columnIndices are the columns to return in the response and finally limit is used to limit the results that come back.
        Parameters:
        predicates - each member in the first list represents a single scan.
        columnIndices - the fields ordinals to select out of Kudu
        limit - process the results until limit is reached. If less then 0, no limit
        offset - skip offset number of rows before returning results
        sorted - whether to return rows in sorted order
        groupByLimited - indicates if the groupBy method should be counting unique keys
        scanStats - scan stats collector
        cancelFlag - flag to indicate the query has been canceled
        projection - function to map the RowResult to calcite object
        filterFunction - predicate to apply to RowResult
        isSingleObject - boolean indicating if the projection returns Object[] or Object
        Returns:
        Enumeration on the objects, Fields conform to getRowType(org.apache.calcite.rel.type.RelDataTypeFactory).
      • asQueryable

        public <T> org.apache.calcite.linq4j.Queryable<T> asQueryable​(org.apache.calcite.linq4j.QueryProvider queryProvider,
                                                                      org.apache.calcite.schema.SchemaPlus schema,
                                                                      String tableName)
        Specified by:
        asQueryable in interface org.apache.calcite.schema.QueryableTable
      • isColumnOrderedDesc

        public boolean isColumnOrderedDesc​(String columnName)
      • isColumnOrderedDesc

        public boolean isColumnOrderedDesc​(int columnIndex)
      • getKuduTable

        public org.apache.kudu.client.KuduTable getKuduTable()
      • getClient

        public org.apache.kudu.client.AsyncKuduClient getClient()
      • getPrimaryKeyColumnsInProjection

        public List<Integer> getPrimaryKeyColumnsInProjection​(org.apache.kudu.Schema projectedSchema)
        Return the Integer indices in the Row Projection that match the primary key columns and in the order they need to match. This lays out how to compare two CalciteRows and determine which one is smaller.

        As an example, imagine we have a table (A, B, C, D, E) with primary columns in order of (A, B) and we have a scanner SELECT D, C, E, B, A the projectedSchema will be D, C, E, B, A and the tableSchema will be A, B, C, D, E *this* function will return List(4, 3) -- the position's of A and B within the projection and in the order they need to be sorted by.

        The returned index list is used by the sorted KuduEnumerable to merge the results from multiple scanners.

        Parameters:
        projectedSchema - the Kudu Schema used in RPC requests
        Returns:
        List of column indexes that part of the primary key in the Kudu Sorted order
      • getPrimaryKeyColumnsInProjection

        public static List<Integer> getPrimaryKeyColumnsInProjection​(org.apache.kudu.Schema schema,
                                                                     org.apache.kudu.Schema projectedSchema)
      • getDescendingColumnsIndicesInProjection

        public List<Integer> getDescendingColumnsIndicesInProjection​(org.apache.kudu.Schema projectedSchema)
        Return the integer indices of the descending sorted columns in the row projection.
        Parameters:
        projectedSchema - the Kudu Schema used in RPC requests
        Returns:
        Column indexes in the RPC that are in descending order
      • getTimestampColumnIndex

        public int getTimestampColumnIndex()
      • getDescendingOrderedColumnIndexes

        public List<Integer> getDescendingOrderedColumnIndexes()
      • getTableType

        public TableType getTableType()