Package com.twilio.kudu.sql
Class CalciteKuduTable
- java.lang.Object
-
- org.apache.calcite.schema.impl.AbstractTable
-
- org.apache.calcite.adapter.java.AbstractQueryableTable
-
- com.twilio.kudu.sql.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
ACalciteKuduTable
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 aKuduTable
to be opened and ready to be used.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CalciteKuduTable.KuduQueryable<T>
Implementation ofQueryable
based on aCalciteKuduTable
.
-
Field Summary
Fields Modifier and Type Field Description protected org.apache.kudu.client.AsyncKuduClient
client
protected List<CalciteKuduTable>
cubeTables
protected List<Integer>
descendingOrderedColumnIndexes
static Instant
EPOCH_DAY_FOR_REVERSE_SORT
static Long
EPOCH_FOR_REVERSE_SORT_IN_MICROSECONDS
static Long
EPOCH_FOR_REVERSE_SORT_IN_MILLISECONDS
protected CubeTableInfo.EventTimeAggregationType
eventTimeAggregationType
protected org.apache.kudu.client.KuduTable
kuduTable
protected TableType
tableType
protected int
timestampColumnIndex
-
Constructor Summary
Constructors Constructor Description 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 theCalciteKuduTable
for a physical scan over the providedKuduTable
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> org.apache.calcite.linq4j.Queryable<T>
asQueryable(org.apache.calcite.linq4j.QueryProvider queryProvider, org.apache.calcite.schema.SchemaPlus schema, String tableName)
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 tablekuduTable
.org.apache.kudu.client.AsyncKuduClient
getClient()
List<CalciteKuduTable>
getCubeTables()
List<Integer>
getDescendingColumnsIndicesInProjection(org.apache.kudu.Schema projectedSchema)
Return the integer indices of the descending sorted columns in the row projection.List<Integer>
getDescendingOrderedColumnIndexes()
CubeTableInfo.EventTimeAggregationType
getEventTimeAggregationType()
org.apache.kudu.client.KuduTable
getKuduTable()
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.static List<Integer>
getPrimaryKeyColumnsInProjection(org.apache.kudu.Schema schema, org.apache.kudu.Schema projectedSchema)
org.apache.calcite.rel.type.RelDataType
getRowType(org.apache.calcite.rel.type.RelDataTypeFactory typeFactory)
Builds a mapping from Kudu Schema into relational schema namesorg.apache.calcite.schema.Statistic
getStatistic()
TableType
getTableType()
int
getTimestampColumnIndex()
boolean
isColumnOrderedDesc(int columnIndex)
boolean
isColumnOrderedDesc(String columnName)
org.apache.calcite.rel.RelNode
toRel(org.apache.calcite.plan.RelOptTable.ToRelContext context, org.apache.calcite.plan.RelOptTable relOptTable)
-
Methods inherited from class org.apache.calcite.adapter.java.AbstractQueryableTable
getElementType, getExpression
-
Methods inherited from class org.apache.calcite.schema.impl.AbstractTable
getJdbcTableType, isRolledUp, rolledUpColumnValidInsideAgg, unwrap
-
-
-
-
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
-
timestampColumnIndex
protected final int timestampColumnIndex
-
cubeTables
protected final List<CalciteKuduTable> cubeTables
-
tableType
protected final TableType tableType
-
eventTimeAggregationType
protected final CubeTableInfo.EventTimeAggregationType eventTimeAggregationType
-
-
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 theCalciteKuduTable
for a physical scan over the providedKuduTable
.KuduTable
must exist and be opened. UseCalciteKuduTableBuilder
to build a table instead of this constructor- Parameters:
kuduTable
- the opened kudu tableclient
- kudu client that is used to write mutationsdescendingOrderColumnIndexes
- indexes of columns that are stored in descending ordertimestampColumnIndex
- column index that represents the single timestampcubeTables
- the list of cube tables (if this is a fact table)tableType
- type of this tableeventTimeAggregationType
- How the table is aggregated across time ranges
-
-
Method Detail
-
getStatistic
public org.apache.calcite.schema.Statistic getStatistic()
- Specified by:
getStatistic
in interfaceorg.apache.calcite.schema.Table
- Overrides:
getStatistic
in classorg.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 interfaceorg.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 interfaceorg.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 tablekuduTable
.KuduPredicate
are the filters to apply to the query,columnIndices
are the columns to return in the response and finallylimit
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 Kudulimit
- process the results until limit is reached. If less then 0, no limitoffset
- skip offset number of rows before returning resultssorted
- whether to return rows in sorted ordergroupByLimited
- indicates if the groupBy method should be counting unique keysscanStats
- scan stats collectorcancelFlag
- flag to indicate the query has been canceledprojection
- function to map theRowResult
to calcite objectfilterFunction
- predicate to apply toRowResult
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 interfaceorg.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 twoCalciteRow
s 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)
-
getEventTimeAggregationType
public CubeTableInfo.EventTimeAggregationType getEventTimeAggregationType()
-
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
-
getCubeTables
public List<CalciteKuduTable> getCubeTables()
-
getTimestampColumnIndex
public int getTimestampColumnIndex()
-
getTableType
public TableType getTableType()
-
-