Search in sources :

Example 96 with SqlNode

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlNode in project calcite by apache.

the class PlannerImpl method parse.

public SqlNode parse(final String sql) throws SqlParseException {
    switch(state) {
        case STATE_0_CLOSED:
        case STATE_1_RESET:
            ready();
    }
    ensure(State.STATE_2_READY);
    SqlParser parser = SqlParser.create(sql, parserConfig);
    SqlNode sqlNode = parser.parseStmt();
    state = State.STATE_3_PARSED;
    return sqlNode;
}
Also used : SqlParser(org.apache.calcite.sql.parser.SqlParser) SqlNode(org.apache.calcite.sql.SqlNode)

Example 97 with SqlNode

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlNode in project calcite by apache.

the class SqlTypeUtil method makeNullableIfOperandsAre.

/**
 * Recreates a given RelDataType with nullability iff any of the operands
 * of a call are nullable.
 */
public static RelDataType makeNullableIfOperandsAre(final SqlValidator validator, final SqlValidatorScope scope, final SqlCall call, RelDataType type) {
    for (SqlNode operand : call.getOperandList()) {
        RelDataType operandType = validator.deriveType(scope, operand);
        if (containsNullable(operandType)) {
            RelDataTypeFactory typeFactory = validator.getTypeFactory();
            type = typeFactory.createTypeWithNullability(type, true);
            break;
        }
    }
    return type;
}
Also used : RelDataTypeFactory(org.apache.calcite.rel.type.RelDataTypeFactory) RelDataType(org.apache.calcite.rel.type.RelDataType) SqlNode(org.apache.calcite.sql.SqlNode)

Example 98 with SqlNode

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlNode in project calcite by apache.

the class AggChecker method visit.

public Void visit(SqlIdentifier id) {
    if (isGroupExpr(id) || id.isStar()) {
        // Star may validly occur in "SELECT COUNT(*) OVER w"
        return null;
    }
    // Is it a call to a parentheses-free function?
    SqlCall call = SqlUtil.makeCall(validator.getOperatorTable(), id);
    if (call != null) {
        return call.accept(this);
    }
    // Didn't find the identifier in the group-by list as is, now find
    // it fully-qualified.
    // TODO: It would be better if we always compared fully-qualified
    // to fully-qualified.
    final SqlQualified fqId = scopes.peek().fullyQualify(id);
    if (isGroupExpr(fqId.identifier)) {
        return null;
    }
    SqlNode originalExpr = validator.getOriginal(id);
    final String exprString = originalExpr.toString();
    throw validator.newValidationError(originalExpr, distinct ? RESOURCE.notSelectDistinctExpr(exprString) : RESOURCE.notGroupExpr(exprString));
}
Also used : SqlCall(org.apache.calcite.sql.SqlCall) SqlNode(org.apache.calcite.sql.SqlNode)

Example 99 with SqlNode

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlNode in project calcite by apache.

the class AggregatingSelectScope method resolve.

// ~ Methods ----------------------------------------------------------------
private Resolved resolve() {
    final ImmutableList.Builder<ImmutableList<ImmutableBitSet>> builder = ImmutableList.builder();
    List<SqlNode> extraExprs = ImmutableList.of();
    Map<Integer, Integer> groupExprProjection = ImmutableMap.of();
    if (select.getGroup() != null) {
        final SqlNodeList groupList = select.getGroup();
        final SqlValidatorUtil.GroupAnalyzer groupAnalyzer = new SqlValidatorUtil.GroupAnalyzer(temporaryGroupExprList);
        for (SqlNode groupExpr : groupList) {
            SqlValidatorUtil.analyzeGroupItem(this, groupAnalyzer, builder, groupExpr);
        }
        extraExprs = groupAnalyzer.extraExprs;
        groupExprProjection = groupAnalyzer.groupExprProjection;
    }
    final Set<ImmutableBitSet> flatGroupSets = Sets.newTreeSet(ImmutableBitSet.COMPARATOR);
    for (List<ImmutableBitSet> groupSet : Linq4j.product(builder.build())) {
        flatGroupSets.add(ImmutableBitSet.union(groupSet));
    }
    // For GROUP BY (), we need a singleton grouping set.
    if (flatGroupSets.isEmpty()) {
        flatGroupSets.add(ImmutableBitSet.of());
    }
    return new Resolved(extraExprs, temporaryGroupExprList, flatGroupSets, groupExprProjection);
}
Also used : ImmutableBitSet(org.apache.calcite.util.ImmutableBitSet) ImmutableList(com.google.common.collect.ImmutableList) SqlNodeList(org.apache.calcite.sql.SqlNodeList) SqlNode(org.apache.calcite.sql.SqlNode)

Example 100 with SqlNode

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlNode in project calcite by apache.

the class GroupByScope method validateExpr.

public void validateExpr(SqlNode expr) {
    SqlNode expanded = validator.expandGroupByOrHavingExpr(expr, this, select, false);
    // expression needs to be valid in parent scope too
    parent.validateExpr(expanded);
}
Also used : SqlNode(org.apache.calcite.sql.SqlNode)

Aggregations

SqlNode (org.apache.calcite.sql.SqlNode)510 RelDataType (org.apache.calcite.rel.type.RelDataType)141 SqlNodeList (org.apache.calcite.sql.SqlNodeList)98 SqlIdentifier (org.apache.calcite.sql.SqlIdentifier)84 SqlCall (org.apache.calcite.sql.SqlCall)81 ArrayList (java.util.ArrayList)78 RelNode (org.apache.calcite.rel.RelNode)60 Test (org.junit.Test)59 BitString (org.apache.calcite.util.BitString)46 SqlSelect (org.apache.calcite.sql.SqlSelect)45 SqlWriter (org.apache.calcite.sql.SqlWriter)42 RexNode (org.apache.calcite.rex.RexNode)40 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)33 RelOptPlanner (org.apache.calcite.plan.RelOptPlanner)25 SqlLiteral (org.apache.calcite.sql.SqlLiteral)23 SqlOperator (org.apache.calcite.sql.SqlOperator)23 SqlParserPos (org.apache.calcite.sql.parser.SqlParserPos)22 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)21 ImmutableList (com.google.common.collect.ImmutableList)20 SqlValidator (org.apache.calcite.sql.validate.SqlValidator)20