org.apache.calcite.sql.SqlNode - java examples

Here are the examples of the java api org.apache.calcite.sql.SqlNode taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

155 Examples 7

19 View Complete Implementation : DelegatingScope.java
Copyright Apache License 2.0
Author : apache
public Map<String, ScopeChild> findQualifyingTableNames(String columnName, SqlNode ctx, SqlNameMatcher nameMatcher) {
    return parent.findQualifyingTableNames(columnName, ctx, nameMatcher);
}

19 View Complete Implementation : Span.java
Copyright Apache License 2.0
Author : apache
/**
 * Adds a node's position to the list,
 * and returns a position that covers the whole range.
 */
public SqlParserPos end(SqlNode n) {
    return add(n).pos();
}

19 View Complete Implementation : SetopNamespace.java
Copyright Apache License 2.0
Author : apache
@Override
public SqlMonotonicity getMonotonicity(String columnName) {
    SqlMonotonicity monotonicity = null;
    int index = getRowType().getFieldNames().indexOf(columnName);
    if (index < 0) {
        return SqlMonotonicity.NOT_MONOTONIC;
    }
    for (SqlNode operand : call.getOperandList()) {
        final SqlValidatorNamespace namespace = validator.getNamespace(operand);
        monotonicity = combine(monotonicity, namespace.getMonotonicity(namespace.getRowType().getFieldNames().get(index)));
    }
    return monotonicity;
}

19 View Complete Implementation : SqlDdlNodes.java
Copyright Apache License 2.0
Author : apache
/**
 * Creates a CREATE FUNCTION.
 */
public static SqlCreateFunction createFunction(SqlParserPos pos, boolean replace, boolean ifNotExists, SqlIdentifier name, SqlNode clreplacedName, SqlNodeList usingList) {
    return new SqlCreateFunction(pos, replace, ifNotExists, name, clreplacedName, usingList);
}

19 View Complete Implementation : SqlValidatorUtil.java
Copyright Apache License 2.0
Author : apache
private static int lookupGroupExpr(Groupreplacedyzer groupreplacedyzer, SqlNode expr) {
    for (Ord<SqlNode> node : Ord.zip(groupreplacedyzer.groupExprs)) {
        if (node.e.equalsDeep(expr, Litmus.IGNORE)) {
            return node.i;
        }
    }
    switch(expr.getKind()) {
        case HOP:
        case TUMBLE:
        case SESSION:
            groupreplacedyzer.extraExprs.add(expr);
            break;
    }
    groupreplacedyzer.groupExprs.add(expr);
    return groupreplacedyzer.groupExprs.size() - 1;
}

19 View Complete Implementation : SqlParserUtil.java
Copyright Apache License 2.0
Author : apache
/**
 * Converts a list of {expression, operator, expression, ...} into a tree,
 * taking operator precedence and replacedociativity into account.
 *
 * @param list        List of operands and operators. This list is modified as
 *                    expressions are reduced.
 * @param start       Position of first operand in the list. Anything to the
 *                    left of this (besides the immediately preceding operand)
 *                    is ignored. Generally use value 1.
 * @param minPrec     Minimum precedence to consider. If the method encounters
 *                    an operator of lower precedence, it doesn't reduce any
 *                    further.
 * @param stopperKind If not {@link SqlKind#OTHER}, stop reading the list if
 *                    we encounter a token of this kind.
 * @return the root node of the tree which the list condenses into
 */
public static SqlNode toTreeEx(SqlSpecialOperator.TokenSequence list, int start, final int minPrec, final SqlKind stopperKind) {
    PrecedenceClimbingParser parser = list.parser(start, token -> {
        if (token instanceof PrecedenceClimbingParser.Op) {
            final SqlOperator op = ((ToTreeLisreplacedem) token.o).op;
            return stopperKind != SqlKind.OTHER && op.kind == stopperKind || minPrec > 0 && op.getLeftPrec() < minPrec;
        } else {
            return false;
        }
    });
    final int beforeSize = parser.all().size();
    parser.partialParse();
    final int afterSize = parser.all().size();
    final SqlNode node = convert(parser.all().get(0));
    list.replaceSublist(start, start + beforeSize - afterSize + 1, node);
    return node;
}

