Class Calcites

java.lang.Object
org.apache.druid.sql.calcite.planner.Calcites

public class Calcites extends Object
Utility functions for Calcite.

See also the file saffron.properties which holds the character set system properties formerly set in this file.

  • Field Details

    • CALCITE_DATE_PARSER

      public static final DateTimes.UtcFormatter CALCITE_DATE_PARSER
    • CALCITE_TIMESTAMP_PARSER

      public static final DateTimes.UtcFormatter 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

      public static Charset defaultCharset()
    • escapeStringLiteral

      public static String escapeStringLiteral(String s)
    • isLiteral

      public static boolean isLiteral(org.apache.calcite.rex.RexNode rexNode, boolean allowCast, boolean allowArray)
      Returns whether an expression is a literal. Like RexUtil.isLiteral(RexNode, boolean) but can accept arrays too.
      Parameters:
      rexNode - expression
      allowCast - allow calls to CAST if its argument is literal
      allowArray - allow calls to ARRAY if its arguments are literal
    • getColumnTypeForRelDataType

      @Nullable public static ColumnType getColumnTypeForRelDataType(org.apache.calcite.rel.type.RelDataType type)
      Convert RelDataType to the most appropriate ColumnType, or null if there is no ColumnType that is appropriate for this RelDataType. Equivalent to getValueTypeForRelDataTypeFull(RelDataType), except this method returns ColumnType.STRING when TypeSignature.isArray() if ExpressionProcessingConfig.processArraysAsMultiValueStrings() is set via the server property druid.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)
      Convert RelDataType to the most appropriate ColumnType, or null if there is no ColumnType that is appropriate for this RelDataType. Equivalent to getColumnTypeForRelDataType(RelDataType), but ignores ExpressionProcessingConfig.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 to ColumnType by getColumnTypeForRelDataType(RelDataType).
    • getStringComparatorForValueType

      public static StringComparator getStringComparatorForValueType(ColumnType valueType)
      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 timestamp
      timeZone - 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 timestamp
      timeZone - 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 timestamp
      sessionTimeZone - 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 timestamp
      sessionTimeZone - 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 timestamp
      timeZone - 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 timestamp
      timeZone - 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 literal
      timeZone - session time zone
      Returns:
      milliseconds time
    • calciteTimestampToJoda

      public static org.joda.time.DateTime calciteTimestampToJoda(long timestamp, org.joda.time.DateTimeZone timeZone)
      Parameters:
      timestamp - Calcite style timestamp
      timeZone - 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)
      Parameters:
      date - Calcite style date
      timeZone - session time zone
      Returns:
      joda timestamp, with time zone set to the session time zone
    • findUnusedPrefixForDigits

      public static String findUnusedPrefixForDigits(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.
    • makePrefixedName

      public static String makePrefixedName(String prefix, String suffix)
    • sqlTypeNameJdbcToJavaClass

      public static Class<?> sqlTypeNameJdbcToJavaClass(org.apache.calcite.sql.type.SqlTypeName typeName)