Java Code Examples for org.apache.calcite.sql.SqlLiteral#createBoolean()

The following examples show how to use org.apache.calcite.sql.SqlLiteral#createBoolean() . 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: RelToSqlConverter.java    From calcite with Apache License 2.0 6 votes vote down vote up
/** @see #dispatch */
public Result visit(Correlate e) {
  final Result leftResult =
      visitChild(0, e.getLeft())
          .resetAlias(e.getCorrelVariable(), e.getRowType());
  parseCorrelTable(e, leftResult);
  final Result rightResult = visitChild(1, e.getRight());
  final SqlNode rightLateral =
      SqlStdOperatorTable.LATERAL.createCall(POS, rightResult.node);
  final SqlNode rightLateralAs =
      SqlStdOperatorTable.AS.createCall(POS, rightLateral,
          new SqlIdentifier(rightResult.neededAlias, POS));

  final SqlNode join =
      new SqlJoin(POS,
          leftResult.asFrom(),
          SqlLiteral.createBoolean(false, POS),
          JoinType.COMMA.symbol(POS),
          rightLateralAs,
          JoinConditionType.NONE.symbol(POS),
          null);
  return result(join, leftResult, rightResult);
}
 
Example 2
Source File: RelToSqlConverter.java    From quark with Apache License 2.0 6 votes vote down vote up
public Result visitJoin(Join e) {
  final Result leftResult = visitChild(0, e.getLeft());
  final Result rightResult = visitChild(1, e.getRight());
  final Context leftContext = leftResult.qualifiedContext();
  final Context rightContext =
      rightResult.qualifiedContext();
  SqlNode sqlCondition = convertConditionToSqlNode(e.getCondition(),
      leftContext,
      rightContext,
      e.getLeft().getRowType().getFieldCount());
  SqlNode join =
      new SqlJoin(POS,
          leftResult.asFrom(),
          SqlLiteral.createBoolean(false, POS),
          joinType(e.getJoinType()).symbol(POS),
          rightResult.asFrom(),
          JoinConditionType.ON.symbol(POS),
          sqlCondition);
  return result(join, leftResult, rightResult);
}
 
Example 3
Source File: RelToSqlConverter.java    From Bats with Apache License 2.0 5 votes vote down vote up
/** @see #dispatch */
public Result visit(Join e) {
  final Result leftResult = visitChild(0, e.getLeft()).resetAlias();
  final Result rightResult = visitChild(1, e.getRight()).resetAlias();
  final Context leftContext = leftResult.qualifiedContext();
  final Context rightContext = rightResult.qualifiedContext();
  SqlNode sqlCondition = null;
  SqlLiteral condType = JoinConditionType.ON.symbol(POS);
  JoinType joinType = joinType(e.getJoinType());
  if (isCrossJoin(e)) {
    joinType = dialect.emulateJoinTypeForCrossJoin();
    condType = JoinConditionType.NONE.symbol(POS);
  } else {
    sqlCondition = convertConditionToSqlNode(e.getCondition(),
        leftContext,
        rightContext,
        e.getLeft().getRowType().getFieldCount());
  }
  SqlNode join =
      new SqlJoin(POS,
          leftResult.asFrom(),
          SqlLiteral.createBoolean(false, POS),
          joinType.symbol(POS),
          rightResult.asFrom(),
          condType,
          sqlCondition);
  return result(join, leftResult, rightResult);
}
 
Example 4
Source File: SqlPosixRegexOperator.java    From calcite with Apache License 2.0 5 votes vote down vote up
public SqlCall createCall(
    SqlLiteral functionQualifier,
    SqlParserPos pos,
    SqlNode... operands) {
  pos = pos.plusAll(Arrays.asList(operands));
  operands = Arrays.copyOf(operands, operands.length + 1);
  operands[operands.length - 1] = SqlLiteral.createBoolean(caseSensitive, SqlParserPos.ZERO);
  return new SqlBasicCall(this, operands, pos, false, functionQualifier);
}
 
