Java Code Examples for org.apache.calcite.sql.type.SqlTypeName#SYMBOL

The following examples show how to use org.apache.calcite.sql.type.SqlTypeName#SYMBOL . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RexLiteralImpl.java    From Bats with Apache License 2.0 5 votes vote down vote up
/**
 * Computes if data type can be omitted from the digset.
 * <p>For instance, {@code 1:BIGINT} has to keep data type while {@code 1:INT}
 * should be represented as just {@code 1}.
 *
 * <p>Implementation assumption: this method should be fast. In fact might call
 * {@link NlsString#getValue()} which could decode the string, however we rely on the cache there.
 *
 * @see RexLiteral#computeDigest(RexDigestIncludeType)
 * @param value value of the literal
 * @param type type of the literal
 * @return NO_TYPE when type can be omitted, ALWAYS otherwise
 */
private static RexDigestIncludeType shouldIncludeType(Comparable value, RelDataType type) {
    if (type.isNullable()) {
        // This means "null literal", so we require a type for it
        // There might be exceptions like AND(null, true) which are handled by RexCall#computeDigest
        return RexDigestIncludeType.ALWAYS;
    }
    // The variable here simplifies debugging (one can set a breakpoint at return)
    // final ensures we set the value in all the branches, and it ensures the value is set just once
    final RexDigestIncludeType includeType;
    if (type.getSqlTypeName() == SqlTypeName.BOOLEAN || type.getSqlTypeName() == SqlTypeName.INTEGER
            || type.getSqlTypeName() == SqlTypeName.SYMBOL) {
        // We don't want false:BOOLEAN NOT NULL, so we don't print type information for
        // non-nullable BOOLEAN and INTEGER
        includeType = RexDigestIncludeType.NO_TYPE;
    } else if (type.getSqlTypeName() == SqlTypeName.CHAR && value instanceof NlsString) {
        NlsString nlsString = (NlsString) value;

        // Ignore type information for 'Bar':CHAR(3)
        if (((nlsString.getCharset() != null && type.getCharset().equals(nlsString.getCharset()))
                || (nlsString.getCharset() == null && SqlCollation.IMPLICIT.getCharset().equals(type.getCharset())))
                && nlsString.getCollation().equals(type.getCollation())
                && ((NlsString) value).getValue().length() == type.getPrecision()) {
            includeType = RexDigestIncludeType.NO_TYPE;
        } else {
            includeType = RexDigestIncludeType.ALWAYS;
        }
    } else if (type.getPrecision() == 0 && (type.getSqlTypeName() == SqlTypeName.TIME
            || type.getSqlTypeName() == SqlTypeName.TIMESTAMP || type.getSqlTypeName() == SqlTypeName.DATE)) {
        // Ignore type information for '12:23:20':TIME(0)
        // Note that '12:23:20':TIME WITH LOCAL TIME ZONE
        includeType = RexDigestIncludeType.NO_TYPE;
    } else {
        includeType = RexDigestIncludeType.ALWAYS;
    }
    return includeType;
}
 
Example 2
Source File: SqlLiteral.java    From Bats with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a literal which represents a sample specification.
 */
public static SqlLiteral createSample(
    SqlSampleSpec sampleSpec,
    SqlParserPos pos) {
  return new SqlLiteral(sampleSpec, SqlTypeName.SYMBOL, pos);
}
 
Example 3
Source File: ColumnConstraint.java    From streamline with Apache License 2.0 4 votes vote down vote up
public PrimaryKey(SqlMonotonicity monotonicity, SqlParserPos pos) {
  super(SqlDDLKeywords.PRIMARY, SqlTypeName.SYMBOL, pos);
  this.monotonicity = monotonicity;
}
 
Example 4
Source File: SqlLiteral.java    From calcite with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a literal which represents a sample specification.
 */
public static SqlLiteral createSample(
    SqlSampleSpec sampleSpec,
    SqlParserPos pos) {
  return new SqlLiteral(sampleSpec, SqlTypeName.SYMBOL, pos);
}
 
