@Override public RelDataType deriveType(SqlValidator validator, SqlValidatorScope scope, SqlCall call) { RelDataTypeFactory factory = validator.getTypeFactory(); return factory.createTypeWithNullability(factory.createSqlType(SqlTypeName.ANY), true); }
public void inferOperandTypes( SqlCallBinding callBinding, RelDataType returnType, RelDataType[] operandTypes) { final RelDataType unknownType = callBinding.getValidator().getUnknownType(); RelDataType knownType = unknownType; for (int i = 1; i < callBinding.getCall().getOperandList().size(); i++) { SqlNode operand = callBinding.getCall().getOperandList().get(i); knownType = callBinding.getValidator().deriveType( callBinding.getScope(), operand); if (!knownType.equals(unknownType)) { break; } } RelDataTypeFactory typeFactory = callBinding.getTypeFactory(); operandTypes[0] = typeFactory.createSqlType(SqlTypeName.BOOLEAN); for (int i = 1; i < operandTypes.length; ++i) { operandTypes[i] = knownType; } } };
private static void findAllValidUdfNames( List<String> names, SqlValidator validator, Collection<SqlMoniker> result) { final List<SqlMoniker> objNames = new ArrayList<>(); SqlValidatorUtil.getSchemaObjectMonikers( validator.getCatalogReader(), names, objNames); for (SqlMoniker objName : objNames) { if (objName.getType() == SqlMonikerType.FUNCTION) { result.add(objName); } } }
public RelDataType deriveType( SqlValidator validator, SqlValidatorScope scope, SqlCall call) { SqlSelect subSelect = call.operand(0); subSelect.validateExpr(validator, scope); SqlValidatorNamespace ns = validator.getNamespace(subSelect); assert null != ns.getRowType(); return SqlTypeUtil.createMultisetType( validator.getTypeFactory(), ns.getRowType(), false); }
protected void convertMatchRecognize(Blackboard bb, SqlCall call) { final SqlMatchRecognize matchRecognize = (SqlMatchRecognize) call; final SqlValidatorNamespace ns = validator.getNamespace(matchRecognize); final SqlValidatorScope scope = validator.getMatchRecognizeScope(matchRecognize); validator.getDefaultNullCollation().last(desc(direction)) ? RelFieldCollation.NullDirection.LAST : RelFieldCollation.NullDirection.FIRST; RexNode rex = rexBuilder.makeLiteral(id.getSimple()); after = rexBuilder.makeCall(validator.getUnknownType(), operator, ImmutableList.of(rex)); } else {
@Override public void validateCall(SqlCall call, SqlValidator validator, SqlValidatorScope scope, SqlValidatorScope operandScope) { super.validateCall(call, validator, scope, operandScope); final SelectScope selectScope = SqlValidatorUtil.getEnclosingSelectScope(scope); assert selectScope != null; final SqlSelect select = selectScope.getNode(); if (!validator.isAggregate(select)) { throw validator.newValidationError(call, Static.RESOURCE.groupingInAggregate(getName())); } final AggregatingSelectScope aggregatingSelectScope = SqlValidatorUtil.getEnclosingAggregateSelectScope(scope); if (aggregatingSelectScope == null) { // We're probably in the GROUP BY clause throw validator.newValidationError(call, Static.RESOURCE.groupingInWrongClause(getName())); } for (SqlNode operand : call.getOperandList()) { if (scope instanceof OrderByScope) { operand = validator.expandOrderExpr(select, operand); } else { operand = validator.expand(operand, scope); } if (!aggregatingSelectScope.resolved.get().isGroupingExpr(operand)) { throw validator.newValidationError(operand, Static.RESOURCE.groupingArgument(getName())); } } }
/** Registers with the validator a {@link SqlNode} that has been created * during the Sql-to-Rel process. */ private static SqlNode reg(SqlValidatorScope scope, SqlNode e) { scope.getValidator().deriveType(scope, e); return e; }
/** Shared implementation for {@link #parse}, {@link #convert} and * {@link #analyzeView}. */ private ParseResult parse_(Context context, String sql, boolean convert, boolean analyze, boolean fail) { final JavaTypeFactory typeFactory = context.getTypeFactory(); CalciteCatalogReader catalogReader = new CalciteCatalogReader( context.getRootSchema(), context.getDefaultSchemaPath(), typeFactory, context.config()); SqlParser parser = createParser(sql); SqlNode sqlNode; try { sqlNode = parser.parseStmt(); } catch (SqlParseException e) { throw new RuntimeException("parse failed", e); } final SqlValidator validator = createSqlValidator(context, catalogReader); SqlNode sqlNode1 = validator.validate(sqlNode); if (convert) { return convert_( context, sql, analyze, fail, catalogReader, validator, sqlNode1); } return new ParseResult(this, validator, sql, sqlNode1, validator.getValidatedNodeType(sqlNode1)); }
@Override public RelDataType getOperandType(int ordinal) { final SqlNode operand = call.operand(ordinal); final RelDataType type = validator.deriveType(scope, operand); final SqlValidatorNamespace namespace = validator.getNamespace(operand); if (namespace != null) { return namespace.getType(); } return type; }
/** * Returns the type inferred for a dynamic parameter. * * @param index 0-based index of dynamic parameter * @return inferred type, never null */ public RelDataType getDynamicParamType(int index) { SqlNode sqlNode = dynamicParamSqlNodes.get(index); if (sqlNode == null) { throw Util.needToImplement("dynamic param type inference"); } return validator.getValidatedNodeType(sqlNode); }
this.bb = bb; this.aggregatingSelectScope = (AggregatingSelectScope) bb.getValidator().getSelectScope(select); name = validator.deriveAlias(selectItem, i);
@Override public boolean isWithin(SqlValidatorScope scope2) { if (this == scope2) { return true; } SqlValidatorScope s = getValidator().getSelectScope((SqlSelect) node); return s.isWithin(scope2); } }
@Override public void validate(SqlValidator validator, SqlValidatorScope scope) { validator.validate(value); }
public void checkMonotonic(String query, SqlMonotonicity expectedMonotonicity) { SqlValidator validator = getValidator(); SqlNode n = parseAndValidate(validator, query); final RelDataType rowType = validator.getValidatedNodeType(n); final SqlValidatorNamespace selectNamespace = validator.getNamespace(n); final String field0 = rowType.getFieldList().get(0).getName(); final SqlMonotonicity monotonicity = selectNamespace.getMonotonicity(field0); assertThat(monotonicity, equalTo(expectedMonotonicity)); }
public void validateCall( SqlCall call, SqlValidator validator, SqlValidatorScope scope, SqlValidatorScope operandScope) { validator.validateQuery(call, operandScope, validator.getUnknownType()); } }
return; for (SqlOperator op : validator.getOperatorTable().getOperatorList()) { SqlIdentifier curOpId = new SqlIdentifier( validator.getOperatorTable(), curOpId); if (call != null) {
@Override public int getGroupCount() { final SelectScope selectScope = SqlValidatorUtil.getEnclosingSelectScope(scope); if (selectScope == null) { // Probably "VALUES expr". Treat same as "SELECT expr GROUP BY ()" return 0; } final SqlSelect select = selectScope.getNode(); final SqlNodeList group = select.getGroup(); if (group != null) { int n = 0; for (SqlNode groupItem : group) { if (!(groupItem instanceof SqlNodeList) || ((SqlNodeList) groupItem).size() != 0) { ++n; } } return n; } return validator.isAggregate(select) ? 0 : -1; }
public void validateExpr(SqlValidator validator, SqlValidatorScope scope) { // First check for builtin functions which don't have parentheses, // like "LOCALTIME". SqlCall call = SqlUtil.makeCall( validator.getOperatorTable(), this); if (call != null) { validator.validateCall(call, scope); return; } validator.validateIdentifier(this, scope); }
SqlNode groupExpr) { final SqlNode expandedGroupExpr = scope.getValidator().expand(groupExpr, scope); scope.getValidator().getCatalogReader().nameMatcher(); final SqlValidatorScope.ResolvedImpl resolved = new SqlValidatorScope.ResolvedImpl();
@Override public RexNode visit(SqlCall call) { List<SqlNode> operands = call.getOperandList(); List<RexNode> newOperands = Lists.newArrayList(); for (SqlNode node : operands) { newOperands.add(node.accept(this)); } return rexBuilder.makeCall( validator.getUnknownType(), call.getOperator(), newOperands); }