Example 5
Source File: RelToSqlConverter.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** @see #dispatch */
public Result visit(Join e) {
  if (e.getJoinType() == JoinRelType.ANTI || e.getJoinType() == JoinRelType.SEMI) {
    return visitAntiOrSemiJoin(e);
  }
  final Result leftResult = visitChild(0, e.getLeft()).resetAlias();
  final Result rightResult = visitChild(1, e.getRight()).resetAlias();
  final Context leftContext = leftResult.qualifiedContext();
  final Context rightContext = rightResult.qualifiedContext();
  SqlNode sqlCondition = null;
  SqlLiteral condType = JoinConditionType.ON.symbol(POS);
  JoinType joinType = joinType(e.getJoinType());
  if (isCrossJoin(e)) {
    joinType = dialect.emulateJoinTypeForCrossJoin();
    condType = JoinConditionType.NONE.symbol(POS);
  } else {
    sqlCondition = convertConditionToSqlNode(e.getCondition(),
        leftContext,
        rightContext,
        e.getLeft().getRowType().getFieldCount(),
        dialect);
  }
  SqlNode join =
      new SqlJoin(POS,
          leftResult.asFrom(),
          SqlLiteral.createBoolean(false, POS),
          joinType.symbol(POS),
          rightResult.asFrom(),
          condType,
          sqlCondition);
  return result(join, leftResult, rightResult);
}
 
Example 6
Source File: SqlImplementor.java    From calcite with Apache License 2.0 5 votes vote down vote up
private SqlCall toSql(RexProgram program, RexOver rexOver) {
  final RexWindow rexWindow = rexOver.getWindow();
  final SqlNodeList partitionList = new SqlNodeList(
      toSql(program, rexWindow.partitionKeys), POS);

  List<SqlNode> orderNodes = Expressions.list();
  if (rexWindow.orderKeys != null) {
    for (RexFieldCollation rfc : rexWindow.orderKeys) {
      addOrderItem(orderNodes, program, rfc);
    }
  }
  final SqlNodeList orderList =
      new SqlNodeList(orderNodes, POS);

  final SqlLiteral isRows =
      SqlLiteral.createBoolean(rexWindow.isRows(), POS);

  // null defaults to true.
  // During parsing the allowPartial == false (e.g. disallow partial)
  // is expand into CASE expression and is handled as a such.
  // Not sure if we can collapse this CASE expression back into
  // "disallow partial" and set the allowPartial = false.
  final SqlLiteral allowPartial = null;

  SqlAggFunction sqlAggregateFunction = rexOver.getAggOperator();

  SqlNode lowerBound = null;
  SqlNode upperBound = null;

  if (sqlAggregateFunction.allowsFraming()) {
    lowerBound = createSqlWindowBound(rexWindow.getLowerBound());
    upperBound = createSqlWindowBound(rexWindow.getUpperBound());
  }

  final SqlWindow sqlWindow = SqlWindow.create(null, null, partitionList,
      orderList, isRows, lowerBound, upperBound, allowPartial, POS);

  final List<SqlNode> nodeList = toSql(program, rexOver.getOperands());
  return createOverCall(sqlAggregateFunction, nodeList, sqlWindow);
}
 
Example 7
Source File: DremioRelToSqlConverter.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
/**
 * @see #dispatch
 */
