public class DruidSqlParserUtils extends Object
| Constructor and Description |
|---|
DruidSqlParserUtils() |
| Modifier and Type | Method and Description |
|---|---|
static org.apache.calcite.sql.SqlOrderBy |
convertClusterByToOrderBy(org.apache.calcite.sql.SqlNode query,
org.apache.calcite.sql.SqlNodeList clusteredByList)
Extracts and converts the information in the CLUSTERED BY clause to a new SqlOrderBy node.
|
static DimFilter |
convertQueryToDimFilter(org.apache.calcite.sql.SqlNode replaceTimeQuery,
org.joda.time.DateTimeZone dateTimeZone)
This method is used to convert an
SqlNode representing a query into a DimFilter for the same query. |
static Granularity |
convertSqlNodeToGranularity(org.apache.calcite.sql.SqlNode sqlNode)
This method is used to extract the granularity from a SqlNode representing following function calls:
1.
|
static Granularity |
convertSqlNodeToGranularityThrowingParseExceptions(org.apache.calcite.sql.SqlNode sqlNode)
Delegates to
convertSqlNodeToGranularity and converts the exceptions to ParseException
with the underlying message |
static String |
parseColumnName(org.apache.calcite.sql.SqlNode sqlNode)
Converts a
SqlNode identifier into a string representation |
static String |
parseTimeStampWithTimeZone(org.apache.calcite.sql.SqlNode sqlNode,
org.joda.time.DateTimeZone timeZone)
Converts a
SqlNode into a timestamp, taking into account the timezone |
static void |
throwIfUnsupportedGranularityInPartitionedBy(Granularity granularity)
Throws an IAE with appropriate message if the granularity supplied is not present in
Granularities. |
static List<String> |
validateQueryAndConvertToIntervals(org.apache.calcite.sql.SqlNode replaceTimeQuery,
Granularity granularity,
org.joda.time.DateTimeZone dateTimeZone)
This method validates and converts a
SqlNode representing a query into an optmizied list of intervals to
be used in creating an ingestion spec. |
public static final String ALL
public static Granularity convertSqlNodeToGranularityThrowingParseExceptions(org.apache.calcite.sql.SqlNode sqlNode) throws ParseException
convertSqlNodeToGranularity and converts the exceptions to ParseException
with the underlying messageParseExceptionpublic static Granularity convertSqlNodeToGranularity(org.apache.calcite.sql.SqlNode sqlNode) throws ParseException
TimeUnits
Since it is to be used primarily while parsing the SqlNode, it is wrapped in convertSqlNodeToGranularityThrowingParseExceptionssqlNode - SqlNode representing a call to a functionParseException - SqlNode cannot be converted a granularitypublic static List<String> validateQueryAndConvertToIntervals(org.apache.calcite.sql.SqlNode replaceTimeQuery, Granularity granularity, org.joda.time.DateTimeZone dateTimeZone) throws org.apache.calcite.tools.ValidationException
SqlNode representing a query into an optmizied list of intervals to
be used in creating an ingestion spec. If the sqlNode is an SqlLiteral of ALL, returns a singleton list of
"ALL". Otherwise, it converts and optimizes the query using MoveTimeFiltersToIntervals into a list of
intervals which contain all valid values of time as per the query.
The following validations are performed
1. Only __time column and timestamp literals are present in the query
2. The interval after optimization is not empty
3. The operands in the expression are supported
4. The intervals after adjusting for timezone are aligned with the granularity parameterreplaceTimeQuery - Sql node representing the querygranularity - granularity of the query for validationdateTimeZone - timezoneorg.apache.calcite.tools.ValidationException - if the SqlNode cannot be converted to a list of intervalspublic static org.apache.calcite.sql.SqlOrderBy convertClusterByToOrderBy(org.apache.calcite.sql.SqlNode query,
org.apache.calcite.sql.SqlNodeList clusteredByList)
query - sql queryclusteredByList - List of clustered by columnspublic static DimFilter convertQueryToDimFilter(org.apache.calcite.sql.SqlNode replaceTimeQuery, org.joda.time.DateTimeZone dateTimeZone) throws org.apache.calcite.tools.ValidationException
SqlNode representing a query into a DimFilter for the same query.
It takes the timezone as a separate parameter, as Sql timestamps don't contain that information. Supported functions
are AND, OR, NOT, >, <, >=, <= and BETWEEN operators in the sql query.replaceTimeQuery - Sql node representing the querydateTimeZone - timezoneorg.apache.calcite.tools.ValidationException - if the SqlNode cannot be converted a Dimfilterpublic static String parseColumnName(org.apache.calcite.sql.SqlNode sqlNode) throws org.apache.calcite.tools.ValidationException
SqlNode identifier into a string representationsqlNode - the sql nodeorg.apache.calcite.tools.ValidationException - if the sql node is not an SqlIdentifierpublic static String parseTimeStampWithTimeZone(org.apache.calcite.sql.SqlNode sqlNode, org.joda.time.DateTimeZone timeZone) throws org.apache.calcite.tools.ValidationException
SqlNode into a timestamp, taking into account the timezonesqlNode - the sql nodetimeZone - timezoneorg.apache.calcite.tools.ValidationException - if the sql node is not a SqlTimestampLiteralpublic static void throwIfUnsupportedGranularityInPartitionedBy(Granularity granularity)
Granularities. It also filters out NONE as it is not a valid
granularity that can be supplied in PARTITIONED BYCopyright © 2011–2022 The Apache Software Foundation. All rights reserved.