Class Calcites
java.lang.Object
org.apache.druid.sql.calcite.planner.Calcites
Utility functions for Calcite.
See also the file saffron.properties which holds the
character set system properties formerly set in this file.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic class -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final org.apache.calcite.sql.type.SqlReturnTypeInferencestatic final org.apache.calcite.sql.type.SqlReturnTypeInferencestatic final DateTimes.UtcFormatterstatic final DateTimes.UtcFormatter -
Method Summary
Modifier and TypeMethodDescriptionstatic org.joda.time.DateTimecalciteDateTimeLiteralToJoda(org.apache.calcite.rex.RexNode literal, org.joda.time.DateTimeZone timeZone) Translates "literal" (a TIMESTAMP or DATE literal) to milliseconds since the epoch using the provided session time zone.static org.joda.time.DateTimecalciteDateToJoda(int date, org.joda.time.DateTimeZone timeZone) The inverse ofjodaToCalciteDate(DateTime, DateTimeZone).static org.joda.time.DateTimecalciteTimestampToJoda(long timestamp, org.joda.time.DateTimeZone timeZone) The inverse ofjodaToCalciteTimestamp(DateTime, DateTimeZone).static org.apache.calcite.sql.type.SqlReturnTypeInferencecomplexReturnTypeWithNullability(ColumnType columnType, boolean nullable) static org.apache.calcite.rel.type.RelDataTypecreateSqlArrayTypeWithNullability(org.apache.calcite.rel.type.RelDataTypeFactory typeFactory, org.apache.calcite.sql.type.SqlTypeName elementTypeName, boolean nullable) Like RelDataTypeFactory.createSqlTypeWithNullability, but creates types that align best with how Druid represents them.static org.apache.calcite.rel.type.RelDataTypecreateSqlType(org.apache.calcite.rel.type.RelDataTypeFactory typeFactory, org.apache.calcite.sql.type.SqlTypeName typeName) Like RelDataTypeFactory.createSqlType, but creates types that align best with how Druid represents them.static org.apache.calcite.rel.type.RelDataTypecreateSqlTypeWithNullability(org.apache.calcite.rel.type.RelDataTypeFactory typeFactory, org.apache.calcite.sql.type.SqlTypeName typeName, boolean nullable) Like RelDataTypeFactory.createSqlTypeWithNullability, but creates types that align best with how Druid represents them.static Charsetstatic Stringstatic StringfindUnusedPrefixForDigits(String basePrefix, Iterable<String> strings) Find a string that is either equal to "basePrefix", or basePrefix prepended by underscores, and where nothing in "strings" starts with prefix plus a digit.static ColumnTypegetColumnTypeForRelDataType(org.apache.calcite.rel.type.RelDataType type) ConvertRelDataTypeto the most appropriateColumnType, or null if there is noColumnTypethat is appropriate for thisRelDataType.static StringComparatorgetStringComparatorForRelDataType(org.apache.calcite.rel.type.RelDataType dataType) Returns the natural StringComparator associated with the RelDataType, or null if the type is not convertible toColumnTypebygetColumnTypeForRelDataType(RelDataType).static StringComparatorgetStringComparatorForValueType(ColumnType valueType) Returns the natural StringComparator associated with the given ColumnTypestatic ColumnTypegetValueTypeForRelDataTypeFull(org.apache.calcite.rel.type.RelDataType type) ConvertRelDataTypeto the most appropriateColumnType, or null if there is noColumnTypethat is appropriate for thisRelDataType.static booleanisDoubleType(org.apache.calcite.sql.type.SqlTypeName sqlTypeName) static booleanisLiteral(org.apache.calcite.rex.RexNode rexNode, boolean allowCast, boolean allowArray) Returns whether an expression is a literal.static booleanisLongType(org.apache.calcite.sql.type.SqlTypeName sqlTypeName) static booleanisStringType(org.apache.calcite.sql.type.SqlTypeName sqlTypeName) static intjodaToCalciteDate(org.joda.time.DateTime dateTime, org.joda.time.DateTimeZone timeZone) Calcite expects "DATE" types to be number of days from the epoch to the UTC date matching the local time fields.static org.apache.calcite.util.DateStringjodaToCalciteDateString(org.joda.time.DateTime dateTime, org.joda.time.DateTimeZone timeZone) Calcite expects DATE literals to be represented by DateStrings in the local time zone.static longjodaToCalciteTimestamp(org.joda.time.DateTime dateTime, org.joda.time.DateTimeZone timeZone) Calcite expects "TIMESTAMP" types to be an instant that has the expected local time fields if printed as UTC.static org.apache.calcite.rex.RexLiteraljodaToCalciteTimestampLiteral(org.apache.calcite.rex.RexBuilder rexBuilder, org.joda.time.DateTime dateTime, org.joda.time.DateTimeZone sessionTimeZone, int precision) Creates a Calcite TIMESTAMP literal from a Joda DateTime.static org.apache.calcite.util.TimestampStringjodaToCalciteTimestampString(org.joda.time.DateTime dateTime, org.joda.time.DateTimeZone sessionTimeZone) Calcite expects TIMESTAMP literals to be represented by TimestampStrings in the local time zone.static org.apache.calcite.util.TimeStringjodaToCalciteTimeString(org.joda.time.DateTime dateTime, org.joda.time.DateTimeZone timeZone) Calcite expects TIME literals to be represented by TimeStrings in the local time zone.static StringmakePrefixedName(String prefix, String suffix) static Class<?>sqlTypeNameJdbcToJavaClass(org.apache.calcite.sql.type.SqlTypeName typeName)
-
Field Details
-
CALCITE_DATE_PARSER
-
CALCITE_TIMESTAMP_PARSER
-
ARG0_NULLABLE_ARRAY_RETURN_TYPE_INFERENCE
public static final org.apache.calcite.sql.type.SqlReturnTypeInference ARG0_NULLABLE_ARRAY_RETURN_TYPE_INFERENCE -
ARG1_NULLABLE_ARRAY_RETURN_TYPE_INFERENCE
public static final org.apache.calcite.sql.type.SqlReturnTypeInference ARG1_NULLABLE_ARRAY_RETURN_TYPE_INFERENCE
-
-
Method Details
-
complexReturnTypeWithNullability
public static org.apache.calcite.sql.type.SqlReturnTypeInference complexReturnTypeWithNullability(ColumnType columnType, boolean nullable) -
defaultCharset
-
escapeStringLiteral
-
isLiteral
public static boolean isLiteral(org.apache.calcite.rex.RexNode rexNode, boolean allowCast, boolean allowArray) Returns whether an expression is a literal. LikeRexUtil.isLiteral(RexNode, boolean)but can accept arrays too.- Parameters:
rexNode- expressionallowCast- allow calls to CAST if its argument is literalallowArray- allow calls to ARRAY if its arguments are literal
-
getColumnTypeForRelDataType
@Nullable public static ColumnType getColumnTypeForRelDataType(org.apache.calcite.rel.type.RelDataType type) ConvertRelDataTypeto the most appropriateColumnType, or null if there is noColumnTypethat is appropriate for thisRelDataType. Equivalent togetValueTypeForRelDataTypeFull(RelDataType), except this method returnsColumnType.STRINGwhenTypeSignature.isArray()ifExpressionProcessingConfig.processArraysAsMultiValueStrings()is set via the server propertydruid.expressions.allowArrayToStringCast.- Returns:
- type, or null if there is no matching type
-
getValueTypeForRelDataTypeFull
@Nullable public static ColumnType getValueTypeForRelDataTypeFull(org.apache.calcite.rel.type.RelDataType type) ConvertRelDataTypeto the most appropriateColumnType, or null if there is noColumnTypethat is appropriate for thisRelDataType. Equivalent togetColumnTypeForRelDataType(RelDataType), but ignoresExpressionProcessingConfig.processArraysAsMultiValueStrings()(and acts as if it is false).- Returns:
- type, or null if there is no matching type
-
isStringType
public static boolean isStringType(org.apache.calcite.sql.type.SqlTypeName sqlTypeName) -
isDoubleType
public static boolean isDoubleType(org.apache.calcite.sql.type.SqlTypeName sqlTypeName) -
isLongType
public static boolean isLongType(org.apache.calcite.sql.type.SqlTypeName sqlTypeName) -
getStringComparatorForRelDataType
@Nullable public static StringComparator getStringComparatorForRelDataType(org.apache.calcite.rel.type.RelDataType dataType) Returns the natural StringComparator associated with the RelDataType, or null if the type is not convertible toColumnTypebygetColumnTypeForRelDataType(RelDataType). -
getStringComparatorForValueType
Returns the natural StringComparator associated with the given ColumnType -
createSqlType
public static org.apache.calcite.rel.type.RelDataType createSqlType(org.apache.calcite.rel.type.RelDataTypeFactory typeFactory, org.apache.calcite.sql.type.SqlTypeName typeName) Like RelDataTypeFactory.createSqlType, but creates types that align best with how Druid represents them. -
createSqlTypeWithNullability
public static org.apache.calcite.rel.type.RelDataType createSqlTypeWithNullability(org.apache.calcite.rel.type.RelDataTypeFactory typeFactory, org.apache.calcite.sql.type.SqlTypeName typeName, boolean nullable) Like RelDataTypeFactory.createSqlTypeWithNullability, but creates types that align best with how Druid represents them. -
createSqlArrayTypeWithNullability
public static org.apache.calcite.rel.type.RelDataType createSqlArrayTypeWithNullability(org.apache.calcite.rel.type.RelDataTypeFactory typeFactory, org.apache.calcite.sql.type.SqlTypeName elementTypeName, boolean nullable) Like RelDataTypeFactory.createSqlTypeWithNullability, but creates types that align best with how Druid represents them. -
jodaToCalciteTimestamp
public static long jodaToCalciteTimestamp(org.joda.time.DateTime dateTime, org.joda.time.DateTimeZone timeZone) Calcite expects "TIMESTAMP" types to be an instant that has the expected local time fields if printed as UTC.- Parameters:
dateTime- joda timestamptimeZone- session time zone- Returns:
- Calcite style millis
-
jodaToCalciteDate
public static int jodaToCalciteDate(org.joda.time.DateTime dateTime, org.joda.time.DateTimeZone timeZone) Calcite expects "DATE" types to be number of days from the epoch to the UTC date matching the local time fields.- Parameters:
dateTime- joda timestamptimeZone- session time zone- Returns:
- Calcite style date
-
jodaToCalciteTimestampLiteral
public static org.apache.calcite.rex.RexLiteral jodaToCalciteTimestampLiteral(org.apache.calcite.rex.RexBuilder rexBuilder, org.joda.time.DateTime dateTime, org.joda.time.DateTimeZone sessionTimeZone, int precision) Creates a Calcite TIMESTAMP literal from a Joda DateTime.- Parameters:
dateTime- joda timestampsessionTimeZone- session time zone- Returns:
- Calcite style Calendar, appropriate for literals
-
jodaToCalciteTimestampString
public static org.apache.calcite.util.TimestampString jodaToCalciteTimestampString(org.joda.time.DateTime dateTime, org.joda.time.DateTimeZone sessionTimeZone) Calcite expects TIMESTAMP literals to be represented by TimestampStrings in the local time zone.- Parameters:
dateTime- joda timestampsessionTimeZone- session time zone- Returns:
- Calcite style Calendar, appropriate for literals
-
jodaToCalciteTimeString
public static org.apache.calcite.util.TimeString jodaToCalciteTimeString(org.joda.time.DateTime dateTime, org.joda.time.DateTimeZone timeZone) Calcite expects TIME literals to be represented by TimeStrings in the local time zone.- Parameters:
dateTime- joda timestamptimeZone- session time zone- Returns:
- Calcite style Calendar, appropriate for literals
-
jodaToCalciteDateString
public static org.apache.calcite.util.DateString jodaToCalciteDateString(org.joda.time.DateTime dateTime, org.joda.time.DateTimeZone timeZone) Calcite expects DATE literals to be represented by DateStrings in the local time zone.- Parameters:
dateTime- joda timestamptimeZone- session time zone- Returns:
- Calcite style Calendar, appropriate for literals
-
calciteDateTimeLiteralToJoda
public static org.joda.time.DateTime calciteDateTimeLiteralToJoda(org.apache.calcite.rex.RexNode literal, org.joda.time.DateTimeZone timeZone) Translates "literal" (a TIMESTAMP or DATE literal) to milliseconds since the epoch using the provided session time zone.- Parameters:
literal- TIMESTAMP or DATE literaltimeZone- session time zone- Returns:
- milliseconds time
-
calciteTimestampToJoda
public static org.joda.time.DateTime calciteTimestampToJoda(long timestamp, org.joda.time.DateTimeZone timeZone) The inverse ofjodaToCalciteTimestamp(DateTime, DateTimeZone).- Parameters:
timestamp- Calcite style timestamptimeZone- session time zone- Returns:
- joda timestamp, with time zone set to the session time zone
-
calciteDateToJoda
public static org.joda.time.DateTime calciteDateToJoda(int date, org.joda.time.DateTimeZone timeZone) The inverse ofjodaToCalciteDate(DateTime, DateTimeZone).- Parameters:
date- Calcite style datetimeZone- session time zone- Returns:
- joda timestamp, with time zone set to the session time zone
-
findUnusedPrefixForDigits
Find a string that is either equal to "basePrefix", or basePrefix prepended by underscores, and where nothing in "strings" starts with prefix plus a digit. -
makePrefixedName
-
sqlTypeNameJdbcToJavaClass
-