Java Code Examples for org.apache.calcite.sql.SqlPrefixOperator

The following examples show how to use org.apache.calcite.sql.SqlPrefixOperator. These examples are extracted from open source projects. 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 Project: Bats   Source File: SqlParserUtil.java    License: Apache License 2.0 5 votes vote down vote up
@Override public PrecedenceClimbingParser parser(int start,
    Predicate<PrecedenceClimbingParser.Token> predicate) {
  final PrecedenceClimbingParser.Builder builder =
      new PrecedenceClimbingParser.Builder();
  for (Object o : Util.skip(list, start)) {
    if (o instanceof ToTreeListItem) {
      final ToTreeListItem item = (ToTreeListItem) o;
      final SqlOperator op = item.getOperator();
      if (op instanceof SqlPrefixOperator) {
        builder.prefix(item, op.getLeftPrec());
      } else if (op instanceof SqlPostfixOperator) {
        builder.postfix(item, op.getRightPrec());
      } else if (op instanceof SqlBinaryOperator) {
        builder.infix(item, op.getLeftPrec(),
            op.getLeftPrec() < op.getRightPrec());
      } else if (op instanceof SqlSpecialOperator) {
        builder.special(item, op.getLeftPrec(), op.getRightPrec(),
            (parser, op2) -> {
              final List<PrecedenceClimbingParser.Token> tokens =
                  parser.all();
              final SqlSpecialOperator op1 =
                  (SqlSpecialOperator) ((ToTreeListItem) op2.o).op;
              SqlSpecialOperator.ReduceResult r =
                  op1.reduceExpr(tokens.indexOf(op2),
                      new TokenSequenceImpl(parser));
              return new PrecedenceClimbingParser.Result(
                  tokens.get(r.startOrdinal),
                  tokens.get(r.endOrdinal - 1),
                  parser.atom(r.node));
            });
      } else {
        throw new AssertionError();
      }
    } else {
      builder.atom(o);
    }
  }
  return builder.build();
}
 
Example 2
Source Project: calcite   Source File: SqlParserUtil.java    License: Apache License 2.0 5 votes vote down vote up
@Override public PrecedenceClimbingParser parser(int start,
    Predicate<PrecedenceClimbingParser.Token> predicate) {
  final PrecedenceClimbingParser.Builder builder =
      new PrecedenceClimbingParser.Builder();
  for (Object o : Util.skip(list, start)) {
    if (o instanceof ToTreeListItem) {
      final ToTreeListItem item = (ToTreeListItem) o;
      final SqlOperator op = item.getOperator();
      if (op instanceof SqlPrefixOperator) {
        builder.prefix(item, op.getLeftPrec());
      } else if (op instanceof SqlPostfixOperator) {
        builder.postfix(item, op.getRightPrec());
      } else if (op instanceof SqlBinaryOperator) {
        builder.infix(item, op.getLeftPrec(),
            op.getLeftPrec() < op.getRightPrec());
      } else if (op instanceof SqlSpecialOperator) {
        builder.special(item, op.getLeftPrec(), op.getRightPrec(),
            (parser, op2) -> {
              final List<PrecedenceClimbingParser.Token> tokens =
                  parser.all();
              final SqlSpecialOperator op1 =
                  (SqlSpecialOperator) ((ToTreeListItem) op2.o).op;
              SqlSpecialOperator.ReduceResult r =
                  op1.reduceExpr(tokens.indexOf(op2),
                      new TokenSequenceImpl(parser));
              return new PrecedenceClimbingParser.Result(
                  tokens.get(r.startOrdinal),
                  tokens.get(r.endOrdinal - 1),
                  parser.atom(r.node));
            });
      } else {
        throw new AssertionError();
      }
    } else {
      builder.atom(o);
    }
  }
  return builder.build();
}