@Override
public SqlImplementor.Result visit(Join e) {
  final DremioRelToSqlConverter.Result leftResult = (DremioRelToSqlConverter.Result) visitChild(0, e.getLeft()).resetAlias();
  final DremioRelToSqlConverter.Result rightResult = (DremioRelToSqlConverter.Result) visitChild(1, e.getRight()).resetAlias();

  SqlNode sqlCondition = null;
  SqlLiteral condType = JoinConditionType.ON.symbol(POS);
  JoinType joinType = joinType(e.getJoinType());
  final Context leftContext = leftResult.qualifiedContext();
  final Context rightContext = rightResult.qualifiedContext();
  final Context joinContext = leftContext.implementor().joinContext(leftContext, rightContext);
  final RexNode condition = e.getCondition() == null ?
    null :
    this.simplifyDatetimePlus(e.getCondition(), e.getCluster().getRexBuilder());
  sqlCondition = joinContext.toSql(null, condition);

  final SqlNode join =
    new SqlJoin(POS,
      leftResult.asFrom(),
      SqlLiteral.createBoolean(false, POS),
      joinType.symbol(POS),
      rightResult.asFrom(),
      condType,
      sqlCondition);
  return result(join, leftResult, rightResult);
}
 
Example 8
Source File: RelToSqlConverter.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
/**
 * @see #dispatch
 */
public Result visit(Join e) {
  final Result leftResult = visitChild(0, e.getLeft()).resetAlias();
  final Result rightResult = visitChild(1, e.getRight()).resetAlias();
  final Context leftContext = leftResult.qualifiedContext();
  final Context rightContext = rightResult.qualifiedContext();
  SqlNode sqlCondition = null;
  SqlLiteral condType = JoinConditionType.ON.symbol(POS);
  JoinType joinType = joinType(e.getJoinType());
  if (e.getJoinType() == JoinRelType.INNER && e.getCondition().isAlwaysTrue()) {
    joinType = JoinType.COMMA;
    condType = JoinConditionType.NONE.symbol(POS);
  } else {
    final RexNode condition = e.getCondition() != null
      ? simplifyDatetimePlus(e.getCondition(), e.getCluster().getRexBuilder())
      : null;
    sqlCondition = convertConditionToSqlNode(
      condition,
      leftContext,
      rightContext,
      e.getLeft().getRowType().getFieldCount());
  }
  SqlNode join =
    new SqlJoin(POS,
      leftResult.asFrom(),
      SqlLiteral.createBoolean(false, POS),
      joinType.symbol(POS),
      rightResult.asFrom(),
      condType,
      sqlCondition);
  return result(join, leftResult, rightResult);
}
 
Example 9
Source File: SqlImplementor.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
protected SqlCall toSql(RexProgram program, RexOver rexOver) {
  final RexWindow rexWindow = rexOver.getWindow();
  final SqlNodeList partitionList = new SqlNodeList(
    toSql(program, rexWindow.partitionKeys), POS);

  ImmutableList.Builder<SqlNode> orderNodes = ImmutableList.builder();
  if (rexWindow.orderKeys != null) {
    for (RexFieldCollation rfc : rexWindow.orderKeys) {
      orderNodes.add(toSql(program, rfc));
    }
  }
  final SqlNodeList orderList =
    new SqlNodeList(orderNodes.build(), POS);

  final SqlLiteral isRows =
    SqlLiteral.createBoolean(rexWindow.isRows(), POS);

  final SqlNode lowerBound =
    createSqlWindowBound(rexWindow.getLowerBound());
  final SqlNode upperBound =
    createSqlWindowBound(rexWindow.getUpperBound());

  // null defaults to true.
  // During parsing the allowPartial == false (e.g. disallow partial)
  // is expand into CASE expression and is handled as a such.
  // Not sure if we can collapse this CASE expression back into
  // "disallow partial" and set the allowPartial = false.
  final SqlLiteral allowPartial = null;

  final SqlWindow sqlWindow = SqlWindow.create(null, null, partitionList,
    orderList, isRows, lowerBound, upperBound, allowPartial, POS);

  final List<SqlNode> nodeList = toSql(program, rexOver.getOperands());
  final SqlCall aggFunctionCall =
    rexOver.getAggOperator().createCall(POS, nodeList);

  return SqlStdOperatorTable.OVER.createCall(POS, aggFunctionCall,
    sqlWindow);
}
 