Example 5
Source File: RexLiteral.java    From calcite with Apache License 2.0 4 votes vote down vote up
/**
 * Computes if data type can be omitted from the digset.
 * <p>For instance, {@code 1:BIGINT} has to keep data type while {@code 1:INT}
 * should be represented as just {@code 1}.
 *
 * <p>Implementation assumption: this method should be fast. In fact might call
 * {@link NlsString#getValue()} which could decode the string, however we rely on the cache there.
 *
 * @see RexLiteral#computeDigest(RexDigestIncludeType)
 * @param value value of the literal
 * @param type type of the literal
 * @return NO_TYPE when type can be omitted, ALWAYS otherwise
 */
private static RexDigestIncludeType shouldIncludeType(Comparable value, RelDataType type) {
  if (type.isNullable()) {
    // This means "null literal", so we require a type for it
    // There might be exceptions like AND(null, true) which are handled by RexCall#computeDigest
    return RexDigestIncludeType.ALWAYS;
  }
  // The variable here simplifies debugging (one can set a breakpoint at return)
  // final ensures we set the value in all the branches, and it ensures the value is set just once
  final RexDigestIncludeType includeType;
  if (type.getSqlTypeName() == SqlTypeName.BOOLEAN
      || type.getSqlTypeName() == SqlTypeName.INTEGER
      || type.getSqlTypeName() == SqlTypeName.SYMBOL) {
    // We don't want false:BOOLEAN NOT NULL, so we don't print type information for
    // non-nullable BOOLEAN and INTEGER
    includeType = RexDigestIncludeType.NO_TYPE;
  } else if (type.getSqlTypeName() == SqlTypeName.CHAR
          && value instanceof NlsString) {
    NlsString nlsString = (NlsString) value;

    // Ignore type information for 'Bar':CHAR(3)
    if ((
        (nlsString.getCharset() != null && type.getCharset().equals(nlsString.getCharset()))
        || (nlsString.getCharset() == null
        && SqlCollation.IMPLICIT.getCharset().equals(type.getCharset())))
        && nlsString.getCollation().equals(type.getCollation())
        && ((NlsString) value).getValue().length() == type.getPrecision()) {
      includeType = RexDigestIncludeType.NO_TYPE;
    } else {
      includeType = RexDigestIncludeType.ALWAYS;
    }
  } else if (type.getPrecision() == 0 && (
             type.getSqlTypeName() == SqlTypeName.TIME
          || type.getSqlTypeName() == SqlTypeName.TIMESTAMP
          || type.getSqlTypeName() == SqlTypeName.DATE)) {
    // Ignore type information for '12:23:20':TIME(0)
    // Note that '12:23:20':TIME WITH LOCAL TIME ZONE
    includeType = RexDigestIncludeType.NO_TYPE;
  } else {
    includeType = RexDigestIncludeType.ALWAYS;
  }
  return includeType;
}
 
Example 6
Source File: SqlLiteral.java    From Bats with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a literal which represents a parser symbol, for example the
 * <code>TRAILING</code> keyword in the call <code>Trim(TRAILING 'x' FROM
 * 'Hello world!')</code>.
 *
 * @see #symbolValue(Class)
 */
public static SqlLiteral createSymbol(Enum<?> o, SqlParserPos pos) {
  return new SqlLiteral(o, SqlTypeName.SYMBOL, pos);
}
 
Example 7
Source File: SqlLiteral.java    From calcite with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a literal which represents a parser symbol, for example the
 * <code>TRAILING</code> keyword in the call <code>Trim(TRAILING 'x' FROM
 * 'Hello world!')</code>.
 *
 * @see #symbolValue(Class)
 */
public static SqlLiteral createSymbol(Enum<?> o, SqlParserPos pos) {
  return new SqlLiteral(o, SqlTypeName.SYMBOL, pos);
}