19 View Complete Implementation : PlannerImpl.java
Copyright Apache License 2.0
Author : apache
public Pair<SqlNode, RelDataType> validateAndGetType(SqlNode sqlNode) throws ValidationException {
    final SqlNode validatedNode = this.validate(sqlNode);
    final RelDataType type = this.validator.getValidatedNodeType(validatedNode);
    return Pair.of(validatedNode, type);
}

19 View Complete Implementation : AbstractSqlTester.java
Copyright Apache License 2.0
Author : apache
public void replacedertExceptionIsThrown(String sql, String expectedMsgPattern) {
    final SqlValidator validator;
    final SqlNode sqlNode;
    final SqlParserUtil.StringAndPos sap = SqlParserUtil.findPos(sql);
    try {
        sqlNode = parseQuery(sap.sql);
        validator = getValidator();
    } catch (Throwable e) {
        checkParseEx(e, expectedMsgPattern, sap.sql);
        return;
    }
    Throwable thrown = null;
    try {
        validator.validate(sqlNode);
    } catch (Throwable ex) {
        thrown = ex;
    }
    SqlTests.checkEx(thrown, expectedMsgPattern, sap, SqlTests.Stage.VALIDATE);
}

19 View Complete Implementation : SqlValidatorUtil.java
Copyright Apache License 2.0
Author : apache
/**
 * Converts an expression "expr" into "expr AS alias".
 */
public static SqlNode addAlias(SqlNode expr, String alias) {
    final SqlParserPos pos = expr.getParserPosition();
    final SqlIdentifier id = new SqlIdentifier(alias, pos);
    return SqlStdOperatorTable.AS.createCall(pos, expr, id);
}

19 View Complete Implementation : SqlRuntimeTester.java
Copyright Apache License 2.0
Author : apache
public void replacedertExceptionIsThrown(String sql, String expectedMsgPattern, boolean runtime) {
    final SqlNode sqlNode;
    final SqlParserUtil.StringAndPos sap = SqlParserUtil.findPos(sql);
    try {
        sqlNode = parseQuery(sap.sql);
    } catch (Throwable e) {
        checkParseEx(e, expectedMsgPattern, sap.sql);
        return;
    }
    Throwable thrown = null;
    final SqlTests.Stage stage;
    final SqlValidator validator = getValidator();
    if (runtime) {
        stage = SqlTests.Stage.RUNTIME;
        SqlNode validated = validator.validate(sqlNode);
        replacedertNotNull(validated);
        try {
            check(sap.sql, SqlTests.ANY_TYPE_CHECKER, SqlTests.ANY_PARAMETER_CHECKER, SqlTests.ANY_RESULT_CHECKER);
        } catch (Throwable ex) {
            // get the real exception in runtime check
            thrown = ex;
        }
    } else {
        stage = SqlTests.Stage.VALIDATE;
        try {
            validator.validate(sqlNode);
        } catch (Throwable ex) {
            thrown = ex;
        }
    }
    SqlTests.checkEx(thrown, expectedMsgPattern, sap, stage);
}

19 View Complete Implementation : SqlJsonArrayFunction.java
Copyright Apache License 2.0
Author : apache
private <E extends Enum<E>> E getEnumValue(SqlNode operand) {
    return (E) ((SqlLiteral) operand).getValue();
}

19 View Complete Implementation : SqlParserPos.java
Copyright Apache License 2.0
Author : apache
private static List<SqlParserPos> toPos(final SqlNode[] nodes) {
    return new AbstractList<SqlParserPos>() {

        public SqlParserPos get(int index) {
            return nodes[index].getParserPosition();
        }

        public int size() {
            return nodes.length;
        }
    };
}

19 View Complete Implementation : Span.java
Copyright Apache License 2.0
Author : apache
/**
 * Adds the positions of a collection of nodes to the list,
 * and returns this Span.
 */
