public class DruidQueryToSqlConverter extends Object
DruidQuery
into a sql query.Modifier and Type | Field and Description |
---|---|
static int |
NO_LIMIT |
static int |
NO_OFFSET |
Constructor and Description |
---|
DruidQueryToSqlConverter(CalciteHelper calciteHelper)
Constructs the default converter.
|
Modifier and Type | Method and Description |
---|---|
protected BiFunction<Aggregation,ApiToFieldMapper,Optional<SqlAggregation>> |
buildDruidSqlTypeConverter()
Builds a converter between druid and sql aggregations.
|
String |
buildSqlQuery(DruidAggregationQuery<?> druidQuery,
ApiToFieldMapper apiToFieldMapper)
Builds the druid query as sql and returns it as a string.
|
protected SqlTimeConverter |
buildSqlTimeConverter()
Builds a time converter to designating how to translate between druid and sql
time information.
|
protected List<org.apache.calcite.rex.RexNode> |
getAllGroupByColumns(org.apache.calcite.tools.RelBuilder builder,
DruidAggregationQuery<?> druidQuery,
ApiToFieldMapper apiToFieldMapper,
String timestampColumn)
Collects all the time columns and dimensions to be grouped on.
|
protected List<org.apache.calcite.tools.RelBuilder.AggCall> |
getAllQueryAggregations(org.apache.calcite.tools.RelBuilder builder,
DruidAggregationQuery<?> druidQuery,
ApiToFieldMapper apiToFieldMapper)
Find all druid aggregations and convert them to
RelBuilder.AggCall . |
protected org.apache.calcite.rex.RexNode |
getAllWhereFilters(org.apache.calcite.tools.RelBuilder builder,
DruidAggregationQuery<?> druidQuery,
ApiToFieldMapper apiToFieldMapper,
String timestampColumn)
Returns the RexNode used to filter the druidQuery.
|
protected Collection<org.apache.calcite.rex.RexNode> |
getHavingFilter(org.apache.calcite.tools.RelBuilder builder,
DruidAggregationQuery<?> druidQuery,
ApiToFieldMapper apiToFieldMapper)
Gets the collection of having filters to be applied from the druid query.
|
protected int |
getLimit(DruidAggregationQuery<?> druidQuery)
Gets the number of rows to limit results to for a Group by Query.
|
protected List<org.apache.calcite.rex.RexNode> |
getSort(org.apache.calcite.tools.RelBuilder builder,
DruidAggregationQuery<?> druidQuery,
ApiToFieldMapper apiToFieldMapper,
String timestampColumn)
Finds the sorting for a druid query.
|
SqlTimeConverter |
getTimeConverter() |
protected boolean |
isValidQuery(DruidQuery<?> druidQuery)
Determines whether or not a query is able to be processed using
the Sql backend.
|
protected String |
writeSql(org.apache.calcite.sql.pretty.SqlPrettyWriter sqlWriter,
org.apache.calcite.rel.rel2sql.RelToSqlConverter relToSql,
org.apache.calcite.rel.RelNode query)
Converts a RelBuilder into a sql string.
|
public static final int NO_OFFSET
public static final int NO_LIMIT
public DruidQueryToSqlConverter(CalciteHelper calciteHelper)
isValidQuery(DruidQuery)
and
buildSqlQuery(DruidAggregationQuery, ApiToFieldMapper)
. Maybe make it a generic
more generic like "DruidQueryConverter<T>
"calciteHelper
- The calcite helper for this database.protected SqlTimeConverter buildSqlTimeConverter()
protected BiFunction<Aggregation,ApiToFieldMapper,Optional<SqlAggregation>> buildDruidSqlTypeConverter()
protected boolean isValidQuery(DruidQuery<?> druidQuery)
druidQuery
- The query to check if is able to be processed.public String buildSqlQuery(DruidAggregationQuery<?> druidQuery, ApiToFieldMapper apiToFieldMapper)
druidQuery
- The query to convert to sql.apiToFieldMapper
- The mapping between api and physical names for the query.protected int getLimit(DruidAggregationQuery<?> druidQuery)
druidQuery
- The query to get the row limit from.protected List<org.apache.calcite.rex.RexNode> getSort(org.apache.calcite.tools.RelBuilder builder, DruidAggregationQuery<?> druidQuery, ApiToFieldMapper apiToFieldMapper, String timestampColumn)
builder
- The RelBuilder created with Calcite.druidQuery
- The query to find the sorting from.apiToFieldMapper
- The mapping from api to physical names.timestampColumn
- The name of the timestamp column in the database.protected org.apache.calcite.rex.RexNode getAllWhereFilters(org.apache.calcite.tools.RelBuilder builder, DruidAggregationQuery<?> druidQuery, ApiToFieldMapper apiToFieldMapper, String timestampColumn)
builder
- The RelBuilder created with Calcite.druidQuery
- The query from which to find filter all the filters for.apiToFieldMapper
- The mapping from api to physical names.timestampColumn
- The name of the timestamp column in the database.protected Collection<org.apache.calcite.rex.RexNode> getHavingFilter(org.apache.calcite.tools.RelBuilder builder, DruidAggregationQuery<?> druidQuery, ApiToFieldMapper apiToFieldMapper)
builder
- The RelBuilder created with Calcite.druidQuery
- The query to find the having filter from.apiToFieldMapper
- The mapping from api to physical name.protected List<org.apache.calcite.tools.RelBuilder.AggCall> getAllQueryAggregations(org.apache.calcite.tools.RelBuilder builder, DruidAggregationQuery<?> druidQuery, ApiToFieldMapper apiToFieldMapper)
RelBuilder.AggCall
.builder
- The RelBuilder created with Calcite.druidQuery
- The druid query to get the aggregations of.apiToFieldMapper
- The mapping from api to physical name.protected List<org.apache.calcite.rex.RexNode> getAllGroupByColumns(org.apache.calcite.tools.RelBuilder builder, DruidAggregationQuery<?> druidQuery, ApiToFieldMapper apiToFieldMapper, String timestampColumn)
builder
- The RelBuilder created with Calcite.druidQuery
- The query to find grouping columns from.apiToFieldMapper
- The mapping from api to physical name.timestampColumn
- The name of the timestamp column in the database.protected String writeSql(org.apache.calcite.sql.pretty.SqlPrettyWriter sqlWriter, org.apache.calcite.rel.rel2sql.RelToSqlConverter relToSql, org.apache.calcite.rel.RelNode query)
sqlWriter
- The writer to be used when translating the RelNode
to sql.relToSql
- The converter from RelNode
to
SqlNode
.query
- The RelNode representing the query.public SqlTimeConverter getTimeConverter()
Copyright © 2016–2018 Yahoo! Inc.. All rights reserved.