/** * Validates a namespace. * * @param namespace Namespace * @param targetRowType Desired row type, must not be null, may be the data * type 'unknown'. */ protected void validateNamespace(final SqlValidatorNamespace namespace, RelDataType targetRowType) { namespace.validate(targetRowType); if (namespace.getNode() != null) { setValidatedNodeType(namespace.getNode(), namespace.getType()); } }
public void validateUpdate(SqlUpdate call) { final SqlValidatorNamespace targetNamespace = getNamespace(call); validateNamespace(targetNamespace, unknownType); final RelOptTable relOptTable = SqlValidatorUtil.getRelOptTable( targetNamespace, catalogReader.unwrap(Prepare.CatalogReader.class), null, null); final SqlValidatorTable table = relOptTable == null ? targetNamespace.getTable() : relOptTable.unwrap(SqlValidatorTable.class); final RelDataType targetRowType = createTargetRowType( table, call.getTargetColumnList(), true); final SqlSelect select = call.getSourceSelect(); validateSelect(select, targetRowType); final RelDataType sourceRowType = getNamespace(call).getRowType(); checkTypeAssignment(sourceRowType, targetRowType, call); checkConstraint(table, call, targetRowType); validateAccess(call.getTargetTable(), table, SqlAccessEnum.UPDATE); }
Collection<SqlMoniker> hintList) { final SqlValidatorNamespace ns = getNamespace(node); if (ns.isWrapperFor(IdentifierNamespace.class)) { IdentifierNamespace idNs = ns.unwrap(IdentifierNamespace.class); final SqlIdentifier id = idNs.getId(); for (int i = 0; i < id.names.size(); i++) {
scope.fullyQualify((SqlIdentifier) selectItem); SqlValidatorNamespace namespace = qualified.namespace; final SqlValidatorTable table = namespace.getTable(); if (table == null) { return null; new ArrayList<>(table.getQualifiedName()); for (String name : qualified.suffix()) { namespace = namespace.lookupChild(name); if (namespace == null) { return null;
protected RelOptTable getTargetTable(SqlNode call) { final SqlValidatorNamespace targetNs = validator.getNamespace(call); if (targetNs.isWrapperFor(SqlValidatorImpl.DmlNamespace.class)) { final SqlValidatorImpl.DmlNamespace dmlNamespace = targetNs.unwrap(SqlValidatorImpl.DmlNamespace.class); return SqlValidatorUtil.getRelOptTable(dmlNamespace, catalogReader, null, null); } final SqlValidatorNamespace resolvedNamespace = targetNs.resolve(); return SqlValidatorUtil.getRelOptTable(resolvedNamespace, catalogReader, null, null); }
public RelDataType validateImpl(RelDataType targetRowType) { resolvedNamespace = Objects.requireNonNull(resolveImpl(id)); if (resolvedNamespace instanceof TableNamespace) { SqlValidatorTable table = resolvedNamespace.getTable(); if (validator.shouldExpandIdentifiers()) { RelDataType rowType = resolvedNamespace.getRowType(); rowType = resolvedNamespace.getRowType(); final String fieldName = field.getName(); final SqlMonotonicity monotonicity = resolvedNamespace.getMonotonicity(fieldName); if (monotonicity != SqlMonotonicity.NOT_MONOTONIC) { builder.add(
private void lookupSelectHints( SqlValidatorNamespace ns, SqlParserPos pos, Collection<SqlMoniker> hintList) { final SqlNode node = ns.getNode(); if (node instanceof SqlSelect) { lookupSelectHints((SqlSelect) node, pos, hintList); } }
/** * Returns whether there are any input columns that are sorted. * * <p>If so, it can be the default ORDER BY clause for a WINDOW specification. * (This is an extension to the SQL standard for streaming.) */ public static boolean containsMonotonic(SqlValidatorScope scope) { for (SqlValidatorNamespace ns : children(scope)) { ns = ns.resolve(); for (String field : ns.getRowType().getFieldNames()) { if (!ns.getMonotonicity(field).mayRepeat()) { return true; } } } return false; }
public void validateDelete(SqlDelete call) { final SqlSelect sqlSelect = call.getSourceSelect(); validateSelect(sqlSelect, unknownType); final SqlValidatorNamespace targetNamespace = getNamespace(call); validateNamespace(targetNamespace, unknownType); final SqlValidatorTable table = targetNamespace.getTable(); validateAccess(call.getTargetTable(), table, SqlAccessEnum.DELETE); }
getNamespace(call).unwrap(MatchRecognizeNamespace.class); assert ns.rowType == null; final SqlValidatorNamespace sqlNs = getNamespace(matchRecognize.getTableRef()); final RelDataType inputDataType = sqlNs.getRowType(); for (RelDataTypeField fs : inputDataType.getFieldList()) { if (!typeBuilder.nameExists(fs.getName())) { ns.setType(getNamespace(matchRecognize.getTableRef()).getRowType()); } else { ns.setType(rowType);
OrderExpressionExpander(SqlSelect select, SqlNode root) { super(getOrderScope(select)); this.select = select; this.root = root; this.aliasList = getNamespace(select).getRowType().getFieldNames(); }
for (ScopeChild child : scope.children) { final int before = fields.size(); if (child.namespace.getRowType().isDynamicStruct()) { hasDynamicStruct = true; includeSystemVars); } else { final SqlNode from = child.namespace.getNode(); final SqlValidatorNamespace fromNs = getNamespace(from, scope); assert fromNs != null; final RelDataType rowType = fromNs.getRowType(); for (RelDataTypeField field : rowType.getFieldList()) { String columnName = field.getName();
@Override public SqlMonotonicity getMonotonicity(String columnName) { SqlMonotonicity monotonicity = null; int index = getRowType().getFieldNames().indexOf(columnName); if (index < 0) { return SqlMonotonicity.NOT_MONOTONIC; } for (SqlNode operand : call.getOperandList()) { final SqlValidatorNamespace namespace = validator.getNamespace(operand); monotonicity = combine(monotonicity, namespace.getMonotonicity( namespace.getRowType().getFieldNames().get(index))); } return monotonicity; }
public RelDataType deriveType( SqlValidatorScope scope, SqlNode expr) { Objects.requireNonNull(scope); Objects.requireNonNull(expr); // if we already know the type, no need to re-derive RelDataType type = nodeToTypeMap.get(expr); if (type != null) { return type; } final SqlValidatorNamespace ns = getNamespace(expr); if (ns != null) { return ns.getType(); } type = deriveTypeImpl(scope, expr); Preconditions.checkArgument( type != null, "SqlValidator.deriveTypeInternal returned null"); setValidatedNodeType(expr, type); return type; }
getNamespace(select).unwrap(SelectNamespace.class); final ScopeChild child = fromScope.children.get(duplicateAliasOrdinal); throw newValidationError(child.namespace.getEnclosingNode(), RESOURCE.fromAliasDuplicate(child.name));
if (scope.children.size() == 1) { for (ScopeChild child : scope.children) { if (!child.namespace.supportsModality(modality)) { if (fail) { throw newValidationError(child.namespace.getNode(), Static.RESOURCE.cannotConvertToStream(child.name)); } else { int supportsModalityCount = 0; for (ScopeChild child : scope.children) { if (child.namespace.supportsModality(modality)) { ++supportsModalityCount; default: for (ScopeChild child : scope.children) { if (!child.namespace.supportsModality(modality)) { if (fail) { throw newValidationError(child.namespace.getNode(), Static.RESOURCE.cannotConvertToRelation(child.name)); } else {
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)); } }
for (ScopeChild entry : map2.values()) { final RelDataTypeField field = liberalMatcher.field(entry.namespace.getRowType(), columnName); list.add(field.getName()); Path.EMPTY, resolved); final RelDataTypeField field = nameMatcher.field(namespace.getRowType(), columnName); if (field != null) { if (hasAmbiguousUnresolvedStar(namespace.getRowType(), field, columnName)) { throw validator.newValidationError(identifier, nameMatcher.field(fromNs.getRowType(), columnName); if (field != null) { switch (field.getType().getStructKind()) { if (fromNs.getEnclosingNode() != null && !(this instanceof MatchRecognizeScope)) { String alias = SqlValidatorUtil.getAlias(fromNs.getEnclosingNode(), -1); if (alias != null && i > 0
ns = ns.lookupChild(name); RelDataType rowType = ns.getRowType(); for (RelDataTypeField field : rowType.getFieldList()) { hintList.add( && (selectScope.getChildren().size() == 1)) { RelDataType rowType = selectScope.getChildren().get(0).getRowType(); for (RelDataTypeField field : rowType.getFieldList()) { hintList.add(