public Span addAll(Iterable<? extends SqlNode> nodes) {
    for (SqlNode node : nodes) {
        add(node);
    }
    return this;
}

19 View Complete Implementation : SqlDotOperator.java
Copyright Apache License 2.0
Author : apache
@Override
public ReduceResult reduceExpr(int ordinal, TokenSequence list) {
    SqlNode left = list.node(ordinal - 1);
    SqlNode right = list.node(ordinal + 1);
    return new ReduceResult(ordinal - 1, ordinal + 2, createCall(SqlParserPos.sum(Arrays.asList(left.getParserPosition(), right.getParserPosition(), list.pos(ordinal))), left, right));
}

19 View Complete Implementation : MssqlSqlDialect.java
Copyright Apache License 2.0
Author : apache
@Override
public void unparseTopN(SqlWriter writer, SqlNode offset, SqlNode fetch) {
    if (top) {
        // Per Microsoft:
        // "For backward compatibility, the parentheses are optional in SELECT
        // statements. We recommend that you always use parentheses for TOP in
        // SELECT statements. Doing so provides consistency with its required
        // use in INSERT, UPDATE, MERGE, and DELETE statements."
        // 
        // Note that "fetch" is ignored.
        writer.keyword("TOP");
        writer.keyword("(");
        fetch.unparse(writer, -1, -1);
        writer.keyword(")");
    }
}

19 View Complete Implementation : RelToSqlConverter.java
Copyright Apache License 2.0
Author : apache
private SqlCall as(SqlNode e, String alias) {
    return SqlStdOperatorTable.AS.createCall(POS, e, new SqlIdentifier(alias, POS));
}

19 View Complete Implementation : SqlAdvisor.java
Copyright Apache License 2.0
Author : apache
/**
 * Attempts to parse and validate a SQL statement. Throws the first
 * exception encountered. The error message of this exception is to be
 * displayed on the UI
 *
 * @param sql A user-input sql statement to be validated
 * @return a List of ValidateErrorInfo (null if sql is valid)
 */
public List<ValidateErrorInfo> validate(String sql) {
    SqlNode sqlNode;
    List<ValidateErrorInfo> errorList = new ArrayList<>();
    sqlNode = collectParserError(sql, errorList);
    if (!errorList.isEmpty()) {
        return errorList;
    }
    try {
        validator.validate(sqlNode);
    } catch (CalciteContextException e) {
        ValidateErrorInfo errInfo = new ValidateErrorInfo(e);
        // validator only returns 1 exception now
        errorList.add(errInfo);
        return errorList;
    } catch (Exception e) {
        ValidateErrorInfo errInfo = new ValidateErrorInfo(1, 1, 1, sql.length(), e.getMessage());
        // parser only returns 1 exception now
        errorList.add(errInfo);
        return errorList;
    }
    return null;
}

19 View Complete Implementation : DelegatingScope.java
Copyright Apache License 2.0
Author : apache
public SqlMonotonicity getMonotonicity(SqlNode expr) {
    return parent.getMonotonicity(expr);
}

19 View Complete Implementation : TableScope.java
Copyright Apache License 2.0
Author : apache
/**
 * The name-resolution scope of a LATERAL TABLE clause.
 *
 * <p>The objects visible are those in the parameters found on the left side of
 * the LATERAL TABLE clause, and objects inherited from the parent scope.
 */
clreplaced TableScope extends ListScope {

    // ~ Instance fields --------------------------------------------------------
    private final SqlNode node;

    // ~ Constructors -----------------------------------------------------------
    /**
     * Creates a scope corresponding to a LATERAL TABLE clause.
     *
     * @param parent  Parent scope
     */
    TableScope(SqlValidatorScope parent, SqlNode node) {
        super(Objects.requireNonNull(parent));
        this.node = Objects.requireNonNull(node);
    }

    // ~ Methods ----------------------------------------------------------------
    public SqlNode getNode() {
        return node;
    }

    @Override
    public boolean isWithin(SqlValidatorScope scope2) {
        if (this == scope2) {
            return true;
        }
        SqlValidatorScope s = getValidator().getSelectScope((SqlSelect) node);
        return s.isWithin(scope2);
    }
}