Example 10
Source File: SqlCreateReflection.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
public static SqlCreateReflection createRaw(SqlParserPos pos, SqlIdentifier tblName, SqlNodeList displayList,
                                            SqlNodeList distributionList, SqlNodeList partitionList,
                                            SqlNodeList sortList,
                                            PartitionDistributionStrategy partitionDistributionStrategy,
                                            SqlIdentifier name) {
  return new SqlCreateReflection(pos, tblName, SqlLiteral.createBoolean(true, SqlParserPos.ZERO), displayList, null, null,
      distributionList, partitionList, sortList, partitionDistributionStrategy, name);
}
 
Example 11
Source File: SqlCreateReflection.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
public static SqlCreateReflection createAggregation(SqlParserPos pos, SqlIdentifier tblName, SqlNodeList dimensionList,
                                                    SqlNodeList measureList, SqlNodeList distributionList,
                                                    SqlNodeList partitionList, SqlNodeList sortList,
                                                    PartitionDistributionStrategy partitionDistributionStrategy, SqlIdentifier name) {
  return new SqlCreateReflection(pos, tblName, SqlLiteral.createBoolean(false, SqlParserPos.ZERO), null, dimensionList,
      measureList, distributionList, partitionList, sortList, partitionDistributionStrategy, name);
}
 
Example 12
Source File: SqlImplementor.java    From Bats with Apache License 2.0 5 votes vote down vote up
private SqlCall toSql(RexProgram program, RexOver rexOver) {
    final RexWindow rexWindow = rexOver.getWindow();
    final SqlNodeList partitionList = new SqlNodeList(toSql(program, rexWindow.partitionKeys), POS);

    ImmutableList.Builder<SqlNode> orderNodes = ImmutableList.builder();
    if (rexWindow.orderKeys != null) {
        for (RexFieldCollation rfc : rexWindow.orderKeys) {
            orderNodes.add(toSql(program, rfc));
        }
    }
    final SqlNodeList orderList = new SqlNodeList(orderNodes.build(), POS);

    final SqlLiteral isRows = SqlLiteral.createBoolean(rexWindow.isRows(), POS);

    // null defaults to true.
    // During parsing the allowPartial == false (e.g. disallow partial)
    // is expand into CASE expression and is handled as a such.
    // Not sure if we can collapse this CASE expression back into
    // "disallow partial" and set the allowPartial = false.
    final SqlLiteral allowPartial = null;

    SqlAggFunction sqlAggregateFunction = rexOver.getAggOperator();

    SqlNode lowerBound = null;
    SqlNode upperBound = null;

    if (sqlAggregateFunction.allowsFraming()) {
        lowerBound = createSqlWindowBound(rexWindow.getLowerBound());
        upperBound = createSqlWindowBound(rexWindow.getUpperBound());
    }

    final SqlWindow sqlWindow = SqlWindow.create(null, null, partitionList, orderList, isRows, lowerBound,
            upperBound, allowPartial, POS);

    final List<SqlNode> nodeList = toSql(program, rexOver.getOperands());
    return createOverCall(sqlAggregateFunction, nodeList, sqlWindow);
}
 
