Search in sources :

Example 6 with SqlParserPos

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

the class SqlDdlNodes method renameColumns.

/**
 * Wraps a query to rename its columns. Used by CREATE VIEW and CREATE
 * MATERIALIZED VIEW.
 */
static SqlNode renameColumns(SqlNodeList columnList, SqlNode query) {
    if (columnList == null) {
        return query;
    }
    final SqlParserPos p = query.getParserPosition();
    final SqlNodeList selectList = new SqlNodeList(ImmutableList.<SqlNode>of(SqlIdentifier.star(p)), p);
    final SqlCall from = SqlStdOperatorTable.AS.createCall(p, ImmutableList.<SqlNode>builder().add(query).add(new SqlIdentifier("_", p)).addAll(columnList).build());
    return new SqlSelect(p, null, selectList, from, null, null, null, null, null, null, null);
}
Also used : SqlSelect(org.apache.calcite.sql.SqlSelect) SqlParserPos(org.apache.calcite.sql.parser.SqlParserPos) SqlCall(org.apache.calcite.sql.SqlCall) SqlNodeList(org.apache.calcite.sql.SqlNodeList) SqlIdentifier(org.apache.calcite.sql.SqlIdentifier)

Example 7 with SqlParserPos

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

the class IdentifierNamespace method validateImpl.

public RelDataType validateImpl(RelDataType targetRowType) {
    resolvedNamespace = Preconditions.checkNotNull(resolveImpl(id));
    if (resolvedNamespace instanceof TableNamespace) {
        SqlValidatorTable table = resolvedNamespace.getTable();
        if (validator.shouldExpandIdentifiers()) {
            // TODO:  expand qualifiers for column references also
            List<String> qualifiedNames = table.getQualifiedName();
            if (qualifiedNames != null) {
                // Assign positions to the components of the fully-qualified
                // identifier, as best we can. We assume that qualification
                // adds names to the front, e.g. FOO.BAR becomes BAZ.FOO.BAR.
                List<SqlParserPos> poses = new ArrayList<>(Collections.nCopies(qualifiedNames.size(), id.getParserPosition()));
                int offset = qualifiedNames.size() - id.names.size();
                // reader.
                if (offset >= 0) {
                    for (int i = 0; i < id.names.size(); i++) {
                        poses.set(i + offset, id.getComponentParserPosition(i));
                    }
                }
                id.setNames(qualifiedNames, poses);
            }
        }
    }
    RelDataType rowType = resolvedNamespace.getRowType();
    if (extendList != null) {
        if (!(resolvedNamespace instanceof TableNamespace)) {
            throw new RuntimeException("cannot convert");
        }
        resolvedNamespace = ((TableNamespace) resolvedNamespace).extend(extendList);
        rowType = resolvedNamespace.getRowType();
    }
    // Build a list of monotonic expressions.
    final ImmutableList.Builder<Pair<SqlNode, SqlMonotonicity>> builder = ImmutableList.builder();
    List<RelDataTypeField> fields = rowType.getFieldList();
    for (RelDataTypeField field : fields) {
        final String fieldName = field.getName();
        final SqlMonotonicity monotonicity = resolvedNamespace.getMonotonicity(fieldName);
        if (monotonicity != SqlMonotonicity.NOT_MONOTONIC) {
            builder.add(Pair.of((SqlNode) new SqlIdentifier(fieldName, SqlParserPos.ZERO), monotonicity));
        }
    }
    monotonicExprs = builder.build();
    // Validation successful.
    return rowType;
}
Also used : SqlParserPos(org.apache.calcite.sql.parser.SqlParserPos) ImmutableList(com.google.common.collect.ImmutableList) ArrayList(java.util.ArrayList) RelDataType(org.apache.calcite.rel.type.RelDataType) SqlIdentifier(org.apache.calcite.sql.SqlIdentifier) RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) Pair(org.apache.calcite.util.Pair) SqlNode(org.apache.calcite.sql.SqlNode)

Example 8 with SqlParserPos

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

the class SqlIdentifier method plus.

/**
 * Creates an identifier that consists of this identifier plus a name segment.
 * Does not modify this identifier.
 */
public SqlIdentifier plus(String name, SqlParserPos pos) {
    final ImmutableList<String> names = ImmutableList.<String>builder().addAll(this.names).add(name).build();
    final ImmutableList<SqlParserPos> componentPositions;
    final SqlParserPos pos2;
    if (this.componentPositions != null) {
        final ImmutableList.Builder<SqlParserPos> builder = ImmutableList.builder();
        componentPositions = builder.addAll(this.componentPositions).add(pos).build();
        pos2 = SqlParserPos.sum(builder.add(this.pos).build());
    } else {
        componentPositions = null;
        pos2 = pos;
    }
    return new SqlIdentifier(names, collation, pos2, componentPositions);
}
Also used : SqlParserPos(org.apache.calcite.sql.parser.SqlParserPos) ImmutableList(com.google.common.collect.ImmutableList)

Example 9 with SqlParserPos

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

the class SqlIdentifier method getComponent.

public SqlIdentifier getComponent(int from, int to) {
    final SqlParserPos pos;
    final ImmutableList<SqlParserPos> pos2;
    if (componentPositions == null) {
        pos2 = null;
        pos = this.pos;
    } else {
        pos2 = componentPositions.subList(from, to);
        pos = SqlParserPos.sum(pos2);
    }
    return new SqlIdentifier(names.subList(from, to), collation, pos, pos2);
}
Also used : SqlParserPos(org.apache.calcite.sql.parser.SqlParserPos)

Example 10 with SqlParserPos

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

the class SqlCall method findValidOptions.

public void findValidOptions(SqlValidator validator, SqlValidatorScope scope, SqlParserPos pos, Collection<SqlMoniker> hintList) {
    for (SqlNode operand : getOperandList()) {
        if (operand instanceof SqlIdentifier) {
            SqlIdentifier id = (SqlIdentifier) operand;
            SqlParserPos idPos = id.getParserPosition();
            if (idPos.toString().equals(pos.toString())) {
                ((SqlValidatorImpl) validator).lookupNameCompletionHints(scope, id.names, pos, hintList);
                return;
            }
        }
    }
// no valid options
}
Also used : SqlValidatorImpl(org.apache.calcite.sql.validate.SqlValidatorImpl) SqlParserPos(org.apache.calcite.sql.parser.SqlParserPos)

Aggregations

SqlParserPos (org.apache.calcite.sql.parser.SqlParserPos)42 SqlNode (org.apache.calcite.sql.SqlNode)17 SqlIntervalQualifier (org.apache.calcite.sql.SqlIntervalQualifier)11 RelDataType (org.apache.calcite.rel.type.RelDataType)9 SqlIdentifier (org.apache.calcite.sql.SqlIdentifier)9 BigDecimal (java.math.BigDecimal)8 HiveIntervalDayTime (org.apache.hadoop.hive.common.type.HiveIntervalDayTime)6 SqlCall (org.apache.calcite.sql.SqlCall)5 ArrayList (java.util.ArrayList)4 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)4 SqlNodeList (org.apache.calcite.sql.SqlNodeList)4 ImmutableList (com.google.common.collect.ImmutableList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 RexNode (org.apache.calcite.rex.RexNode)3 SqlNumericLiteral (org.apache.calcite.sql.SqlNumericLiteral)3 SqlOperator (org.apache.calcite.sql.SqlOperator)3 Calendar (java.util.Calendar)2 IdentityHashMap (java.util.IdentityHashMap)2 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)2