Refine search
final SqlKind kind = call.getKind(); final List<SqlNode> operands = call.getOperandList(); for (int i = 0; i < operands.size(); i++) { SqlNode operand = operands.get(i); performUnconditionalRewrites(operand, childUnderFrom); if (newOperand != null && newOperand != operand) { call.setOperand(i, newOperand); node = call.getOperator().rewriteCall(this, call); final SqlKind kind = node.getKind(); switch (kind) { case VALUES: SqlNodeList selectList2 = getInnerSelect(node).getSelectList(); for (Ord<SqlNode> sel : Ord.zip(selectList2)) { if (stripAs(sel.e).equalsDeep(sqlNode, Litmus.IGNORE)) { orderList.set(i, SqlLiteral.createExactNumeric(Integer.toString(sel.i + 1), SqlParserPos.ZERO)); selectList.add(SqlIdentifier.star(SqlParserPos.ZERO)); return new SqlSelect(SqlParserPos.ZERO, null, selectList, call.operand(0), null, null, null, null, null, null, null);
selectList = SqlNode.clone(updateStmt.getSourceSelect().getSelectList()); } else { selectList.add(SqlIdentifier.star(SqlParserPos.ZERO)); SqlValidatorUtil.addAlias( targetTable, call.getAlias().getSimple()); SqlInsert insertCall = call.getInsertCall(); JoinType joinType = (insertCall == null) ? JoinType.INNER : JoinType.LEFT; final SqlNode leftJoinTerm = SqlNode.clone(sourceTableRef); SqlNode outerJoin = new SqlJoin(SqlParserPos.ZERO, leftJoinTerm, SqlLiteral.createBoolean(false, SqlParserPos.ZERO), joinType.symbol(SqlParserPos.ZERO), targetTable, SqlCall rowCall = valuesCall.operand(0); selectList = new SqlNodeList( rowCall.getOperandList(), SqlParserPos.ZERO); final SqlNode insertSource = SqlNode.clone(sourceTableRef); select = new SqlSelect(SqlParserPos.ZERO, null, selectList, insertSource, null,
try { p = SqlParserUtil.trim(token.image, "xX'"); frags = startList(SqlLiteral.createBinaryString(p, getPos())); nfrags++; } catch (NumberFormatException ex) { try { p = SqlParserUtil.trim(token.image, "'"); // no embedded quotes frags.add(SqlLiteral.createBinaryString(p, getPos())); nfrags++; } catch (NumberFormatException ex) { SqlCharStringLiteral literal; try { literal = SqlLiteral.createCharString(p, charSet, getPos()); } catch (java.nio.charset.UnsupportedCharsetException e) { {if (true) throw SqlUtil.newContextException(getPos(), p = SqlParserUtil.parseString(token.image); try { literal = SqlLiteral.createCharString(p, charSet, getPos()); } catch (java.nio.charset.UnsupportedCharsetException e) { {if (true) throw SqlUtil.newContextException(getPos(), {if (true) return lit.unescapeUnicode(unicodeEscapeChar);} } else { SqlNode[] rands = (SqlNode[]) frags.toArray(new SqlNode[nfrags]); for (int i = 0; i < rands.length; ++i) { rands[i] = ((SqlLiteral) rands[i]).unescapeUnicode(
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); }
public void validateLiteral(SqlLiteral literal) { switch (literal.getTypeName()) { case DECIMAL: BigDecimal bd = (BigDecimal) literal.getValue(); BigInteger unscaled = bd.unscaledValue(); long longValue = unscaled.longValue(); final BitString bitString = (BitString) literal.getValue(); if ((bitString.getBitCount() % 8) != 0) { throw newValidationError(literal, RESOURCE.binaryLiteralOdd()); 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())); SqlIntervalLiteral.IntervalValue interval = (SqlIntervalLiteral.IntervalValue) literal.getValue(); SqlIntervalQualifier intervalQualifier = interval.getIntervalQualifier(); literal.getParserPosition(), typeFactory.getTypeSystem()); Util.discard(values);
/** Parses a unsigned numeric literal */ final public SqlNumericLiteral UnsignedNumericLiteral() throws ParseException { if (jj_2_321(2)) { jj_consume_token(UNSIGNED_INTEGER_LITERAL); {if (true) return SqlLiteral.createExactNumeric(token.image, getPos());} } else if (jj_2_322(2)) { jj_consume_token(DECIMAL_NUMERIC_LITERAL); {if (true) return SqlLiteral.createExactNumeric(token.image, getPos());} } else if (jj_2_323(2)) { jj_consume_token(APPROX_NUMERIC_LITERAL); {if (true) return SqlLiteral.createApproxNumeric(token.image, getPos());} } else { jj_consume_token(-1); throw new ParseException(); } throw new Error("Missing return statement in function"); }
&& rowsPerMatch.getValue() == SqlMatchRecognize.RowsPerMatchOption.ALL_ROWS; for (SqlNode node : partitionBy) { SqlIdentifier identifier = (SqlIdentifier) node; identifier.validate(this, scope); RelDataType type = deriveType(scope, identifier); String name = identifier.names.get(1); pattern.accept(visitor); interval.validate(this, scope); if (((SqlIntervalLiteral) interval).signum() < 0) { throw newValidationError(interval, RESOURCE.intervalMustBeNonNegative(interval.toValue())); for (SqlNode right : (SqlNodeList) operands.get(1)) { SqlIdentifier id = (SqlIdentifier) right; if (!scope.getPatternVars().contains(id.getSimple())) { if (skipTo instanceof SqlCall) { final SqlCall skipToCall = (SqlCall) skipTo; final SqlIdentifier id = skipToCall.operand(0);
/** * Copies a {@link SqlCall}, replacing the time unit operand with the given * literal. * * @param call Call * @param literal Literal to replace time unit with * @param pos Parser position * @return Modified call */ public static SqlCall replaceTimeUnitOperand(SqlCall call, String literal, SqlParserPos pos) { SqlLiteral literalNode = SqlLiteral.createCharString(literal, null, pos); return call.getOperator().createCall(call.getFunctionQuantifier(), pos, call.getOperandList().get(0), literalNode); }
/** Parse a special literal keyword */ final public SqlLiteral SpecialLiteral() throws ParseException { if (jj_2_327(2)) { jj_consume_token(TRUE); {if (true) return SqlLiteral.createBoolean(true, getPos());} } else if (jj_2_328(2)) { jj_consume_token(FALSE); {if (true) return SqlLiteral.createBoolean(false, getPos());} } else if (jj_2_329(2)) { jj_consume_token(UNKNOWN); {if (true) return SqlLiteral.createUnknown(getPos());} } else if (jj_2_330(2)) { jj_consume_token(NULL); {if (true) return SqlLiteral.createNull(getPos());} } else { jj_consume_token(-1); throw new ParseException(); } throw new Error("Missing return statement in function"); }
public SqlLiteral createLiteral(Object o, SqlParserPos pos) { switch (this) { case BOOLEAN: return SqlLiteral.createBoolean((Boolean) o, pos); case TINYINT: case SMALLINT: case BIGINT: case DECIMAL: return SqlLiteral.createExactNumeric(o.toString(), pos); case VARCHAR: case CHAR: return SqlLiteral.createCharString((String) o, pos); case VARBINARY: case BINARY: return SqlLiteral.createBinaryString((byte[]) o, pos); case DATE: return SqlLiteral.createDate(o instanceof Calendar ? DateString.fromCalendarFields((Calendar) o) : (DateString) o, pos); case TIME: return SqlLiteral.createTime(o instanceof Calendar ? TimeString.fromCalendarFields((Calendar) o) : (TimeString) o, 0 /* todo */, pos); case TIMESTAMP: return SqlLiteral.createTimestamp(o instanceof Calendar ? TimestampString.fromCalendarFields((Calendar) o) : (TimestampString) o, 0 /* todo */, pos);
SqlParserPos pos = new SqlParserPos(1, 1); SqlNode amt = bs.getAmt() == 0 ? null : SqlLiteral.createExactNumeric( String.valueOf(bs.getAmt()), new SqlParserPos(2, 2)); RexNode amtLiteral = null; SqlCall sc = null; sc = (SqlCall) SqlWindow.createPreceding(amt, pos); rwb = RexWindowBound.create(sc, cluster.getRexBuilder().makeCall(sc.getOperator(), amtLiteral)); rwb = RexWindowBound.create(SqlWindow.createCurrentRow(new SqlParserPos(1, 1)), null); break; sc = (SqlCall) SqlWindow.createFollowing(amt, pos); rwb = RexWindowBound.create(sc, cluster.getRexBuilder().makeCall(sc.getOperator(), amtLiteral));
SqlLiteral startNum = null; SqlLiteral endNum = null; SqlLiteral reluctant = SqlLiteral.createBoolean(false, SqlParserPos.ZERO); e = PatternPrimary(); if (jj_2_227(2)) { if (jj_2_222(2)) { jj_consume_token(STAR); startNum = SqlLiteral.createExactNumeric("0", SqlParserPos.ZERO); endNum = SqlLiteral.createExactNumeric("-1", SqlParserPos.ZERO); } else if (jj_2_223(2)) { jj_consume_token(PLUS); startNum = SqlLiteral.createExactNumeric("1", SqlParserPos.ZERO); endNum = SqlLiteral.createExactNumeric("-1", SqlParserPos.ZERO); } else if (jj_2_224(2)) { jj_consume_token(HOOK); startNum = SqlLiteral.createExactNumeric("0", SqlParserPos.ZERO); endNum = SqlLiteral.createExactNumeric("1", SqlParserPos.ZERO); } else if (jj_2_225(2)) { jj_consume_token(LBRACE); if (jj_2_218(2)) { jj_consume_token(COMMA); endNum = SqlLiteral.createExactNumeric("-1", SqlParserPos.ZERO); if (jj_2_217(2)) { endNum = UnsignedNumericLiteral(); startNum = SqlLiteral.createExactNumeric("-1", SqlParserPos.ZERO); jj_consume_token(COMMA); endNum = UnsignedNumericLiteral();
final public SqlCall MatchRecognizeNavigationPhysical() throws ParseException { final Span s; SqlCall func; SqlOperator funcOp; SqlNode arg0; SqlNode arg1 = SqlLiteral.createExactNumeric("1", SqlParserPos.ZERO); if (jj_2_575(2)) { jj_consume_token(PREV); funcOp = SqlStdOperatorTable.PREV; } else if (jj_2_576(2)) { jj_consume_token(NEXT); funcOp = SqlStdOperatorTable.NEXT; } else { jj_consume_token(-1); throw new ParseException(); } s = span(); jj_consume_token(LPAREN); arg0 = Expression(ExprContext.ACCEPT_SUB_QUERY); if (jj_2_577(2)) { jj_consume_token(COMMA); arg1 = NumericLiteral(); } else { ; } jj_consume_token(RPAREN); {if (true) return funcOp.createCall(s.end(this), arg0, arg1);} throw new Error("Missing return statement in function"); }
@Override public SqlNode visit(SqlIdentifier id) { if (id.isSimple()) { return id; } SqlOperator operator = id.names.get(0).equals(alpha) ? SqlStdOperatorTable.PREV : SqlStdOperatorTable.LAST; return operator.createCall(SqlParserPos.ZERO, id, SqlLiteral.createExactNumeric("0", SqlParserPos.ZERO)); } }
SqlLiteral lit = SqlLiteral.createCharString(id, "UTF16", getPos()); lit = lit.unescapeUnicode(unicodeEscapeChar); {if (true) return lit.toValue();} } else if (jj_2_419(2)) { id = NonReservedKeyWord();
public SqlNode rewriteCall(SqlValidator validator, SqlCall call) { List<SqlNode> operands = call.getOperandList(); SqlParserPos pos = call.getParserPosition(); checkOperandCount( validator, getOperandTypeChecker(), call); assert operands.size() == 2; SqlNodeList whenList = new SqlNodeList(pos); SqlNodeList thenList = new SqlNodeList(pos); whenList.add(operands.get(1)); thenList.add(SqlLiteral.createNull(SqlParserPos.ZERO)); return SqlCase.createSwitched(pos, operands.get(0), whenList, thenList, SqlNode.clone(operands.get(0))); } }
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) { rand.unparse(writer, leftPrec, rightPrec); } else { if (rand.getTypeName() == SqlTypeName.BINARY) { BitString bs = (BitString) rand.getValue(); writer.literal("'" + bs.toHexString() + "'"); } else { writer.literal("'" + rand.toValue() + "'");
joinConditionType = JoinConditionType.ON.symbol(getPos()); condition = Expression(ExprContext.ACCEPT_SUB_QUERY); e = new SqlJoin(joinType.getParserPosition(), e, natural, joinConditionType = JoinConditionType.USING.symbol(getPos()); list = ParenthesizedSimpleIdentifierList(); e = new SqlJoin(joinType.getParserPosition(), e, natural, new SqlNodeList(list.getList(), Span.of(joinConditionType).end(this))); } else { e = new SqlJoin(joinType.getParserPosition(), e, natural, joinType, e2, JoinConditionType.NONE.symbol(joinType.getParserPosition()), null); joinType = JoinType.COMMA.symbol(getPos()); e2 = TableRef(); e = new SqlJoin(joinType.getParserPosition(), e, SqlLiteral.createBoolean(false, joinType.getParserPosition()), joinType, e2,
private void doWriteFetchNext(SqlNode fetch, SqlNode offset) { if (offset == null && !configurer.allowNoOffset()) offset = SqlLiteral.createExactNumeric("0", SqlParserPos.ZERO); if (fetch != null && !configurer.allowNoOrderByWithFetch() && lastFrame != null && lastFrame.getFrameType() != FrameTypeEnum.ORDER_BY_LIST) { // MSSQL requires ORDER_BY list for FETCH clause, so must append one here. DUMMY_ORDER_BY_NODE.unparse(this, 0, 0); } if (offset != null) { this.newlineAndIndent(); final Frame offsetFrame = this.startList(FrameTypeEnum.OFFSET); this.keyword("OFFSET"); offset.unparse(this, -1, -1); this.keyword("ROWS"); this.endList(offsetFrame); } if (fetch != null) { if (!configurer.allowFetchNoRows() && fetch instanceof SqlNumericLiteral) if (((SqlNumericLiteral) fetch).toValue().equals("0")) fetch = SqlLiteral.createExactNumeric("1", SqlParserPos.ZERO); this.newlineAndIndent(); final Frame fetchFrame = this.startList(FrameTypeEnum.FETCH); this.keyword("FETCH"); this.keyword("NEXT"); fetch.unparse(this, -1, -1); this.keyword("ROWS"); this.keyword("ONLY"); this.endList(fetchFrame); } }
switch (root.getKind()) { case GROUPING_SETS: case ROLLUP: switch (literal.getTypeName()) { case DECIMAL: case DOUBLE: final int intValue = literal.intValue(false); if (intValue >= 0) { if (intValue < 1 || intValue > select.getSelectList().size()) {