use of org.apache.calcite.sql.SqlIdentifier in project drill by apache.
the class DrillCompoundIdentifier method getAsSqlNode.
public SqlNode getAsSqlNode() {
if (ids.size() == 1) {
return new SqlIdentifier(Collections.singletonList(ids.get(0).value), ids.get(0).parserPos);
}
int startIndex;
SqlNode node;
if (ids.get(1).isArray()) {
// handle everything post zero index as item operator.
startIndex = 1;
node = new //
SqlIdentifier(//
ImmutableList.of(ids.get(0).value), //
null, //
ids.get(0).parserPos, ImmutableList.of(ids.get(0).parserPos));
} else {
// handle everything post two index as item operator.
startIndex = 2;
node = new //
SqlIdentifier(//
ImmutableList.of(ids.get(0).value, ids.get(1).value), //
null, //
ids.get(0).parserPos, ImmutableList.of(ids.get(0).parserPos, ids.get(1).parserPos));
}
for (int i = startIndex; i < ids.size(); i++) {
node = ids.get(i).getNode(node);
}
return node;
}
use of org.apache.calcite.sql.SqlIdentifier in project calcite by apache.
the class SqlSequenceValueOperator method validateCall.
@Override
public void validateCall(SqlCall call, SqlValidator validator, SqlValidatorScope scope, SqlValidatorScope operandScope) {
List<SqlNode> operands = call.getOperandList();
assert operands.size() == 1;
assert operands.get(0) instanceof SqlIdentifier;
SqlIdentifier id = (SqlIdentifier) operands.get(0);
validator.validateSequenceValue(scope, id);
}
use of org.apache.calcite.sql.SqlIdentifier in project calcite by apache.
the class SqlOperatorBaseTest method testSqlOperatorOverloading.
@Test
public void testSqlOperatorOverloading() {
final SqlStdOperatorTable operatorTable = SqlStdOperatorTable.instance();
for (SqlOperator sqlOperator : operatorTable.getOperatorList()) {
String operatorName = sqlOperator.getName();
List<SqlOperator> routines = new ArrayList<>();
operatorTable.lookupOperatorOverloads(new SqlIdentifier(operatorName, SqlParserPos.ZERO), null, sqlOperator.getSyntax(), routines);
Iterator<SqlOperator> iter = routines.iterator();
while (iter.hasNext()) {
SqlOperator operator = iter.next();
if (!sqlOperator.getClass().isInstance(operator)) {
iter.remove();
}
}
assertThat(routines.size(), equalTo(1));
assertThat(sqlOperator, equalTo(routines.get(0)));
}
}
use of org.apache.calcite.sql.SqlIdentifier in project calcite by apache.
the class SqlCreateTable method execute.
public void execute(CalcitePrepare.Context context) {
final List<String> path = context.getDefaultSchemaPath();
CalciteSchema schema = context.getRootSchema();
for (String p : path) {
schema = schema.getSubSchema(p, true);
}
final JavaTypeFactory typeFactory = new JavaTypeFactoryImpl();
final RelDataTypeFactory.Builder builder = typeFactory.builder();
for (Pair<SqlIdentifier, SqlDataTypeSpec> pair : nameTypes()) {
builder.add(pair.left.getSimple(), pair.right.deriveType(typeFactory, true));
}
final RelDataType rowType = builder.build();
schema.add(name.getSimple(), new MutableArrayTable(name.getSimple(), RelDataTypeImpl.proto(rowType)));
}
use of org.apache.calcite.sql.SqlIdentifier in project calcite by apache.
the class RelToSqlConverter method visit.
/**
* @see #dispatch
*/
public Result visit(Values e) {
final List<Clause> clauses = ImmutableList.of(Clause.SELECT);
final Map<String, RelDataType> pairs = ImmutableMap.of();
final Context context = aliasContext(pairs, false);
SqlNode query;
final boolean rename = stack.size() <= 1 || !(Iterables.get(stack, 1).r instanceof TableModify);
final List<String> fieldNames = e.getRowType().getFieldNames();
if (!dialect.supportsAliasedValues() && rename) {
// Oracle does not support "AS t (c1, c2)". So instead of
// (VALUES (v0, v1), (v2, v3)) AS t (c0, c1)
// we generate
// SELECT v0 AS c0, v1 AS c1 FROM DUAL
// UNION ALL
// SELECT v2 AS c0, v3 AS c1 FROM DUAL
List<SqlSelect> list = new ArrayList<>();
for (List<RexLiteral> tuple : e.getTuples()) {
final List<SqlNode> values2 = new ArrayList<>();
final SqlNodeList exprList = exprList(context, tuple);
for (Pair<SqlNode, String> value : Pair.zip(exprList, fieldNames)) {
values2.add(SqlStdOperatorTable.AS.createCall(POS, value.left, new SqlIdentifier(value.right, POS)));
}
list.add(new SqlSelect(POS, null, new SqlNodeList(values2, POS), new SqlIdentifier("DUAL", POS), null, null, null, null, null, null, null));
}
if (list.size() == 1) {
query = list.get(0);
} else {
query = SqlStdOperatorTable.UNION_ALL.createCall(new SqlNodeList(list, POS));
}
} else {
// Generate ANSI syntax
// (VALUES (v0, v1), (v2, v3))
// or, if rename is required
// (VALUES (v0, v1), (v2, v3)) AS t (c0, c1)
final SqlNodeList selects = new SqlNodeList(POS);
for (List<RexLiteral> tuple : e.getTuples()) {
selects.add(ANONYMOUS_ROW.createCall(exprList(context, tuple)));
}
query = SqlStdOperatorTable.VALUES.createCall(selects);
if (rename) {
final List<SqlNode> list = new ArrayList<>();
list.add(query);
list.add(new SqlIdentifier("t", POS));
for (String fieldName : fieldNames) {
list.add(new SqlIdentifier(fieldName, POS));
}
query = SqlStdOperatorTable.AS.createCall(POS, list);
}
}
return result(query, clauses, e, null);
}
Aggregations