final SqlValidatorScope seekScope = (seek instanceof SqlSelect) ? validator.getSelectScope((SqlSelect) seek) : null; final Blackboard seekBb = createBlackboard(seekScope, null);
(CollectNamespace) validator.getNamespace(call); Blackboard usedBb; if (null != nss) { null); RelDataType multisetType = validator.getValidatedNodeType(call); validator.setValidatedNodeType( list, multisetType.getComponentType()); cluster.traitSetOf(Convention.NONE), input, validator.deriveAlias(call, i)); joinList.add(collectRel);
final boolean top) { if (needsValidation) { query = validator.validate(query);
List<SqlNode> orderList) { SqlNodeList selectList = select.getSelectList(); selectList = validator.expandStar(selectList, select, false); SqlNode expr2 = validator.expandOrderExpr(select, expr); exprs.add(bb.convertExpression(expr2)); fieldNames.add(deriveAlias(expr, aliases, i));
SqlNode windowOrRef = call.operand(1); final SqlWindow window = validator.resolveWindow(windowOrRef, bb.scope, true); final SqlNodeList partitionList = window.getPartitionList(); final ImmutableList.Builder<RexNode> partitionKeys = rexAgg = rexBuilder.ensureType( validator.getValidatedNodeType(call), rexAgg, false);
if (validator.isAggregate(selectNode)) { aggList.add(selectNode); ++i; final SqlNode expandedGroupExpr = validator.expand(groupExpr, bb.scope); aggConverter.addGroupExpr(expandedGroupExpr); SqlValidatorUtil.getEnclosingSelectScope(bb.scope); final SqlValidatorNamespace selectNamespace = validator.getNamespace(selectScope.getNode()); final List<String> names = selectNamespace.getRowType().getFieldNames(); selectNames.add( k < sysFieldCount ? validator.deriveAlias(expr, k++) : names.get(k++ - sysFieldCount)); selectNames.add(validator.deriveAlias(expr, k++));
SqlWindow win = validator.resolveWindow(this, operandScope, false); partitionList = win.partitionList; orderList = win.orderList; validator.getColumnReferenceExpansion(); validator.setColumnReferenceExpansion(false); try { orderItem.validateExpr(validator, scope); } finally { validator.setColumnReferenceExpansion( savedColumnReferenceExpansion); && windowCall != null && windowCall.getOperator().requiresOrder()) { throw validator.newValidationError(this, RESOURCE.funcNeedsOrderBy()); throw validator.newValidationError(isRows, RESOURCE.rankWithFrame()); throw validator.newValidationError(isRows, RESOURCE.compoundOrderByProhibitsRange()); validator.deriveType( operandScope, orderList.get(0)); throw validator.newValidationError(this, RESOURCE.overMissingOrderBy()); && windowCall != null
/** * 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); }
public ParseResult parse( Context context, String sql) { final JavaTypeFactory typeFactory = context.getTypeFactory(); OptiqCatalogReader catalogReader = new OptiqCatalogReader( context.getRootSchema(), context.getDefaultSchemaPath(), typeFactory); SqlParser parser = new SqlParser(sql); SqlNode sqlNode; try { sqlNode = parser.parseStmt(); } catch (SqlParseException e) { throw new RuntimeException("parse failed", e); } final SqlValidator validator = new OptiqSqlValidator( SqlStdOperatorTable.instance(), catalogReader, typeFactory); SqlNode sqlNode1 = validator.validate(sqlNode); return new ParseResult( sql, sqlNode1, validator.getValidatedNodeType(sqlNode1)); }
@Test public void testRewriteWithColumnReferenceExpansion() { // NOTE jvs 9-Apr-2007: This tests illustrates that // ORDER BY is still a special case. Update expected // output if that gets fixed in the future. SqlValidator validator = tester.getValidator(); validator.setIdentifierExpansion(true); validator.setColumnReferenceExpansion(true); tester.checkRewrite( validator, "select name from dept where name = 'Moonracer' group by name" + " having sum(deptno) > 3 order by name", "SELECT `DEPT`.`NAME`\n" + "FROM `CATALOG`.`SALES`.`DEPT` AS `DEPT`\n" + "WHERE `DEPT`.`NAME` = 'Moonracer'\n" + "GROUP BY `DEPT`.`NAME`\n" + "HAVING SUM(`DEPT`.`DEPTNO`) > 3\n" + "ORDER BY `NAME`"); }
validator.getNamespace(from).resolve(); if (fromNamespace.getNode() != null) { convertFrom(bb, fromNamespace.getNode()); final SqlJoin join = (SqlJoin) from; final Blackboard fromBlackboard = createBlackboard(validator.getJoinScope(from), null); SqlNode left = join.getLeft(); SqlNode right = join.getRight(); final Blackboard leftBlackboard = createBlackboard( Util.first(validator.getJoinScope(left), ((DelegatingScope) bb.scope).getParent()), null); final Blackboard rightBlackboard = createBlackboard( Util.first(validator.getJoinScope(right), ((DelegatingScope) bb.scope).getParent()), null); convertFrom(leftBlackboard, left); final List<String> columnList = SqlValidatorUtil.deriveNaturalJoinColumnList( validator.getNamespace(left).getRowType(), validator.getNamespace(right).getRowType()); conditionExp = convertUsing(leftRel, rightRel, columnList); } else { (null != bb.root) ? bb.root : new OneRowRel(cluster), Collections.singletonList(bb.convertExpression(node)),
protected RelDataType uniquifyFields(RelDataType rowType) { return validator.getTypeFactory().createStructType( RelOptUtil.getFieldTypeList(rowType), SqlValidatorUtil.uniquify(rowType.getFieldNames())); }
SqlNode converted = validator.expandOrderExpr(select, orderItem); final SelectScope selectScope = validator.getRawSelectScope(select); int ordinal = -1; for (SqlNode selectItem : selectScope.getExpandedSelectList()) {
final RelDataType resultType = validator.getValidatedNodeType(sqlQuery); fieldOrigins = validator.getFieldOrigins(sqlQuery); assert fieldOrigins.size() == resultType.getFieldCount(); parameterRowType = validator.getParameterRowType(sqlQuery);
RelDataType type = validator.deriveType(bb.scope, call); boolean distinct = false; SqlLiteral quantifier = call.getFunctionQuantifier();
public RelDataType deriveType( SqlValidator validator, SqlValidatorScope scope, SqlCall call) { SqlSelect subSelect = (SqlSelect) call.operands[0]; subSelect.validateExpr(validator, scope); SqlValidatorNamespace ns = validator.getNamespace(subSelect); assert null != ns.getRowType(); return SqlTypeUtil.createMultisetType( validator.getTypeFactory(), ns.getRowType(), false); }
/** * Recreates a given RelDataType with nullablility iff any of a calls * operand types are nullable. */ public static RelDataType makeNullableIfOperandsAre( final SqlValidator validator, final SqlValidatorScope scope, final SqlCall call, RelDataType type) { for (SqlNode operand : call.operands) { RelDataType operandType = validator.deriveType(scope, operand); if (containsNullable(operandType)) { RelDataTypeFactory typeFactory = validator.getTypeFactory(); type = typeFactory.createTypeWithNullability(type, true); break; } } return type; }
final RelDataType resultType = validator.getValidatedNodeType(sqlQuery); fieldOrigins = validator.getFieldOrigins(sqlQuery); assert fieldOrigins.size() == resultType.getFieldCount();
private String deriveAlias( final SqlNode node, Collection<String> aliases, final int ordinal) { String alias = validator.deriveAlias(node, ordinal); if ((alias == null) || aliases.contains(alias)) { String aliasBase = (alias == null) ? "EXPR$" : alias; for (int j = 0;; j++) { alias = aliasBase + j; if (!aliases.contains(alias)) { break; } } } aliases.add(alias); return alias; }
public RelDataType getOperandType(int ordinal) { final SqlNode operand = call.operands[ordinal]; final RelDataType type = validator.deriveType(scope, operand); final SqlValidatorNamespace namespace = validator.getNamespace(operand); if (namespace != null) { return namespace.getRowTypeSansSystemColumns(); } return type; }