Package org.apache.calcite.adapter.druid
Class DruidTable
- java.lang.Object
-
- org.apache.calcite.schema.impl.AbstractTable
-
- org.apache.calcite.adapter.druid.DruidTable
-
- All Implemented Interfaces:
Table
,TranslatableTable
,Wrapper
public class DruidTable extends AbstractTable implements TranslatableTable
Table mapped onto a Druid table.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
DruidTable.MapRelProtoDataType
Creates aRelDataType
from a map of field names and types.
-
Field Summary
Fields Modifier and Type Field Description (package private) com.google.common.collect.ImmutableMap<java.lang.String,SqlTypeName>
allFields
(package private) com.google.common.collect.ImmutableMap<java.lang.String,java.util.List<ComplexMetric>>
complexMetrics
(package private) java.lang.String
dataSource
static org.joda.time.Interval
DEFAULT_INTERVAL
static java.lang.String
DEFAULT_TIMESTAMP_COLUMN
(package private) com.google.common.collect.ImmutableList<org.joda.time.Interval>
intervals
(package private) com.google.common.collect.ImmutableSet<java.lang.String>
metricFieldNames
(package private) RelProtoDataType
protoRowType
(package private) DruidSchema
schema
(package private) java.lang.String
timestampFieldName
-
Constructor Summary
Constructors Constructor Description DruidTable(DruidSchema schema, java.lang.String dataSource, RelProtoDataType protoRowType, java.util.Set<java.lang.String> metricFieldNames, java.lang.String timestampFieldName, java.util.List<org.joda.time.Interval> intervals, java.util.Map<java.lang.String,java.util.List<ComplexMetric>> complexMetrics, java.util.Map<java.lang.String,SqlTypeName> allFields)
Creates a Druid table.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) static Table
create(DruidSchema druidSchema, java.lang.String dataSourceName, java.util.List<org.joda.time.Interval> intervals, java.util.Map<java.lang.String,SqlTypeName> fieldMap, java.util.Set<java.lang.String> metricNameSet, java.lang.String timestampColumnName, java.util.Map<java.lang.String,java.util.List<ComplexMetric>> complexMetrics)
Creates aDruidTable
by copying the given parameters.(package private) static Table
create(DruidSchema druidSchema, java.lang.String dataSourceName, java.util.List<org.joda.time.Interval> intervals, java.util.Map<java.lang.String,SqlTypeName> fieldMap, java.util.Set<java.lang.String> metricNameSet, java.lang.String timestampColumnName, DruidConnectionImpl connection, java.util.Map<java.lang.String,java.util.List<ComplexMetric>> complexMetrics)
Creates aDruidTable
by using the givenDruidConnectionImpl
to populate the other parameters.java.util.List<ComplexMetric>
getComplexMetricsFrom(java.lang.String alias)
Returns the list ofComplexMetric
that match the givenalias
if it exists, otherwise returns an empty list, nevernull
RelDataType
getRowType(RelDataTypeFactory typeFactory)
Returns this table's row type.boolean
isComplexMetric(java.lang.String alias)
Returns true if and only if the givenalias
is a reference to a registeredComplexMetric
private boolean
isCountDistinct(SqlCall call)
boolean
isMetric(java.lang.String name)
boolean
isRolledUp(java.lang.String column)
Determines whether the givencolumn
has been rolled up.private boolean
isSupportedPostAggOperation(SqlKind kind)
private boolean
isValidParentKind(SqlNode node)
ComplexMetric
resolveComplexMetric(java.lang.String alias, AggregateCall call)
Returns the appropriateComplexMetric
that is mapped from the givenalias
if it exists, and is used in the expected context with the givenAggregateCall
.boolean
rolledUpColumnValidInsideAgg(java.lang.String column, SqlCall call, SqlNode parent, CalciteConnectionConfig config)
Determines whether the given rolled up column can be used inside the given aggregate function.RelNode
toRel(RelOptTable.ToRelContext context, RelOptTable relOptTable)
Converts this table into arelational expression
.-
Methods inherited from class org.apache.calcite.schema.impl.AbstractTable
getJdbcTableType, getStatistic, unwrap
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.calcite.schema.Table
getJdbcTableType, getStatistic
-
-
-
-
Field Detail
-
DEFAULT_TIMESTAMP_COLUMN
public static final java.lang.String DEFAULT_TIMESTAMP_COLUMN
- See Also:
- Constant Field Values
-
DEFAULT_INTERVAL
public static final org.joda.time.Interval DEFAULT_INTERVAL
-
schema
final DruidSchema schema
-
dataSource
final java.lang.String dataSource
-
protoRowType
final RelProtoDataType protoRowType
-
metricFieldNames
final com.google.common.collect.ImmutableSet<java.lang.String> metricFieldNames
-
intervals
final com.google.common.collect.ImmutableList<org.joda.time.Interval> intervals
-
timestampFieldName
final java.lang.String timestampFieldName
-
complexMetrics
final com.google.common.collect.ImmutableMap<java.lang.String,java.util.List<ComplexMetric>> complexMetrics
-
allFields
final com.google.common.collect.ImmutableMap<java.lang.String,SqlTypeName> allFields
-
-
Constructor Detail
-
DruidTable
public DruidTable(DruidSchema schema, java.lang.String dataSource, RelProtoDataType protoRowType, java.util.Set<java.lang.String> metricFieldNames, java.lang.String timestampFieldName, java.util.List<org.joda.time.Interval> intervals, java.util.Map<java.lang.String,java.util.List<ComplexMetric>> complexMetrics, java.util.Map<java.lang.String,SqlTypeName> allFields)
Creates a Druid table.- Parameters:
schema
- Druid schema that contains this tabledataSource
- Druid data source nameprotoRowType
- Field names and typesmetricFieldNames
- Names of fields that are metricsintervals
- Default interval if query does not constrain the time, or nulltimestampFieldName
- Name of the column that contains the time
-
-
Method Detail
-
create
static Table create(DruidSchema druidSchema, java.lang.String dataSourceName, java.util.List<org.joda.time.Interval> intervals, java.util.Map<java.lang.String,SqlTypeName> fieldMap, java.util.Set<java.lang.String> metricNameSet, java.lang.String timestampColumnName, DruidConnectionImpl connection, java.util.Map<java.lang.String,java.util.List<ComplexMetric>> complexMetrics)
Creates aDruidTable
by using the givenDruidConnectionImpl
to populate the other parameters. The parameters may be partially populated.- Parameters:
druidSchema
- Druid schemadataSourceName
- Data source name in Druid, also table nameintervals
- Intervals, or null to use defaultfieldMap
- Partially populated map of fields (dimensions plus metrics)metricNameSet
- Partially populated set of metric namestimestampColumnName
- Name of timestamp column, or nullconnection
- Connection used to find column definitions; Must be non-nullcomplexMetrics
- List of complex metrics in Druid (thetaSketch, hyperUnique)- Returns:
- A table
-
create
static Table create(DruidSchema druidSchema, java.lang.String dataSourceName, java.util.List<org.joda.time.Interval> intervals, java.util.Map<java.lang.String,SqlTypeName> fieldMap, java.util.Set<java.lang.String> metricNameSet, java.lang.String timestampColumnName, java.util.Map<java.lang.String,java.util.List<ComplexMetric>> complexMetrics)
Creates aDruidTable
by copying the given parameters.- Parameters:
druidSchema
- Druid schemadataSourceName
- Data source name in Druid, also table nameintervals
- Intervals, or null to use defaultfieldMap
- Fully populated map of fields (dimensions plus metrics)metricNameSet
- Fully populated set of metric namestimestampColumnName
- Name of timestamp column, or nullcomplexMetrics
- List of complex metrics in Druid (thetaSketch, hyperUnique)- Returns:
- A table
-
resolveComplexMetric
public ComplexMetric resolveComplexMetric(java.lang.String alias, AggregateCall call)
Returns the appropriateComplexMetric
that is mapped from the givenalias
if it exists, and is used in the expected context with the givenAggregateCall
. Otherwise returnsnull
.
-
isRolledUp
public boolean isRolledUp(java.lang.String column)
Description copied from interface:Table
Determines whether the givencolumn
has been rolled up.- Specified by:
isRolledUp
in interfaceTable
- Overrides:
isRolledUp
in classAbstractTable
-
rolledUpColumnValidInsideAgg
public boolean rolledUpColumnValidInsideAgg(java.lang.String column, SqlCall call, SqlNode parent, CalciteConnectionConfig config)
Description copied from interface:Table
Determines whether the given rolled up column can be used inside the given aggregate function. You can assume thatisRolledUp(column)
istrue
.- Specified by:
rolledUpColumnValidInsideAgg
in interfaceTable
- Overrides:
rolledUpColumnValidInsideAgg
in classAbstractTable
- Parameters:
column
- The column name for whichisRolledUp
is truecall
- The aggregate callparent
- Parent node ofcall
in theSqlNode
treeconfig
- Config settings. May be null- Returns:
- true iff the given aggregate call is valid
-
isValidParentKind
private boolean isValidParentKind(SqlNode node)
-
isCountDistinct
private boolean isCountDistinct(SqlCall call)
-
isSupportedPostAggOperation
private boolean isSupportedPostAggOperation(SqlKind kind)
-
getComplexMetricsFrom
public java.util.List<ComplexMetric> getComplexMetricsFrom(java.lang.String alias)
Returns the list ofComplexMetric
that match the givenalias
if it exists, otherwise returns an empty list, nevernull
-
isComplexMetric
public boolean isComplexMetric(java.lang.String alias)
Returns true if and only if the givenalias
is a reference to a registeredComplexMetric
-
getRowType
public RelDataType getRowType(RelDataTypeFactory typeFactory)
Description copied from interface:Table
Returns this table's row type.This is a struct type whose fields describe the names and types of the columns in this table.
The implementer must use the type factory provided. This ensures that the type is converted into a canonical form; other equal types in the same query will use the same object.
- Specified by:
getRowType
in interfaceTable
- Parameters:
typeFactory
- Type factory with which to create the type- Returns:
- Row type
-
toRel
public RelNode toRel(RelOptTable.ToRelContext context, RelOptTable relOptTable)
Description copied from interface:TranslatableTable
Converts this table into arelational expression
.- Specified by:
toRel
in interfaceTranslatableTable
-
isMetric
public boolean isMetric(java.lang.String name)
-
-