Example 13
Source File: DremioRelToSqlConverter.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
@Override
public SqlCall toSql(RexProgram program, RexOver rexOver) {
  final RexWindow rexWindow = rexOver.getWindow();
  final SqlNodeList partitionList = new SqlNodeList(
    toSql(program, rexWindow.partitionKeys), POS);

  ImmutableList.Builder<SqlNode> orderNodes = ImmutableList.builder();
  if (rexWindow.orderKeys != null) {
    for (RexFieldCollation rfc : rexWindow.orderKeys) {
      // Omit ORDER BY <ordinal> clauses, which are parsed by Calcite but not actually
      // used for sorting.
      if (!(rfc.getKey() instanceof RexLiteral)) {
        if (rfc.getNullDirection() != dialect.defaultNullDirection(rfc.getDirection())) {
          // Get the SQL Node for the column being sorted on only.
          final SqlNode orderingColumnNode = toSql(program, rfc.left);

          final SqlNode emulatedNullDirNode = dialect.emulateNullDirection(orderingColumnNode,
            rfc.getNullDirection() == RelFieldCollation.NullDirection.FIRST, rfc.getDirection().isDescending());
          if (emulatedNullDirNode != null) {
            // Dialect requires emulating null direction.
            // Put the emulation in the order list first, then the ordering on the column only.
            orderNodes.add(emulatedNullDirNode);
            orderNodes.add(orderingColumnNode);
          } else {
            // Dialect implements NULLS FIRST and NULLS LAST clauses. These will get
            // unparsed as part of the RexFieldCollation.
            orderNodes.add(toSql(program, rfc));
          }
        } else {
          orderNodes.add(toSql(program, rfc));
        }
      }
    }
  }

  final SqlNodeList orderList =
    new SqlNodeList(orderNodes.build(), POS);

  final SqlLiteral isRows =
    SqlLiteral.createBoolean(rexWindow.isRows(), POS);

  final SqlNode lowerBound;
  final SqlNode upperBound;

  // Remove unnecessary Window Frames. When Calcite parses an OVER clause with no frame,
  final boolean hasUnnecessaryFrame = getDialect().removeDefaultWindowFrame(rexOver)
    && OverUtils.hasDefaultFrame(rexOver);

  if (hasUnnecessaryFrame) {
    lowerBound = null;
    upperBound = null;
  } else {
    lowerBound = createSqlWindowBound(rexWindow.getLowerBound());
    upperBound = createSqlWindowBound(rexWindow.getUpperBound());
  }

  // null defaults to true.
  // During parsing the allowPartial == false (e.g. disallow partial)
  // is expand into CASE expression and is handled as a such.
  // Not sure if we can collapse this CASE expression back into
  // "disallow partial" and set the allowPartial = false.
  final SqlLiteral allowPartial = null;

  final SqlWindow sqlWindow = getDremioRelToSqlConverter().adjustWindowForSource(
    this, rexOver.getAggOperator(), SqlWindow.create(
      null, null, partitionList,
      orderList, isRows, lowerBound, upperBound, allowPartial, POS));

  final List<SqlNode> nodeList = toSql(program, rexOver.getOperands());

  // Create the call for the aggregate in the window function.
  // If it happens to be a SUM0 call, we need to swap that with our own version which sets
  // the name to just SUM, rather than $SUM0, so that it can be translated to SQL compatible
  // with RDBMSes.
  final SqlAggFunction operator = rexOver.getAggOperator() != SqlStdOperatorTable.SUM0 ?
    rexOver.getAggOperator() : SUM0_FUNCTION;

  final SqlCall aggFunctionCall = operator.createCall(POS, nodeList);

  return SqlStdOperatorTable.OVER.createCall(POS, aggFunctionCall,
    sqlWindow);
}
 
