use of org.apache.calcite.sql.SqlCall in project drill by apache.
the class DrillValidator method validateFrom.
@Override
protected void validateFrom(SqlNode node, RelDataType targetRowType, SqlValidatorScope scope) {
if (node.getKind() == SqlKind.AS) {
SqlCall sqlCall = (SqlCall) node;
SqlNode sqlNode = sqlCall.operand(0);
switch(sqlNode.getKind()) {
case IDENTIFIER:
SqlIdentifier tempNode = (SqlIdentifier) sqlNode;
changeNamesIfTableIsTemporary(tempNode);
replaceAliasWithActualName(tempNode);
// Check the schema and throw a valid SchemaNotFound exception instead of TableNotFound exception.
((DrillCalciteCatalogReader) getCatalogReader()).isValidSchema(tempNode.names);
break;
case UNNEST:
if (sqlCall.operandCount() < 3) {
throw Static.RESOURCE.validationError("Alias table and column name are required for UNNEST").ex();
}
}
}
if (isImpersonationEnabled) {
ImpersonationUtil.getProcessUserUGI().doAs((PrivilegedAction<Void>) () -> {
super.validateFrom(node, targetRowType, scope);
return null;
});
} else {
super.validateFrom(node, targetRowType, scope);
}
}
use of org.apache.calcite.sql.SqlCall in project drill by apache.
the class UnsupportedOperatorsVisitor method detectMultiplePartitions.
/**
* Disable multiple partitions in a SELECT-CLAUSE
* If multiple partitions are defined in the query,
* SqlUnsupportedException would be thrown to inform
* @param sqlSelect SELECT-CLAUSE in the query
*/
private void detectMultiplePartitions(SqlSelect sqlSelect) {
for (SqlNode nodeInSelectList : sqlSelect.getSelectList()) {
// enter the first operand of AS operator
if (nodeInSelectList.getKind() == SqlKind.AS && (((SqlCall) nodeInSelectList).getOperandList().get(0).getKind() == SqlKind.OVER)) {
nodeInSelectList = ((SqlCall) nodeInSelectList).getOperandList().get(0);
}
if (nodeInSelectList.getKind() != SqlKind.OVER) {
continue;
}
// This is used to keep track of the window function which has been defined
SqlNode definedWindow = null;
SqlNode window = ((SqlCall) nodeInSelectList).operand(1);
// which is defined in the window list
if (window instanceof SqlIdentifier) {
// Expand the SqlIdentifier as the expression defined in the window list
for (SqlNode sqlNode : sqlSelect.getWindowList()) {
if (((SqlWindow) sqlNode).getDeclName().equalsDeep(window, Litmus.IGNORE)) {
window = sqlNode;
break;
}
}
assert !(window instanceof SqlIdentifier) : "Identifier should have been expanded as a window defined in the window list";
}
// In a SELECT-SCOPE, only a partition can be defined
if (definedWindow == null) {
definedWindow = window;
} else {
if (!definedWindow.equalsDeep(window, Litmus.IGNORE)) {
unsupportedOperatorCollector.setException(SqlUnsupportedException.ExceptionType.FUNCTION, "Multiple window definitions in a single SELECT list is not currently supported \n" + "See Apache Drill JIRA: DRILL-3196");
throw new UnsupportedOperationException();
}
}
}
}
use of org.apache.calcite.sql.SqlCall in project flink by apache.
the class HiveParserBaseSemanticAnalyzer method getBound.
public static RexWindowBound getBound(HiveParserWindowingSpec.BoundarySpec spec, RelOptCluster cluster) {
RexWindowBound res = null;
if (spec != null) {
SqlParserPos dummyPos = new SqlParserPos(1, 1);
SqlNode amt = spec.getAmt() == 0 || spec.getAmt() == HiveParserWindowingSpec.BoundarySpec.UNBOUNDED_AMOUNT ? null : SqlLiteral.createExactNumeric(String.valueOf(spec.getAmt()), new SqlParserPos(2, 2));
RexNode amtLiteral = amt == null ? null : cluster.getRexBuilder().makeLiteral(spec.getAmt(), cluster.getTypeFactory().createSqlType(SqlTypeName.INTEGER), true);
switch(spec.getDirection()) {
case PRECEDING:
if (amt == null) {
res = RexWindowBound.create(SqlWindow.createUnboundedPreceding(dummyPos), null);
} else {
SqlCall call = (SqlCall) SqlWindow.createPreceding(amt, dummyPos);
res = RexWindowBound.create(call, cluster.getRexBuilder().makeCall(call.getOperator(), amtLiteral));
}
break;
case CURRENT:
res = RexWindowBound.create(SqlWindow.createCurrentRow(dummyPos), null);
break;
case FOLLOWING:
if (amt == null) {
res = RexWindowBound.create(SqlWindow.createUnboundedFollowing(dummyPos), null);
} else {
SqlCall call = (SqlCall) SqlWindow.createFollowing(amt, dummyPos);
res = RexWindowBound.create(call, cluster.getRexBuilder().makeCall(call.getOperator(), amtLiteral));
}
break;
}
}
return res;
}
use of org.apache.calcite.sql.SqlCall in project flink by apache.
the class SqlValidatorImpl method findAllValidFunctionNames.
private static void findAllValidFunctionNames(List<String> names, SqlValidator validator, Collection<SqlMoniker> result, SqlParserPos pos) {
// a function name can only be 1 part
if (names.size() > 1) {
return;
}
for (SqlOperator op : validator.getOperatorTable().getOperatorList()) {
SqlIdentifier curOpId = new SqlIdentifier(op.getName(), pos);
final SqlCall call = validator.makeNullaryCall(curOpId);
if (call != null) {
result.add(new SqlMonikerImpl(op.getName(), SqlMonikerType.FUNCTION));
} else {
if ((op.getSyntax() == SqlSyntax.FUNCTION) || (op.getSyntax() == SqlSyntax.PREFIX)) {
if (op.getOperandTypeChecker() != null) {
String sig = op.getAllowedSignatures();
sig = sig.replace("'", "");
result.add(new SqlMonikerImpl(sig, SqlMonikerType.FUNCTION));
continue;
}
result.add(new SqlMonikerImpl(op.getName(), SqlMonikerType.FUNCTION));
}
}
}
}
use of org.apache.calcite.sql.SqlCall in project flink by apache.
the class SqlValidatorImpl method validateQuery.
public void validateQuery(SqlNode node, SqlValidatorScope scope, RelDataType targetRowType) {
final SqlValidatorNamespace ns = getNamespace(node, scope);
if (node.getKind() == SqlKind.TABLESAMPLE) {
List<SqlNode> operands = ((SqlCall) node).getOperandList();
SqlSampleSpec sampleSpec = SqlLiteral.sampleValue(operands.get(1));
if (sampleSpec instanceof SqlSampleSpec.SqlTableSampleSpec) {
validateFeature(RESOURCE.sQLFeature_T613(), node.getParserPosition());
} else if (sampleSpec instanceof SqlSampleSpec.SqlSubstitutionSampleSpec) {
validateFeature(RESOURCE.sQLFeatureExt_T613_Substitution(), node.getParserPosition());
}
}
validateNamespace(ns, targetRowType);
switch(node.getKind()) {
case EXTEND:
// Until we have a dedicated namespace for EXTEND
deriveType(scope, node);
}
if (node == top) {
validateModality(node);
}
validateAccess(node, ns.getTable(), SqlAccessEnum.SELECT);
validateSnapshot(node, scope, ns);
}
Aggregations