19 View Complete Implementation : SqlParserPos.java
Copyright Apache License 2.0
Author : apache
/**
 * Combines this parser position with an array of positions to create a
 * position that spans from the first point in the first to the last point
 * in the other.
 */
public SqlParserPos plusAll(SqlNode[] nodes) {
    return plusAll(Arrays.asList(nodes));
}

19 View Complete Implementation : SqlCase.java
Copyright Apache License 2.0
Author : apache
@Override
public void setOperand(int i, SqlNode operand) {
    switch(i) {
        case 0:
            value = operand;
            break;
        case 1:
            whenList = (SqlNodeList) operand;
            break;
        case 2:
            thenList = (SqlNodeList) operand;
            break;
        case 3:
            elseExpr = operand;
            break;
        default:
            throw new replacedertionError(i);
    }
}

19 View Complete Implementation : AbstractSqlTester.java
Copyright Apache License 2.0
Author : apache
public void checkFails(String expression, String expectedError, boolean runtime) {
    if (runtime) {
        // We need to test that the expression fails at runtime.
        // Ironically, that means that it must succeed at prepare time.
        SqlValidator validator = getValidator();
        final String sql = buildQuery(expression);
        SqlNode n = parseAndValidate(validator, sql);
        replacedertNotNull(n);
    } else {
        checkQueryFails(buildQuery(expression), expectedError);
    }
}

19 View Complete Implementation : PigConverter.java
Copyright Apache License 2.0
Author : apache
/**
 * Converts a Pig script to a list of SQL statements.
 *
 * @param pigQuery Pig script
 * @param writer The SQL writer to decide dialect and format of SQL statements
 * @throws IOException Exception during parsing or translating Pig
 */
private List<String> pigToSql(String pigQuery, SqlWriter writer) throws IOException {
    final RelToSqlConverter sqlConverter = new PigRelToSqlConverter(writer.getDialect());
    final List<RelNode> finalRels = pigQuery2Rel(pigQuery);
    final List<String> sqlStatements = new ArrayList<>();
    for (RelNode rel : finalRels) {
        final SqlNode sqlNode = sqlConverter.visitChild(0, rel).replacedtatement();
        sqlNode.unparse(writer, 0, 0);
        sqlStatements.add(writer.toString());
    }
    return sqlStatements;
}

19 View Complete Implementation : AggFinder.java
Copyright Apache License 2.0
Author : apache
// ~ Methods ----------------------------------------------------------------
/**
 * Finds an aggregate.
 *
 * @param node Parse tree to search
 * @return First aggregate function in parse tree, or null if not found
 */
public SqlCall findAgg(SqlNode node) {
    try {
        node.accept(this);
        return null;
    } catch (Util.FoundOne e) {
        Util.swallow(e, null);
        return (SqlCall) e.getNode();
    }
}

19 View Complete Implementation : CompositeSingleOperandTypeChecker.java
Copyright Apache License 2.0
Author : apache
public boolean checkSingleOperandType(SqlCallBinding callBinding, SqlNode node, int iFormalOperand, boolean throwOnFailure) {
    replacedert allowedRules.size() >= 1;
    final ImmutableList<? extends SqlSingleOperandTypeChecker> rules = getRules();
    if (composition == Composition.SEQUENCE) {
        return rules.get(iFormalOperand).checkSingleOperandType(callBinding, node, 0, throwOnFailure);
    }
    int typeErrorCount = 0;
    boolean throwOnAndFailure = (composition == Composition.AND) && throwOnFailure;
    for (SqlSingleOperandTypeChecker rule : rules) {
        if (!rule.checkSingleOperandType(callBinding, node, iFormalOperand, throwOnAndFailure)) {
            typeErrorCount++;
        }
    }
    boolean ret;
    switch(composition) {
        case AND:
            ret = typeErrorCount == 0;
            break;
        case OR:
            ret = typeErrorCount < allowedRules.size();
            break;
        default:
            // should never come here
            throw Util.unexpected(composition);
    }
    if (!ret && throwOnFailure) {
        // In the case of a composite OR, we want to throw an error
        // describing in more detail what the problem was, hence doing the
        // loop again.
        for (SqlSingleOperandTypeChecker rule : rules) {
            rule.checkSingleOperandType(callBinding, node, iFormalOperand, true);
        }
        // If no exception thrown, just throw a generic validation signature
        // error.
        throw callBinding.newValidationSignatureError();
    }
    return ret;
}