Example 14
Source File: SqlImplementor.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
public List<SqlNode> toSql(Window.Group group, ImmutableList<RexLiteral> constants,
                           int inputFieldCount) {
  final List<SqlNode> rexOvers = new ArrayList<>();
  final List<SqlNode> partitionKeys = new ArrayList<>();
  final List<SqlNode> orderByKeys = new ArrayList<>();
  for (int partition : group.keys) {
    partitionKeys.add(this.field(partition));
  }
  for (RelFieldCollation collation : group.orderKeys.getFieldCollations()) {
    this.addOrderItem(orderByKeys, collation);
  }
  SqlLiteral isRows = SqlLiteral.createBoolean(group.isRows, POS);
  SqlNode lowerBound = null;
  SqlNode upperBound = null;

  final SqlLiteral allowPartial = null;

  for (Window.RexWinAggCall winAggCall : group.aggCalls) {
    SqlAggFunction aggFunction = (SqlAggFunction) winAggCall.getOperator();
    final SqlWindow sqlWindow = SqlWindow.create(null, null,
      new SqlNodeList(partitionKeys, POS), new SqlNodeList(orderByKeys, POS),
      isRows, lowerBound, upperBound, allowPartial, POS);
    if (aggFunction.allowsFraming()) {
      lowerBound = createSqlWindowBound(group.lowerBound);
      upperBound = createSqlWindowBound(group.upperBound);
      sqlWindow.setLowerBound(lowerBound);
      sqlWindow.setUpperBound(upperBound);
    }

    RexShuttle replaceConstants = new RexShuttle() {
      @Override
      public RexNode visitInputRef(RexInputRef inputRef) {
        int index = inputRef.getIndex();
        RexNode ref;
        if (index > inputFieldCount - 1) {
          ref = constants.get(index - inputFieldCount);
        } else {
          ref = inputRef;
        }
        return ref;
      }
    };
    RexCall aggCall = (RexCall) winAggCall.accept(replaceConstants);
    List<SqlNode> operands = toSql(null, aggCall.operands);
    rexOvers.add(createOverCall(aggFunction, operands, sqlWindow));
  }
  return rexOvers;
}
 
Example 15
Source File: SqlImplementor.java    From calcite with Apache License 2.0 4 votes vote down vote up
public List<SqlNode> toSql(Window.Group group, ImmutableList<RexLiteral> constants,
    int inputFieldCount) {
  final List<SqlNode> rexOvers = new ArrayList<>();
  final List<SqlNode> partitionKeys = new ArrayList<>();
  final List<SqlNode> orderByKeys = new ArrayList<>();
  for (int partition: group.keys) {
    partitionKeys.add(this.field(partition));
  }
  for (RelFieldCollation collation: group.orderKeys.getFieldCollations()) {
    this.addOrderItem(orderByKeys, collation);
  }
  SqlLiteral isRows = SqlLiteral.createBoolean(group.isRows, POS);
  SqlNode lowerBound = null;
  SqlNode upperBound = null;

  final SqlLiteral allowPartial = null;

  for (Window.RexWinAggCall winAggCall: group.aggCalls) {
    SqlAggFunction aggFunction = (SqlAggFunction) winAggCall.getOperator();
    final SqlWindow sqlWindow = SqlWindow.create(null, null,
            new SqlNodeList(partitionKeys, POS), new SqlNodeList(orderByKeys, POS),
            isRows, lowerBound, upperBound, allowPartial, POS);
    if (aggFunction.allowsFraming()) {
      lowerBound = createSqlWindowBound(group.lowerBound);
      upperBound = createSqlWindowBound(group.upperBound);
      sqlWindow.setLowerBound(lowerBound);
      sqlWindow.setUpperBound(upperBound);
    }

    RexShuttle replaceConstants = new RexShuttle() {
      @Override public RexNode visitInputRef(RexInputRef inputRef) {
        int index = inputRef.getIndex();
        RexNode ref;
        if (index > inputFieldCount - 1) {
          ref = constants.get(index - inputFieldCount);
        } else {
          ref = inputRef;
        }
        return ref;
      }
    };
    RexCall aggCall = (RexCall) winAggCall.accept(replaceConstants);
    List<SqlNode> operands = toSql(null, aggCall.operands);
    rexOvers.add(createOverCall(aggFunction, operands, sqlWindow));
  }
  return rexOvers;
}
 
