use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataType in project calcite by apache.
the class SqlValidatorImpl method validateMerge.
public void validateMerge(SqlMerge call) {
SqlSelect sqlSelect = call.getSourceSelect();
// REVIEW zfong 5/25/06 - Does an actual type have to be passed into
// validateSelect()?
// REVIEW jvs 6-June-2006: In general, passing unknownType like
// this means we won't be able to correctly infer the types
// for dynamic parameter markers (SET x = ?). But
// maybe validateUpdate and validateInsert below will do
// the job?
// REVIEW ksecretan 15-July-2011: They didn't get a chance to
// since validateSelect() would bail.
// Let's use the update/insert targetRowType when available.
IdentifierNamespace targetNamespace = (IdentifierNamespace) getNamespace(call.getTargetTable());
validateNamespace(targetNamespace, unknownType);
SqlValidatorTable table = targetNamespace.getTable();
validateAccess(call.getTargetTable(), table, SqlAccessEnum.UPDATE);
RelDataType targetRowType = unknownType;
if (call.getUpdateCall() != null) {
targetRowType = createTargetRowType(table, call.getUpdateCall().getTargetColumnList(), true);
}
if (call.getInsertCall() != null) {
targetRowType = createTargetRowType(table, call.getInsertCall().getTargetColumnList(), false);
}
validateSelect(sqlSelect, targetRowType);
if (call.getUpdateCall() != null) {
validateUpdate(call.getUpdateCall());
}
if (call.getInsertCall() != null) {
validateInsert(call.getInsertCall());
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataType 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.rel.type.RelDataType 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.rel.type.RelDataType in project calcite by apache.
the class SqlValidatorImpl method deriveConstructorType.
public RelDataType deriveConstructorType(SqlValidatorScope scope, SqlCall call, SqlFunction unresolvedConstructor, SqlFunction resolvedConstructor, List<RelDataType> argTypes) {
SqlIdentifier sqlIdentifier = unresolvedConstructor.getSqlIdentifier();
assert sqlIdentifier != null;
RelDataType type = catalogReader.getNamedType(sqlIdentifier);
if (type == null) {
// TODO jvs 12-Feb-2005: proper type name formatting
throw newValidationError(sqlIdentifier, RESOURCE.unknownDatatypeName(sqlIdentifier.toString()));
}
if (resolvedConstructor == null) {
if (call.operandCount() > 0) {
// no user-defined constructor could be found
throw handleUnresolvedFunction(call, unresolvedConstructor, argTypes, null);
}
} else {
SqlCall testCall = resolvedConstructor.createCall(call.getParserPosition(), call.getOperandList());
RelDataType returnType = resolvedConstructor.validateOperands(this, scope, testCall);
assert type == returnType;
}
if (shouldExpandIdentifiers()) {
if (resolvedConstructor != null) {
((SqlBasicCall) call).setOperator(resolvedConstructor);
} else {
// fake a fully-qualified call to the default constructor
((SqlBasicCall) call).setOperator(new SqlFunction(type.getSqlIdentifier(), ReturnTypes.explicit(type), null, null, null, SqlFunctionCategory.USER_DEFINED_CONSTRUCTOR));
}
}
return type;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataType 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);
}
Aggregations