19 View Complete Implementation : AbstractSqlTester.java
Copyright Apache License 2.0
Author : apache
public void check(String query, TypeChecker typeChecker, ParameterChecker parameterChecker, ResultChecker resultChecker) {
    // This implementation does NOT check the result!
    // All it does is check the return type.
    if (typeChecker == null) {
        // Parse and validate. There should be no errors.
        Util.discard(getResultType(query));
    } else {
        // Parse and validate. There should be no errors.
        // There must be 1 column. Get its type.
        RelDataType actualType = getColumnType(query);
        // Check result type.
        typeChecker.checkType(actualType);
    }
    SqlValidator validator = getValidator();
    SqlNode n = parseAndValidate(validator, query);
    final RelDataType parameterRowType = validator.getParameterRowType(n);
    parameterChecker.checkParameters(parameterRowType);
}

19 View Complete Implementation : SqlValidatorUtil.java
Copyright Apache License 2.0
Author : apache
/**
 * Derives an alias for a node, and invents a mangled identifier if it
 * cannot.
 *
 * <p>Examples:
 *
 * <ul>
 * <li>Alias: "1 + 2 as foo" yields "foo"
 * <li>Identifier: "foo.bar.baz" yields "baz"
 * <li>Anything else yields "expr$<i>ordinal</i>"
 * </ul>
 *
 * @return An alias, if one can be derived; or a synthetic alias
 * "expr$<i>ordinal</i>" if ordinal < 0; otherwise null
 */
public static String getAlias(SqlNode node, int ordinal) {
    switch(node.getKind()) {
        case AS:
            // E.g. "1 + 2 as foo" --> "foo"
            return ((SqlCall) node).operand(1).toString();
        case OVER:
            // E.g. "bids over w" --> "bids"
            return getAlias(((SqlCall) node).operand(0), ordinal);
        case IDENTIFIER:
            // E.g. "foo.bar" --> "bar"
            return Util.last(((SqlIdentifier) node).names);
        default:
            if (ordinal < 0) {
                return null;
            } else {
                return SqlUtil.deriveAliasFromOrdinal(ordinal);
            }
    }
}

19 View Complete Implementation : SqlCaseOperator.java
Copyright Apache License 2.0
Author : apache
public boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFailure) {
    SqlCase caseCall = (SqlCase) callBinding.getCall();
    SqlNodeList whenList = caseCall.getWhenOperands();
    SqlNodeList thenList = caseCall.getThenOperands();
    replacedert whenList.size() == thenList.size();
    // checking that search conditions are ok...
    for (SqlNode node : whenList) {
        // should throw validation error if something wrong...
        RelDataType type = callBinding.getValidator().deriveType(callBinding.getScope(), node);
        if (!SqlTypeUtil.inBooleanFamily(type)) {
            if (throwOnFailure) {
                throw callBinding.newError(RESOURCE.expectedBoolean());
            }
            return false;
        }
    }
    boolean foundNotNull = false;
    for (SqlNode node : thenList) {
        if (!SqlUtil.isNullLiteral(node, false)) {
            foundNotNull = true;
        }
    }
    if (!SqlUtil.isNullLiteral(caseCall.getElseOperand(), false)) {
        foundNotNull = true;
    }
    if (!foundNotNull) {
        // according to the sql standard we can not have all of the THEN
        // statements and the ELSE returning null
        if (throwOnFailure && !callBinding.getValidator().isTypeCoercionEnabled()) {
            throw callBinding.newError(RESOURCE.mustNotNullInElse());
        }
        return false;
    }
    return true;
}

