use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlNode in project calcite by apache.
the class SqlValidatorImpl method validate.
public SqlNode validate(SqlNode topNode) {
SqlValidatorScope scope = new EmptyScope(this);
scope = new CatalogScope(scope, ImmutableList.of("CATALOG"));
final SqlNode topNode2 = validateScopedExpression(topNode, scope);
final RelDataType type = getValidatedNodeType(topNode2);
Util.discard(type);
return topNode2;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlNode in project calcite by apache.
the class SqlValidatorImpl method createTargetRowType.
/**
* Derives a row-type for INSERT and UPDATE operations.
*
* @param table Target table for INSERT/UPDATE
* @param targetColumnList List of target columns, or null if not specified
* @param append Whether to append fields to those in <code>
* baseRowType</code>
* @return Rowtype
*/
protected RelDataType createTargetRowType(SqlValidatorTable table, SqlNodeList targetColumnList, boolean append) {
RelDataType baseRowType = table.getRowType();
if (targetColumnList == null) {
return baseRowType;
}
List<RelDataTypeField> targetFields = baseRowType.getFieldList();
final List<Map.Entry<String, RelDataType>> types = new ArrayList<>();
if (append) {
for (RelDataTypeField targetField : targetFields) {
types.add(Pair.of(SqlUtil.deriveAliasFromOrdinal(types.size()), targetField.getType()));
}
}
final Set<Integer> assignedFields = new HashSet<>();
final RelOptTable relOptTable = table instanceof RelOptTable ? ((RelOptTable) table) : null;
for (SqlNode node : targetColumnList) {
SqlIdentifier id = (SqlIdentifier) node;
RelDataTypeField targetField = SqlValidatorUtil.getTargetField(baseRowType, typeFactory, id, catalogReader, relOptTable);
if (targetField == null) {
throw newValidationError(id, RESOURCE.unknownTargetColumn(id.toString()));
}
if (!assignedFields.add(targetField.getIndex())) {
throw newValidationError(id, RESOURCE.duplicateTargetColumn(targetField.getName()));
}
types.add(targetField);
}
return typeFactory.createStructType(types);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlNode in project calcite by apache.
the class SqlValidatorImpl method navigationInMeasure.
private SqlNode navigationInMeasure(SqlNode node, boolean allRows) {
final Set<String> prefix = node.accept(new PatternValidator(true));
Util.discard(prefix);
final List<SqlNode> ops = ((SqlCall) node).getOperandList();
final SqlOperator defaultOp = allRows ? SqlStdOperatorTable.RUNNING : SqlStdOperatorTable.FINAL;
final SqlNode op0 = ops.get(0);
if (!isRunningOrFinal(op0.getKind()) || !allRows && op0.getKind() == SqlKind.RUNNING) {
SqlNode newNode = defaultOp.createCall(SqlParserPos.ZERO, op0);
node = SqlStdOperatorTable.AS.createCall(SqlParserPos.ZERO, newNode, ops.get(1));
}
node = new NavigationExpander().go(node);
return node;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlNode in project calcite by apache.
the class SqlValidatorImpl method validateDefinitions.
private void validateDefinitions(SqlMatchRecognize mr, MatchRecognizeScope scope) {
final Set<String> aliases = catalogReader.nameMatcher().isCaseSensitive() ? new LinkedHashSet<String>() : new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
for (SqlNode item : mr.getPatternDefList().getList()) {
final String alias = alias(item);
if (!aliases.add(alias)) {
throw newValidationError(item, Static.RESOURCE.patternVarAlreadyDefined(alias));
}
scope.addPatternVar(alias);
}
final List<SqlNode> sqlNodes = new ArrayList<>();
for (SqlNode item : mr.getPatternDefList().getList()) {
final String alias = alias(item);
SqlNode expand = expand(item, scope);
expand = navigationInDefine(expand, alias);
setOriginal(expand, item);
inferUnknownTypes(booleanType, scope, expand);
expand.validate(this, scope);
// Some extra work need required here.
// In PREV, NEXT, FINAL and LAST, only one pattern variable is allowed.
sqlNodes.add(SqlStdOperatorTable.AS.createCall(SqlParserPos.ZERO, expand, new SqlIdentifier(alias, SqlParserPos.ZERO)));
final RelDataType type = deriveType(scope, expand);
if (!SqlTypeUtil.inBooleanFamily(type)) {
throw newValidationError(expand, RESOURCE.condMustBeBoolean("DEFINE"));
}
setValidatedNodeType(item, type);
}
SqlNodeList list = new SqlNodeList(sqlNodes, mr.getPatternDefList().getParserPosition());
inferUnknownTypes(unknownType, scope, list);
for (SqlNode node : list) {
validateExpr(node, scope);
}
mr.setOperand(SqlMatchRecognize.OPERAND_PATTERN_DEFINES, list);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlNode in project calcite 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);
Preconditions.checkNotNull(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);
}
}
Aggregations