当前位置: 首页>>代码示例>>Java>>正文


Java SqlLiteral.getTypeName方法代码示例

本文整理汇总了Java中org.apache.calcite.sql.SqlLiteral.getTypeName方法的典型用法代码示例。如果您正苦于以下问题:Java SqlLiteral.getTypeName方法的具体用法?Java SqlLiteral.getTypeName怎么用?Java SqlLiteral.getTypeName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.calcite.sql.SqlLiteral的用法示例。


在下文中一共展示了SqlLiteral.getTypeName方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: visit

import org.apache.calcite.sql.SqlLiteral; //导入方法依赖的package包/类
public SqlNode visit(SqlLiteral literal) {
  // Ordinal markers, e.g. 'select a, b from t order by 2'.
  // Only recognize them if they are the whole expression,
  // and if the dialect permits.
  if (literal == root && getConformance().isSortByOrdinal()) {
    switch (literal.getTypeName()) {
    case DECIMAL:
    case DOUBLE:
      final int intValue = literal.intValue(false);
      if (intValue >= 0) {
        if (intValue < 1 || intValue > aliasList.size()) {
          throw newValidationError(
              literal, RESOURCE.orderByOrdinalOutOfRange());
        }

        // SQL ordinals are 1-based, but Sort's are 0-based
        int ordinal = intValue - 1;
        return nthSelectItem(ordinal, literal.getParserPosition());
      }
      break;
    }
  }

  return super.visit(literal);
}
 
开发者ID:apache,项目名称:calcite,代码行数:26,代码来源:SqlValidatorImpl.java

示例2: createOptionValue

