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


Java SqlLiteral.getValueAs方法代码示例

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


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

示例1: unparseCall

import org.apache.calcite.sql.SqlLiteral; //导入方法依赖的package包/类
@Override public void unparseCall(SqlWriter writer, SqlCall call,
    int leftPrec, int rightPrec) {
  if (call.getOperator() == SqlStdOperatorTable.SUBSTRING) {
    SqlUtil.unparseFunctionSyntax(OracleSqlOperatorTable.SUBSTR, writer, call);
  } else {
    switch (call.getKind()) {
    case FLOOR:
      if (call.operandCount() != 2) {
        super.unparseCall(writer, call, leftPrec, rightPrec);
        return;
      }

      final SqlLiteral timeUnitNode = call.operand(1);
      final TimeUnitRange timeUnit = timeUnitNode.getValueAs(TimeUnitRange.class);

      SqlCall call2 = SqlFloorFunction.replaceTimeUnitOperand(call, timeUnit.name(),
          timeUnitNode.getParserPosition());
      SqlFloorFunction.unparseDatetimeFunction(writer, call2, "TRUNC", true);
      break;

    default:
      super.unparseCall(writer, call, leftPrec, rightPrec);
    }
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:26,代码来源:OracleSqlDialect.java

示例2: unparseCall

import org.apache.calcite.sql.SqlLiteral; //导入方法依赖的package包/类
@Override public void unparseCall(SqlWriter writer, SqlCall call,
    int leftPrec, int rightPrec) {
  switch (call.getKind()) {
  case FLOOR:
    if (call.operandCount() != 2) {
      super.unparseCall(writer, call, leftPrec, rightPrec);
      return;
    }

    final SqlLiteral timeUnitNode = call.operand(1);
    final TimeUnitRange timeUnit = timeUnitNode.getValueAs(TimeUnitRange.class);

    final String translatedLit = convertTimeUnit(timeUnit);
    SqlCall call2 = SqlFloorFunction.replaceTimeUnitOperand(call, translatedLit,
        timeUnitNode.getParserPosition());
    SqlFloorFunction.unparseDatetimeFunction(writer, call2, "TRUNC", true);
    break;

  default:
    super.unparseCall(writer, call, leftPrec, rightPrec);
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:23,代码来源:HsqldbSqlDialect.java

示例3: unparseCall

import org.apache.calcite.sql.SqlLiteral; //导入方法依赖的package包/类
@Override public void unparseCall(SqlWriter writer, SqlCall call,
    int leftPrec, int rightPrec) {
  switch (call.getKind()) {
  case FLOOR:
    if (call.operandCount() != 2) {
      super.unparseCall(writer, call, leftPrec, rightPrec);
      return;
    }

    final SqlLiteral timeUnitNode = call.operand(1);
    final TimeUnitRange timeUnit = timeUnitNode.getValueAs(TimeUnitRange.class);

    SqlCall call2 = SqlFloorFunction.replaceTimeUnitOperand(call, timeUnit.name(),
        timeUnitNode.getParserPosition());
    SqlFloorFunction.unparseDatetimeFunction(writer, call2, "DATE_TRUNC", false);
    break;

  default:
    super.unparseCall(writer, call, leftPrec, rightPrec);
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:22,代码来源:PostgresqlSqlDialect.java

示例4: 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


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