use of org.apache.calcite.sql.SqlNodeList in project calcite by apache.
the class SqlShuttle method visit.
public SqlNode visit(SqlNodeList nodeList) {
boolean update = false;
List<SqlNode> exprs = nodeList.getList();
int exprCount = exprs.size();
List<SqlNode> newList = new ArrayList<SqlNode>(exprCount);
for (SqlNode operand : exprs) {
SqlNode clonedOperand;
if (operand == null) {
clonedOperand = null;
} else {
clonedOperand = operand.accept(this);
if (clonedOperand != operand) {
update = true;
}
}
newList.add(clonedOperand);
}
if (update) {
return new SqlNodeList(newList, nodeList.getParserPosition());
} else {
return nodeList;
}
}
use of org.apache.calcite.sql.SqlNodeList in project calcite by apache.
the class AggChecker method visit.
public Void visit(SqlCall call) {
final SqlValidatorScope scope = scopes.peek();
if (call.getOperator().isAggregator()) {
if (distinct) {
if (scope instanceof AggregatingSelectScope) {
SqlNodeList selectList = ((SqlSelect) scope.getNode()).getSelectList();
// Check if this aggregation function is just an element in the select
for (SqlNode sqlNode : selectList) {
if (sqlNode.getKind() == SqlKind.AS) {
sqlNode = ((SqlCall) sqlNode).operand(0);
}
if (validator.expand(sqlNode, scope).equalsDeep(call, Litmus.IGNORE)) {
return null;
}
}
}
// Cannot use agg fun in ORDER BY clause if have SELECT DISTINCT.
SqlNode originalExpr = validator.getOriginal(call);
final String exprString = originalExpr.toString();
throw validator.newValidationError(call, RESOURCE.notSelectDistinctExpr(exprString));
}
// BY deptno'
return null;
}
if (call.getKind() == SqlKind.FILTER) {
call.operand(0).accept(this);
return null;
}
// Visit the operand in window function
if (call.getKind() == SqlKind.OVER) {
for (SqlNode operand : call.<SqlCall>operand(0).getOperandList()) {
operand.accept(this);
}
// Check the OVER clause
final SqlNode over = call.operand(1);
if (over instanceof SqlCall) {
over.accept(this);
} else if (over instanceof SqlIdentifier) {
// Check the corresponding SqlWindow in WINDOW clause
final SqlWindow window = scope.lookupWindow(((SqlIdentifier) over).getSimple());
window.getPartitionList().accept(this);
window.getOrderList().accept(this);
}
}
if (isGroupExpr(call)) {
// This call matches an expression in the GROUP BY clause.
return null;
}
final SqlCall groupCall = SqlStdOperatorTable.convertAuxiliaryToGroupCall(call);
if (groupCall != null) {
if (isGroupExpr(groupCall)) {
// TUMBLE(rowtime, INTERVAL '1' HOUR')
return null;
}
throw validator.newValidationError(groupCall, RESOURCE.auxiliaryWithoutMatchingGroupCall(call.getOperator().getName(), groupCall.getOperator().getName()));
}
if (call.isA(SqlKind.QUERY)) {
// references to forbidden columns.
return null;
}
// Switch to new scope.
SqlValidatorScope newScope = scope.getOperandScope(call);
scopes.push(newScope);
// Visit the operands (only expressions).
call.getOperator().acceptCall(this, call, true, ArgHandlerImpl.<Void>instance());
// Restore scope.
scopes.pop();
return null;
}
use of org.apache.calcite.sql.SqlNodeList in project flink by apache.
the class SqlAddHivePartitions method toProps.
private static List<SqlNodeList> toProps(List<SqlCharStringLiteral> partLocations) {
List<SqlNodeList> res = new ArrayList<>(partLocations.size());
for (SqlCharStringLiteral partLocation : partLocations) {
SqlNodeList prop = null;
if (partLocation != null) {
prop = new SqlNodeList(partLocation.getParserPosition());
prop.add(HiveDDLUtils.toTableOption(SqlCreateHiveTable.TABLE_LOCATION_URI, partLocation, partLocation.getParserPosition()));
}
res.add(prop);
}
return res;
}
use of org.apache.calcite.sql.SqlNodeList in project flink by apache.
the class SqlAlterHiveTableAddReplaceColumn method unparse.
@Override
public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
writer.keyword("ALTER TABLE");
tableIdentifier.unparse(writer, leftPrec, rightPrec);
SqlNodeList partitionSpec = getPartitionSpec();
if (partitionSpec != null && partitionSpec.size() > 0) {
writer.keyword("PARTITION");
partitionSpec.unparse(writer, getOperator().getLeftPrec(), getOperator().getRightPrec());
}
if (isReplace()) {
writer.keyword("REPLACE");
} else {
writer.keyword("ADD");
}
writer.keyword("COLUMNS");
SqlWriter.Frame frame = writer.startList(SqlWriter.FrameTypeEnum.create("sds"), "(", ")");
for (SqlNode column : origColumns) {
printIndent(writer);
column.unparse(writer, leftPrec, rightPrec);
}
writer.newlineAndIndent();
writer.endList(frame);
if (cascade) {
writer.keyword("CASCADE");
} else {
writer.keyword("RESTRICT");
}
}
use of org.apache.calcite.sql.SqlNodeList in project flink by apache.
the class SqlAlterHiveTableFileFormat method createPropList.
private static SqlNodeList createPropList(SqlIdentifier format) {
SqlNodeList res = new SqlNodeList(format.getParserPosition());
res.add(HiveDDLUtils.toTableOption(SqlCreateHiveTable.HiveTableStoredAs.STORED_AS_FILE_FORMAT, format.getSimple(), format.getParserPosition()));
return res;
}
Aggregations