Example 16
Source File: RexToSqlNodeConverterImpl.java    From Bats with Apache License 2.0 4 votes vote down vote up
public SqlNode convertLiteral(RexLiteral literal) {
  // Numeric
  if (SqlTypeFamily.EXACT_NUMERIC.getTypeNames().contains(
      literal.getTypeName())) {
    return SqlLiteral.createExactNumeric(
        literal.getValue().toString(),
        SqlParserPos.ZERO);
  }

  if (SqlTypeFamily.APPROXIMATE_NUMERIC.getTypeNames().contains(
      literal.getTypeName())) {
    return SqlLiteral.createApproxNumeric(
        literal.getValue().toString(),
        SqlParserPos.ZERO);
  }

  // Timestamp
  if (SqlTypeFamily.TIMESTAMP.getTypeNames().contains(
      literal.getTypeName())) {
    return SqlLiteral.createTimestamp(
        literal.getValueAs(TimestampString.class),
        0,
        SqlParserPos.ZERO);
  }

  // Date
  if (SqlTypeFamily.DATE.getTypeNames().contains(
      literal.getTypeName())) {
    return SqlLiteral.createDate(
        literal.getValueAs(DateString.class),
        SqlParserPos.ZERO);
  }

  // Time
  if (SqlTypeFamily.TIME.getTypeNames().contains(
      literal.getTypeName())) {
    return SqlLiteral.createTime(
        literal.getValueAs(TimeString.class),
        0,
        SqlParserPos.ZERO);
  }

  // String
  if (SqlTypeFamily.CHARACTER.getTypeNames().contains(
      literal.getTypeName())) {
    return SqlLiteral.createCharString(
        ((NlsString) (literal.getValue())).getValue(),
        SqlParserPos.ZERO);
  }

  // Boolean
  if (SqlTypeFamily.BOOLEAN.getTypeNames().contains(
      literal.getTypeName())) {
    return SqlLiteral.createBoolean(
        (Boolean) literal.getValue(),
        SqlParserPos.ZERO);
  }

  // Null
  if (SqlTypeFamily.NULL == literal.getTypeName().getFamily()) {
    return SqlLiteral.createNull(SqlParserPos.ZERO);
  }

  return null;
}
 
Example 17
Source File: RexToSqlNodeConverterImpl.java    From calcite with Apache License 2.0 4 votes vote down vote up
public SqlNode convertLiteral(RexLiteral literal) {
  // Numeric
  if (SqlTypeFamily.EXACT_NUMERIC.getTypeNames().contains(
      literal.getTypeName())) {
    return SqlLiteral.createExactNumeric(
        literal.getValue().toString(),
        SqlParserPos.ZERO);
  }

  if (SqlTypeFamily.APPROXIMATE_NUMERIC.getTypeNames().contains(
      literal.getTypeName())) {
    return SqlLiteral.createApproxNumeric(
        literal.getValue().toString(),
        SqlParserPos.ZERO);
  }

  // Timestamp
  if (SqlTypeFamily.TIMESTAMP.getTypeNames().contains(
      literal.getTypeName())) {
    return SqlLiteral.createTimestamp(
        literal.getValueAs(TimestampString.class),
        0,
        SqlParserPos.ZERO);
  }

  // Date
  if (SqlTypeFamily.DATE.getTypeNames().contains(
      literal.getTypeName())) {
    return SqlLiteral.createDate(
        literal.getValueAs(DateString.class),
        SqlParserPos.ZERO);
  }

  // Time
  if (SqlTypeFamily.TIME.getTypeNames().contains(
      literal.getTypeName())) {
    return SqlLiteral.createTime(
        literal.getValueAs(TimeString.class),
        0,
        SqlParserPos.ZERO);
  }

  // String
  if (SqlTypeFamily.CHARACTER.getTypeNames().contains(
      literal.getTypeName())) {
    return SqlLiteral.createCharString(
        ((NlsString) (literal.getValue())).getValue(),
        SqlParserPos.ZERO);
  }

  // Boolean
  if (SqlTypeFamily.BOOLEAN.getTypeNames().contains(
      literal.getTypeName())) {
    return SqlLiteral.createBoolean(
        (Boolean) literal.getValue(),
        SqlParserPos.ZERO);
  }

  // Null
  if (SqlTypeFamily.NULL == literal.getTypeName().getFamily()) {
    return SqlLiteral.createNull(SqlParserPos.ZERO);
  }

  return null;
}