use of org.apache.calcite.sql.SqlNodeList in project flink by apache.
the class SqlValidatorImpl method createSourceSelectForDelete.
/**
* Creates the SELECT statement that putatively feeds rows into a DELETE statement to be
* deleted.
*
* @param call Call to the DELETE operator
* @return select statement
*/
protected SqlSelect createSourceSelectForDelete(SqlDelete call) {
final SqlNodeList selectList = new SqlNodeList(SqlParserPos.ZERO);
selectList.add(SqlIdentifier.star(SqlParserPos.ZERO));
SqlNode sourceTable = call.getTargetTable();
if (call.getAlias() != null) {
sourceTable = SqlValidatorUtil.addAlias(sourceTable, call.getAlias().getSimple());
}
return new SqlSelect(SqlParserPos.ZERO, null, selectList, sourceTable, call.getCondition(), null, null, null, null, null, null, null);
}
use of org.apache.calcite.sql.SqlNodeList in project flink by apache.
the class SqlValidatorImpl method createSourceSelectForUpdate.
/**
* Creates the SELECT statement that putatively feeds rows into an UPDATE statement to be
* updated.
*
* @param call Call to the UPDATE operator
* @return select statement
*/
protected SqlSelect createSourceSelectForUpdate(SqlUpdate call) {
final SqlNodeList selectList = new SqlNodeList(SqlParserPos.ZERO);
selectList.add(SqlIdentifier.star(SqlParserPos.ZERO));
int ordinal = 0;
for (SqlNode exp : call.getSourceExpressionList()) {
// Force unique aliases to avoid a duplicate for Y with
// SET X=Y
String alias = SqlUtil.deriveAliasFromOrdinal(ordinal);
selectList.add(SqlValidatorUtil.addAlias(exp, alias));
++ordinal;
}
SqlNode sourceTable = call.getTargetTable();
if (call.getAlias() != null) {
sourceTable = SqlValidatorUtil.addAlias(sourceTable, call.getAlias().getSimple());
}
return new SqlSelect(SqlParserPos.ZERO, null, selectList, sourceTable, call.getCondition(), null, null, null, null, null, null, null);
}
use of org.apache.calcite.sql.SqlNodeList in project flink by apache.
the class SqlValidatorImpl method validateOrderList.
/**
* Validates the ORDER BY clause of a SELECT statement.
*
* @param select Select statement
*/
protected void validateOrderList(SqlSelect select) {
// ORDER BY is validated in a scope where aliases in the SELECT clause
// are visible. For example, "SELECT empno AS x FROM emp ORDER BY x"
// is valid.
SqlNodeList orderList = select.getOrderList();
if (orderList == null) {
return;
}
if (!shouldAllowIntermediateOrderBy()) {
if (!cursorSet.contains(select)) {
throw newValidationError(select, RESOURCE.invalidOrderByPos());
}
}
final SqlValidatorScope orderScope = getOrderScope(select);
Objects.requireNonNull(orderScope);
List<SqlNode> expandList = new ArrayList<>();
for (SqlNode orderItem : orderList) {
SqlNode expandedOrderItem = expand(orderItem, orderScope);
expandList.add(expandedOrderItem);
}
SqlNodeList expandedOrderList = new SqlNodeList(expandList, orderList.getParserPosition());
select.setOrderBy(expandedOrderList);
for (SqlNode orderItem : expandedOrderList) {
validateOrderItem(select, orderItem);
}
}
use of org.apache.calcite.sql.SqlNodeList in project flink by apache.
the class SqlToOperationConverter method convertCreateView.
/**
* Convert CREATE VIEW statement.
*/
private Operation convertCreateView(SqlCreateView sqlCreateView) {
final SqlNode query = sqlCreateView.getQuery();
final SqlNodeList fieldList = sqlCreateView.getFieldList();
UnresolvedIdentifier unresolvedIdentifier = UnresolvedIdentifier.of(sqlCreateView.fullViewName());
ObjectIdentifier identifier = catalogManager.qualifyIdentifier(unresolvedIdentifier);
String comment = sqlCreateView.getComment().map(c -> c.getNlsString().getValue()).orElse(null);
CatalogView catalogView = convertViewQuery(query, fieldList.getList(), OperationConverterUtils.extractProperties(sqlCreateView.getProperties().orElse(null)), comment);
return new CreateViewOperation(identifier, catalogView, sqlCreateView.isIfNotExists(), sqlCreateView.isTemporary());
}
use of org.apache.calcite.sql.SqlNodeList in project flink by apache.
the class ParserImpl method parse.
/**
* When parsing statement, it first uses {@link ExtendedParser} to parse statements. If {@link
* ExtendedParser} fails to parse statement, it uses the {@link CalciteParser} to parse
* statements.
*
* @param statement input statement.
* @return parsed operations.
*/
@Override
public List<Operation> parse(String statement) {
CalciteParser parser = calciteParserSupplier.get();
FlinkPlannerImpl planner = validatorSupplier.get();
Optional<Operation> command = EXTENDED_PARSER.parse(statement);
if (command.isPresent()) {
return Collections.singletonList(command.get());
}
// parse the sql query
// use parseSqlList here because we need to support statement end with ';' in sql client.
SqlNodeList sqlNodeList = parser.parseSqlList(statement);
List<SqlNode> parsed = sqlNodeList.getList();
Preconditions.checkArgument(parsed.size() == 1, "only single statement supported");
return Collections.singletonList(SqlToOperationConverter.convert(planner, catalogManager, parsed.get(0)).orElseThrow(() -> new TableException("Unsupported query: " + statement)));
}
Aggregations