19 View Complete Implementation : MysqlSqlDialect.java
Copyright Apache License 2.0
Author : apache
@Override
public SqlNode emulateNullDirection(SqlNode node, boolean nullsFirst, boolean desc) {
    return emulateNullDirectionWithIsNull(node, nullsFirst, desc);
}

19 View Complete Implementation : AggregatingSelectScope.java
Copyright Apache License 2.0
Author : apache
public boolean checkAggregateExpr(SqlNode expr, boolean deep) {
    // Fully-qualify any identifiers in expr.
    if (deep) {
        expr = validator.expand(expr, this);
    }
    // Make sure expression is valid, throws if not.
    Pair<ImmutableList<SqlNode>, ImmutableList<SqlNode>> pair = getGroupExprs();
    final AggChecker aggChecker = new AggChecker(validator, this, pair.left, pair.right, distinct);
    if (deep) {
        expr.accept(aggChecker);
    }
    // Return whether expression exactly matches one of the group
    // expressions.
    return aggChecker.isGroupExpr(expr);
}

19 View Complete Implementation : ParameterScope.java
Copyright Apache License 2.0
Author : apache
@Override
public RelDataType resolveColumn(String name, SqlNode ctx) {
    return nameToTypeMap.get(name);
}

19 View Complete Implementation : RexWindowBound.java
Copyright Apache License 2.0
Author : apache
/**
 * Creates window bound.
 * @param node SqlNode of the bound
 * @param rexNode offset value when bound is not UNBOUNDED/CURRENT ROW
 * @return window bound
 */
public static RexWindowBound create(SqlNode node, RexNode rexNode) {
    if (SqlWindow.isUnboundedPreceding(node) || SqlWindow.isUnboundedFollowing(node)) {
        return new RexWindowBoundUnbounded(node);
    }
    if (SqlWindow.isCurrentRow(node)) {
        return new RexWindowBoundCurrentRow();
    }
    return new RexWindowBoundBounded(rexNode);
}

19 View Complete Implementation : DelegatingScope.java
Copyright Apache License 2.0
Author : apache
public void validateExpr(SqlNode expr) {
// Do not delegate to parent. An expression valid in this scope may not
// be valid in the parent scope.
}

19 View Complete Implementation : RexSqlStandardConvertletTable.java
Copyright Apache License 2.0
Author : apache
private SqlNode[] convertExpressionList(RexToSqlNodeConverter converter, List<RexNode> nodes) {
    final SqlNode[] exprs = new SqlNode[nodes.size()];
    for (int i = 0; i < nodes.size(); i++) {
        RexNode node = nodes.get(i);
        exprs[i] = converter.convertNode(node);
        if (exprs[i] == null) {
            return null;
        }
    }
    return exprs;
}

19 View Complete Implementation : SqlPrettyWriter.java
Copyright Apache License 2.0
Author : apache
public void fetchOffset(SqlNode fetch, SqlNode offset) {
    if (fetch == null && offset == null) {
        return;
    }
    dialect.unparseOffsetFetch(this, offset, fetch);
}

19 View Complete Implementation : PlannerImpl.java
Copyright Apache License 2.0
Author : apache
public SqlNode validate(SqlNode sqlNode) throws ValidationException {
    ensure(State.STATE_3_PARSED);
    this.validator = createSqlValidator(createCatalogReader());
    try {
        validatedSqlNode = validator.validate(sqlNode);
    } catch (RuntimeException e) {
        throw new ValidationException(e);
    }
    state = State.STATE_4_VALIDATED;
    return validatedSqlNode;
}

19 View Complete Implementation : SqlJsonQueryFunction.java
Copyright Apache License 2.0
Author : apache
private <E extends Enum<E>> E getEnumValue(SqlNode operand) {
    return (E) ((SqlLiteral) operand).getValue();
}

