/** * Converts a WITH sub-query into a relational expression. */ public RelNode convertWith(SqlWith with) { return convertQuery(with.body, false, false); }
input = convertQueryOrInList(usedBb, list); } else { input = convertQuery(call.operand(0), false, true);
private RelNode convertCursor(Blackboard bb, SubQuery subQuery) { final SqlCall cursorCall = (SqlCall) subQuery.node; assert cursorCall.operandCount() == 1; SqlNode query = cursorCall.operand(0); RelNode converted = convertQuery(query, false, false); int iCursor = bb.cursors.size(); bb.cursors.add(converted); subQuery.expr = new RexInputRef( iCursor, converted.getRowType()); return converted; }
input = convertQueryOrInList(usedBb, list); } else { input = convertQuery(call.operands[0], false, true);
/** * Converts a WITH sub-query into a relational expression. */ public RelNode convertWith(SqlWith with) { return convertQuery(with.body, false, false); }
SqlCall cursorCall = call.operand(1); SqlNode query = cursorCall.operand(0); RelNode converted = convertQuery(query, false, false); bb.setRoot(converted, false); datasetStack.pop();
private RelNode convertCursor(Blackboard bb, SqlCall cursorCall) { assert (cursorCall.operands.length == 1); SqlNode query = cursorCall.operands[0]; RelNode converted = convertQuery(query, false, false); int iCursor = bb.cursors.size(); bb.cursors.add(converted); RexNode expr = new RexInputRef( iCursor, converted.getRowType()); bb.mapSubqueryToExpr.put(cursorCall, expr); return converted; }
private RelNode convertCursor(Blackboard bb, SqlCall cursorCall) { assert cursorCall.operandCount() == 1; SqlNode query = cursorCall.operand(0); RelNode converted = convertQuery(query, false, false); int iCursor = bb.cursors.size(); bb.cursors.add(converted); RexNode expr = new RexInputRef( iCursor, converted.getRowType()); bb.mapSubqueryToExpr.put(cursorCall, expr); return converted; }
@Override public RelNode expandView( RelDataType rowType, String queryString, List<String> schemaPath) { expansionDepth++; SqlParser parser = SqlParser.create(queryString); SqlNode sqlNode; try { sqlNode = parser.parseQuery(); } catch (SqlParseException e) { throw new RuntimeException("parse failed", e); } // View may have different schema path than current connection. final CatalogReader catalogReader = this.catalogReader.withSchemaPath(schemaPath); SqlValidator validator = createSqlValidator(catalogReader); SqlNode sqlNode1 = validator.validate(sqlNode); SqlToRelConverter sqlToRelConverter = getSqlToRelConverter(validator, catalogReader); RelNode relNode = sqlToRelConverter.convertQuery(sqlNode1, true, false); --expansionDepth; return relNode; }
@Override public RelNode expandView( RelDataType rowType, String queryString, List<String> schemaPath) { expansionDepth++; SqlParser parser = new SqlParser(queryString); SqlNode sqlNode; try { sqlNode = parser.parseQuery(); } catch (SqlParseException e) { throw new RuntimeException("parse failed", e); } // View may have different schema path than current connection. final OptiqCatalogReader catalogReader = new OptiqCatalogReader( ((OptiqCatalogReader) this.catalogReader).rootSchema, schemaPath, ((OptiqCatalogReader) this.catalogReader).typeFactory); SqlValidator validator = createSqlValidator(catalogReader); SqlNode sqlNode1 = validator.validate(sqlNode); SqlToRelConverter sqlToRelConverter = getSqlToRelConverter(validator, catalogReader); RelNode relNode = sqlToRelConverter.convertQuery(sqlNode1, true, false); --expansionDepth; return relNode; }
public RelNode expandView(RelDataType rowType, String queryString, List<String> schemaPath) { SqlParser parser = SqlParser.create(parserFactory, queryString, lex.quoting, lex.unquotedCasing, lex.quotedCasing); SqlNode sqlNode; try { sqlNode = parser.parseQuery(); } catch (SqlParseException e) { throw new RuntimeException("parse failed", e); } final OptiqCatalogReader catalogReader = createCatalogReader().withSchemaPath(schemaPath); SqlValidator validator = new OptiqSqlValidator( operatorTable, catalogReader, typeFactory); SqlNode validatedSqlNode = validator.validate(sqlNode); SqlToRelConverter sqlToRelConverter = new SqlToRelConverter( null, validator, catalogReader, planner, createRexBuilder(), convertletTable); sqlToRelConverter.setTrimUnusedFields(false); return sqlToRelConverter.convertQuery(validatedSqlNode, true, false); } }
/** Populates a materialization record, converting a table path * (essentially a list of strings, like ["hr", "sales"]) into a table object * that can be used in the planning process. */ void populate(Materialization materialization) { SqlParser parser = new SqlParser(materialization.sql); SqlNode node; try { node = parser.parseStmt(); } catch (SqlParseException e) { throw new RuntimeException("parse failed", e); } SqlToRelConverter sqlToRelConverter2 = getSqlToRelConverter(getSqlValidator(), catalogReader); materialization.queryRel = sqlToRelConverter2.convertQuery(node, true, true); RelOptTable table = catalogReader.getTable(materialization.materializedTable.path()); materialization.tableRel = table.toRel(sqlToRelConverter2.makeToRelContext()); } }
/** Populates a materialization record, converting a table path * (essentially a list of strings, like ["hr", "sales"]) into a table object * that can be used in the planning process. */ void populate(Materialization materialization) { SqlParser parser = SqlParser.create(materialization.sql); SqlNode node; try { node = parser.parseStmt(); } catch (SqlParseException e) { throw new RuntimeException("parse failed", e); } SqlToRelConverter sqlToRelConverter2 = getSqlToRelConverter(getSqlValidator(), catalogReader); materialization.queryRel = sqlToRelConverter2.convertQuery(node, true, true); // Identify and substitute a StarTable in queryRel. // // It is possible that no StarTables match. That is OK, but the // materialization patterns that are recognized will not be as rich. // // It is possible that more than one StarTable matches. TBD: should we // take the best (whatever that means), or all of them? useStar(schema, materialization); RelOptTable table = this.catalogReader.getTable(materialization.materializedTable.path()); materialization.tableRel = sqlToRelConverter2.toRel(table); }
protected void convertCollectionTable( Blackboard bb, SqlCall call) { if (call.getOperator() == SqlStdOperatorTable.sampleFunction) { final String sampleName = SqlLiteral.stringValue(call.operands[0]); datasetStack.push(sampleName); SqlCall cursorCall = (SqlCall) call.operands[1]; SqlNode query = cursorCall.operands[0]; RelNode converted = convertQuery(query, false, false); bb.setRoot(converted, false); datasetStack.pop(); return; } replaceSubqueries(bb, call); RexNode rexCall = bb.convertExpression(call); final List<RelNode> inputs = bb.retrieveCursors(); Set<RelColumnMapping> columnMappings = getColumnMappings(call.getOperator()); TableFunctionRel callRel = new TableFunctionRel( cluster, inputs, rexCall, validator.getValidatedNodeType(call), columnMappings); bb.setRoot(callRel, true); afterTableFunction(bb, call, callRel); }
public RelNode convert(SqlNode sql) throws RelConversionException { ensure(State.STATE_4_VALIDATED); assert validatedSqlNode != null; this.sqlToRelConverter = new SqlToRelConverter( new ViewExpanderImpl(), validator, createCatalogReader(), planner, createRexBuilder(), convertletTable); sqlToRelConverter.setTrimUnusedFields(false); sqlToRelConverter.enableTableAccessConversion(false); rel = sqlToRelConverter.convertQuery(validatedSqlNode, false, true); rel = sqlToRelConverter.flattenTypes(rel, true); rel = sqlToRelConverter.decorrelate(validatedSqlNode, rel); state = State.STATE_5_CONVERTED; return rel; }
SqlCall cursorCall = call.operand(1); SqlNode query = cursorCall.operand(0); RelNode converted = convertQuery(query, false, false); bb.setRoot(converted, false); datasetStack.pop();
public RelNode convertSqlToRel(String sql) { Util.pre(sql != null, "sql != null"); final SqlNode sqlQuery; try { sqlQuery = parseQuery(sql); } catch (Exception e) { throw Util.newInternal(e); // todo: better handling } final RelDataTypeFactory typeFactory = getTypeFactory(); final Prepare.CatalogReader catalogReader = createCatalogReader(typeFactory); final SqlValidator validator = createValidator( catalogReader, typeFactory); final SqlToRelConverter converter = createSqlToRelConverter( validator, catalogReader, typeFactory); converter.setTrimUnusedFields(true); final SqlNode validatedQuery = validator.validate(sqlQuery); final RelNode rel = converter.convertQuery(validatedQuery, false, true); Util.post(rel != null, "return != null"); return rel; }
final SqlNode validatedQuery = validator.validate(sqlQuery); RelNode rel = converter.convertQuery(validatedQuery, false, true); assert rel != null; if (enableDecorrelate || enableTrim) {
sqlToRelConverter.convertQuery(sqlQuery, needsValidation, true);
sqlToRelConverter.convertQuery(sqlQuery, needsValidation, true); Hook.CONVERTED.run(rootRel);