use of org.apache.calcite.sql.validate.SqlQualified in project calcite by apache.
the class SqlToRelConverter method convertIdentifier.
/**
* Converts an identifier into an expression in a given scope. For example,
* the "empno" in "select empno from emp join dept" becomes "emp.empno".
*/
private RexNode convertIdentifier(Blackboard bb, SqlIdentifier identifier) {
// first check for reserved identifiers like CURRENT_USER
final SqlCall call = SqlUtil.makeCall(opTab, identifier);
if (call != null) {
return bb.convertExpression(call);
}
String pv = null;
if (bb.isPatternVarRef && identifier.names.size() > 1) {
pv = identifier.names.get(0);
}
final SqlQualified qualified;
if (bb.scope != null) {
qualified = bb.scope.fullyQualify(identifier);
} else {
qualified = SqlQualified.create(null, 1, null, identifier);
}
final Pair<RexNode, Map<String, Integer>> e0 = bb.lookupExp(qualified);
RexNode e = e0.left;
for (String name : qualified.suffix()) {
if (e == e0.left && e0.right != null) {
int i = e0.right.get(name);
e = rexBuilder.makeFieldAccess(e, i);
} else {
// name already fully-qualified
final boolean caseSensitive = true;
if (identifier.isStar() && bb.scope instanceof MatchRecognizeScope) {
e = rexBuilder.makeFieldAccess(e, 0);
} else {
e = rexBuilder.makeFieldAccess(e, name, caseSensitive);
}
}
}
if (e instanceof RexInputRef) {
// adjust the type to account for nulls introduced by outer joins
e = adjustInputRef(bb, (RexInputRef) e);
if (pv != null) {
e = RexPatternFieldRef.of(pv, (RexInputRef) e);
}
}
if (e0.left instanceof RexCorrelVariable) {
assert e instanceof RexFieldAccess;
final RexNode prev = bb.mapCorrelateToRex.put(((RexCorrelVariable) e0.left).id, (RexFieldAccess) e);
assert prev == null;
}
return e;
}
use of org.apache.calcite.sql.validate.SqlQualified in project calcite by apache.
the class SqlIdentifier method getMonotonicity.
public SqlMonotonicity getMonotonicity(SqlValidatorScope scope) {
// for "star" column, whether it's static or dynamic return not_monotonic directly.
if (Util.last(names).equals("") || DynamicRecordType.isDynamicStarColName(Util.last(names))) {
return SqlMonotonicity.NOT_MONOTONIC;
}
// First check for builtin functions which don't have parentheses,
// like "LOCALTIME".
final SqlValidator validator = scope.getValidator();
SqlCall call = SqlUtil.makeCall(validator.getOperatorTable(), this);
if (call != null) {
return call.getMonotonicity(scope);
}
final SqlQualified qualified = scope.fullyQualify(this);
final SqlIdentifier fqId = qualified.identifier;
return qualified.namespace.resolve().getMonotonicity(Util.last(fqId.names));
}
use of org.apache.calcite.sql.validate.SqlQualified in project hazelcast by hazelcast.
the class HazelcastSqlValidator method extractFieldName.
private String extractFieldName(SqlIdentifier identifier, SelectScope scope) {
SqlCall call = makeNullaryCall(identifier);
if (call != null) {
return null;
}
SqlQualified qualified = scope.fullyQualify(identifier);
List<String> names = qualified.identifier.names;
if (names.size() < 2) {
return null;
}
return Util.last(names);
}
Aggregations