19 View Complete Implementation : PlannerImpl.java
Copyright Apache License 2.0
Author : apache
public RelRoot rel(SqlNode sql) throws RelConversionException {
    ensure(State.STATE_4_VALIDATED);
    replacedert validatedSqlNode != null;
    final RexBuilder rexBuilder = createRexBuilder();
    final RelOptCluster cluster = RelOptCluster.create(planner, rexBuilder);
    final SqlToRelConverter.Config config = SqlToRelConverter.configBuilder().withConfig(sqlToRelConverterConfig).withTrimUnusedFields(false).withConvertTableAccess(false).build();
    final SqlToRelConverter sqlToRelConverter = new SqlToRelConverter(this, validator, createCatalogReader(), cluster, convertletTable, config);
    root = sqlToRelConverter.convertQuery(validatedSqlNode, false, true);
    root = root.withRel(sqlToRelConverter.flattenTypes(root.rel, true));
    final RelBuilder relBuilder = config.getRelBuilderFactory().create(cluster, null);
    root = root.withRel(RelDecorrelator.decorrelateQuery(root.rel, relBuilder));
    state = State.STATE_5_CONVERTED;
    return root;
}

19 View Complete Implementation : AbstractSqlTester.java
Copyright Apache License 2.0
Author : apache
public SqlNode parseAndValidate(SqlValidator validator, String sql) {
    SqlNode sqlNode;
    try {
        sqlNode = parseQuery(sql);
    } catch (Throwable e) {
        throw new RuntimeException("Error while parsing query: " + sql, e);
    }
    return validator.validate(sqlNode);
}

19 View Complete Implementation : AggFinder.java
Copyright Apache License 2.0
Author : apache
/**
 * Creates a copy of this finder that has the same parameters as this,
 * then returns the list of all aggregates found.
 */
Iterable<SqlCall> findAll(Iterable<SqlNode> nodes) {
    final AggIterable aggIterable = new AggIterable(opTab, over, aggregate, group, delegate, nameMatcher);
    for (SqlNode node : nodes) {
        node.accept(aggIterable);
    }
    return aggIterable.calls;
}

19 View Complete Implementation : EmptyScope.java
Copyright Apache License 2.0
Author : apache
public SqlMonotonicity getMonotonicity(SqlNode expr) {
    return ((expr instanceof SqlLiteral) || (expr instanceof SqlDynamicParam) || (expr instanceof SqlDataTypeSpec)) ? SqlMonotonicity.CONSTANT : SqlMonotonicity.NOT_MONOTONIC;
}

19 View Complete Implementation : SqlValidatorUtil.java
Copyright Apache License 2.0
Author : apache
/**
 * Returns whether any of the given expressions are sorted.
 *
 * <p>If so, it can be the default ORDER BY clause for a WINDOW specification.
 * (This is an extension to the SQL standard for streaming.)
 */
static boolean containsMonotonic(SelectScope scope, SqlNodeList nodes) {
    for (SqlNode node : nodes) {
        if (!scope.getMonotonicity(node).mayRepeat()) {
            return true;
        }
    }
    return false;
}

19 View Complete Implementation : EmptyScope.java
Copyright Apache License 2.0
Author : apache
public Map<String, ScopeChild> findQualifyingTableNames(String columnName, SqlNode ctx, SqlNameMatcher nameMatcher) {
    return ImmutableMap.of();
}

19 View Complete Implementation : SqlAdvisor.java
Copyright Apache License 2.0
Author : apache
/**
 * Attempts to complete and validate a given partially completed sql
 * statement, and returns whether it is valid.
 *
 * @param sql A partial or syntactically incorrect sql statement to validate
 * @return whether SQL statement is valid
 */
public boolean isValid(String sql) {
    SqlSimpleParser simpleParser = new SqlSimpleParser(HINT_TOKEN, parserConfig);
    String simpleSql = simpleParser.simplifySql(sql);
    SqlNode sqlNode;
    try {
        sqlNode = parseQuery(simpleSql);
    } catch (Exception e) {
        // if the sql can't be parsed we wont' be able to validate it
        return false;
    }
    try {
        validator.validate(sqlNode);
    } catch (Exception e) {
        return false;
    }
    return true;
}