import org.apache.calcite.sql.SqlLiteral; //导入方法依赖的package包/类
private static OptionValue createOptionValue(final String name, final OptionValue.OptionType type,
                                             final SqlLiteral literal) {
  final Object object = literal.getValue();
  final SqlTypeName typeName = literal.getTypeName();
  switch (typeName) {
  case DECIMAL: {
    final BigDecimal bigDecimal = (BigDecimal) object;
    if (bigDecimal.scale() == 0) {
      return OptionValue.createLong(type, name, bigDecimal.longValue());
    } else {
      return OptionValue.createDouble(type, name, bigDecimal.doubleValue());
    }
  }

  case DOUBLE:
  case FLOAT:
    return OptionValue.createDouble(type, name, ((BigDecimal) object).doubleValue());

  case SMALLINT:
  case TINYINT:
  case BIGINT:
  case INTEGER:
    return OptionValue.createLong(type, name, ((BigDecimal) object).longValue());

  case VARBINARY:
  case VARCHAR:
  case CHAR:
    return OptionValue.createString(type, name, ((NlsString) object).getValue());

  case BOOLEAN:
    return OptionValue.createBoolean(type, name, (Boolean) object);

  default:
    throw UserException.validationError()
      .message("Drill doesn't support assigning literals of type %s in SET statements.", typeName)
      .build(logger);
  }
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:39,代码来源:SetOptionHandler.java

示例3: createOptionValue

import org.apache.calcite.sql.SqlLiteral; //导入方法依赖的package包/类
private static OptionValue createOptionValue(final String name, final OptionValue.OptionType type,
                                             final SqlLiteral literal) {
  final Object object = literal.getValue();
  final SqlTypeName typeName = literal.getTypeName();
  switch (typeName) {
  case DECIMAL: {
    final BigDecimal bigDecimal = (BigDecimal) object;
    if (bigDecimal.scale() == 0) {
      return OptionValue.createLong(type, name, bigDecimal.longValue());
    } else {
      return OptionValue.createDouble(type, name, bigDecimal.doubleValue());
    }
  }

  case DOUBLE:
  case FLOAT:
    return OptionValue.createDouble(type, name, ((BigDecimal) object).doubleValue());

  case SMALLINT:
  case TINYINT:
  case BIGINT:
  case INTEGER:
    return OptionValue.createLong(type, name, ((BigDecimal) object).longValue());

  case VARBINARY:
  case VARCHAR:
  case CHAR:
    return OptionValue.createString(type, name, ((NlsString) object).getValue());

  case BOOLEAN:
    return OptionValue.createBoolean(type, name, (Boolean) object);

  default:
    throw UserException.validationError()
      .message("Dremio doesn't support assigning literals of type %s in SET statements.", typeName)
      .build(logger);
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:39,代码来源:SetOptionHandler.java

示例4: sqlLiteralToObject

import org.apache.calcite.sql.SqlLiteral; //导入方法依赖的package包/类
private static Object sqlLiteralToObject(final SqlLiteral literal) {
  final Object object = literal.getValue();
  final SqlTypeName typeName = literal.getTypeName();
  switch (typeName) {
  case DECIMAL: {
    final BigDecimal bigDecimal = (BigDecimal) object;
    if (bigDecimal.scale() == 0) {
      return bigDecimal.longValue();
    } else {
      return bigDecimal.doubleValue();
    }
  }

  case DOUBLE:
  case FLOAT:
    return ((BigDecimal) object).doubleValue();

  case SMALLINT:
  case TINYINT:
  case BIGINT:
  case INTEGER:
    return ((BigDecimal) object).longValue();

  case VARBINARY:
  case VARCHAR:
  case CHAR:
    return ((NlsString) object).getValue().toString();

  case BOOLEAN:
    return object;

  default:
    throw UserException.validationError()
      .message("Drill doesn't support assigning literals of type %s in SET statements.", typeName)
      .build(logger);
  }
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:38,代码来源:SetOptionHandler.java

示例5: validateLiteral

import org.apache.calcite.sql.SqlLiteral; //导入方法依赖的package包/类
public void validateLiteral(SqlLiteral literal) {
  switch (literal.getTypeName()) {
  case DECIMAL:
    // Decimal and long have the same precision (as 64-bit integers), so
    // the unscaled value of a decimal must fit into a long.

    // REVIEW jvs 4-Aug-2004:  This should probably be calling over to
    // the available calculator implementations to see what they
    // support.  For now use ESP instead.
    //
    // jhyde 2006/12/21: I think the limits should be baked into the
    // type system, not dependent on the calculator implementation.
    BigDecimal bd = (BigDecimal) literal.getValue();
    BigInteger unscaled = bd.unscaledValue();
    long longValue = unscaled.longValue();
    if (!BigInteger.valueOf(longValue).equals(unscaled)) {
      // overflow
      throw newValidationError(literal,
          RESOURCE.numberLiteralOutOfRange(bd.toString()));
    }
    break;

  case DOUBLE:
    validateLiteralAsDouble(literal);
    break;

  case BINARY:
    final BitString bitString = (BitString) literal.getValue();
    if ((bitString.getBitCount() % 8) != 0) {
      throw newValidationError(literal, RESOURCE.binaryLiteralOdd());
    }
    break;

  case DATE:
  case TIME:
  case TIMESTAMP:
    Calendar calendar = literal.getValueAs(Calendar.class);
    final int year = calendar.get(Calendar.YEAR);
    final int era = calendar.get(Calendar.ERA);
    if (year < 1 || era == GregorianCalendar.BC || year > 9999) {
      throw newValidationError(literal,
          RESOURCE.dateLiteralOutOfRange(literal.toString()));
    }
    break;

  case INTERVAL_YEAR:
  case INTERVAL_YEAR_MONTH:
  case INTERVAL_MONTH:
  case INTERVAL_DAY:
  case INTERVAL_DAY_HOUR:
  case INTERVAL_DAY_MINUTE:
  case INTERVAL_DAY_SECOND:
  case INTERVAL_HOUR:
  case INTERVAL_HOUR_MINUTE:
  case INTERVAL_HOUR_SECOND:
  case INTERVAL_MINUTE:
  case INTERVAL_MINUTE_SECOND:
  case INTERVAL_SECOND:
    if (literal instanceof SqlIntervalLiteral) {
      SqlIntervalLiteral.IntervalValue interval =
          (SqlIntervalLiteral.IntervalValue)
              literal.getValue();
      SqlIntervalQualifier intervalQualifier =
          interval.getIntervalQualifier();

      // ensure qualifier is good before attempting to validate literal
      validateIntervalQualifier(intervalQualifier);
      String intervalStr = interval.getIntervalLiteral();
      // throws CalciteContextException if string is invalid
      int[] values = intervalQualifier.evaluateIntervalLiteral(intervalStr,
          literal.getParserPosition(), typeFactory.getTypeSystem());
      Util.discard(values);
    }
    break;
  default:
    // default is to do nothing
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:79,代码来源:SqlValidatorImpl.java

示例6: unparse

import org.apache.calcite.sql.SqlLiteral; //导入方法依赖的package包/类
public void unparse(
    SqlWriter writer,
    SqlCall call,
    int leftPrec,
    int rightPrec) {
  final SqlWriter.Frame frame = writer.startList("", "");
  SqlCollation collation = null;
  for (Ord<SqlNode> operand : Ord.zip(call.getOperandList())) {
    SqlLiteral rand = (SqlLiteral) operand.e;
    if (operand.i > 0) {
      // SQL:2003 says there must be a newline between string
      // fragments.
      writer.newlineAndIndent();
    }
    if (rand instanceof SqlCharStringLiteral) {
      NlsString nls = ((SqlCharStringLiteral) rand).getNlsString();
      if (operand.i == 0) {
        collation = nls.getCollation();

        // print with prefix
        writer.literal(nls.asSql(true, false));
      } else {
        // print without prefix
        writer.literal(nls.asSql(false, false));
      }
    } else if (operand.i == 0) {
      // print with prefix
      rand.unparse(writer, leftPrec, rightPrec);
    } else {
      // print without prefix
      if (rand.getTypeName() == SqlTypeName.BINARY) {
        BitString bs = (BitString) rand.getValue();
        writer.literal("'" + bs.toHexString() + "'");
      } else {
        writer.literal("'" + rand.toValue() + "'");
      }
    }
  }
  if (collation != null) {
    collation.unparse(writer, 0, 0);
  }
  writer.endList(frame);
}
 
开发者ID:apache,项目名称:calcite,代码行数:44,代码来源:SqlLiteralChainOperator.java


注:本文中的org.apache.calcite.sql.SqlLiteral.getTypeName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。