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);
}
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;
}
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);
}
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);
}
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
}
Aggregations