19 View Complete Implementation : LiteralOperandTypeChecker.java
Copyright Apache License 2.0
Author : apache
public boolean checkSingleOperandType(SqlCallBinding callBinding, SqlNode node, int iFormalOperand, boolean throwOnFailure) {
    Util.discard(iFormalOperand);
    if (SqlUtil.isNullLiteral(node, true)) {
        if (allowNull) {
            return true;
        }
        if (throwOnFailure) {
            throw callBinding.newError(RESOURCE.argumentMustNotBeNull(callBinding.getOperator().getName()));
        }
        return false;
    }
    if (!SqlUtil.isLiteral(node) && !SqlUtil.isLiteralChain(node)) {
        if (throwOnFailure) {
            throw callBinding.newError(RESOURCE.argumentMustBeLiteral(callBinding.getOperator().getName()));
        }
        return false;
    }
    return true;
}

19 View Complete Implementation : SqlPrettyWriterTest.java
Copyright Apache License 2.0
Author : apache
/**
 * Parses a SQL query. To use a different parser, override this method.
 */
protected SqlNode parseQuery(String sql) {
    SqlNode node;
    try {
        node = SqlParser.create(sql).parseQuery();
    } catch (SqlParseException e) {
        String message = "Received error while parsing SQL '" + sql + "'" + "; error is:\n" + e.toString();
        throw new replacedertionError(message);
    }
    return node;
}

19 View Complete Implementation : SqlValidatorUtil.java
Copyright Apache License 2.0
Author : apache
/**
 * replacedyzes a tuple in a GROUPING SETS clause.
 *
 * <p>For example, in {@code GROUP BY GROUPING SETS ((a, b), a, c)},
 * {@code (a, b)} is a tuple.
 *
 * <p>Gathers into {@code groupExprs} the set of distinct expressions being
 * grouped, and returns a bitmap indicating which expressions this tuple
 * is grouping.
 */
private static List<ImmutableBitSet> replacedyzeGroupTuple(SqlValidatorScope scope, Groupreplacedyzer groupreplacedyzer, List<SqlNode> operandList) {
    List<ImmutableBitSet> list = new ArrayList<>();
    for (SqlNode operand : operandList) {
        list.add(replacedyzeGroupExpr(scope, groupreplacedyzer, operand));
    }
    return list;
}

19 View Complete Implementation : OrderByScope.java
Copyright Apache License 2.0
Author : apache
/**
 * Returns the number of columns in the SELECT clause that have {@code name}
 * as their implicit (e.g. {@code t.name}) or explicit (e.g.
 * {@code t.c as name}) alias.
 */
private int aliasCount(SqlNameMatcher nameMatcher, String name) {
    int n = 0;
    for (SqlNode s : select.getSelectList()) {
        final String alias = SqlValidatorUtil.getAlias(s, -1);
        if (alias != null && nameMatcher.matches(alias, name)) {
            n++;
        }
    }
    return n;
}

19 View Complete Implementation : AggFinder.java
Copyright Apache License 2.0
Author : apache
public SqlCall findAgg(List<SqlNode> nodes) {
    try {
        for (SqlNode node : nodes) {
            node.accept(this);
        }
        return null;
    } catch (Util.FoundOne e) {
        Util.swallow(e, null);
        return (SqlCall) e.getNode();
    }
}

19 View Complete Implementation : SqlParserUtil.java
Copyright Apache License 2.0
Author : apache
/**
 * Converts a list of {expression, operator, expression, ...} into a tree,
 * taking operator precedence and replacedociativity into account.
 */
public static SqlNode toTree(List<Object> list) {
    if (list.size() == 1 && list.get(0) instanceof SqlNode) {
        // Short-cut for the simple common case
        return (SqlNode) list.get(0);
    }
    LOGGER.trace("Attempting to reduce {}", list);
    final OldTokenSequenceImpl tokenSequence = new OldTokenSequenceImpl(list);
    final SqlNode node = toTreeEx(tokenSequence, 0, 0, SqlKind.OTHER);
    LOGGER.debug("Reduced {}", node);
    return node;
}