use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelRoot in project druid by apache.
the class DruidPlanner method plan.
/**
* Plan an SQL query for execution, returning a {@link PlannerResult} which can be used to actually execute the query.
*
* Ideally, the query can be planned into a native Druid query, using {@link #planWithDruidConvention}, but will
* fall-back to {@link #planWithBindableConvention} if this is not possible.
*
* In some future this could perhaps re-use some of the work done by {@link #validate()}
* instead of repeating it, but that day is not today.
*/
public PlannerResult plan() throws SqlParseException, ValidationException, RelConversionException {
resetPlanner();
final ParsedNodes parsed = ParsedNodes.create(planner.parse(plannerContext.getSql()));
try {
if (parsed.getIngestionGranularity() != null) {
plannerContext.getQueryContext().put(DruidSqlInsert.SQL_INSERT_SEGMENT_GRANULARITY, plannerContext.getJsonMapper().writeValueAsString(parsed.getIngestionGranularity()));
}
} catch (JsonProcessingException e) {
throw new ValidationException("Unable to serialize partition granularity.");
}
// the planner's type factory is not available until after parsing
this.rexBuilder = new RexBuilder(planner.getTypeFactory());
final SqlNode parameterizedQueryNode = rewriteDynamicParameters(parsed.getQueryNode());
final SqlNode validatedQueryNode = planner.validate(parameterizedQueryNode);
final RelRoot rootQueryRel = planner.rel(validatedQueryNode);
try {
return planWithDruidConvention(rootQueryRel, parsed.getExplainNode(), parsed.getInsertNode());
} catch (Exception e) {
Throwable cannotPlanException = Throwables.getCauseOfType(e, RelOptPlanner.CannotPlanException.class);
if (null == cannotPlanException) {
// Not a CannotPlanningException, rethrow without trying with bindable
throw e;
}
// any error, if it is plannable by the bindable convention
if (parsed.getInsertNode() == null) {
// Try again with BINDABLE convention. Used for querying Values and metadata tables.
try {
return planWithBindableConvention(rootQueryRel, parsed.getExplainNode());
} catch (Exception e2) {
e.addSuppressed(e2);
}
}
Logger logger = log;
if (!QueryContexts.isDebug(plannerContext.getQueryContext())) {
logger = log.noStackTrace();
}
String errorMessage = buildSQLPlanningErrorMessage(cannotPlanException);
logger.warn(e, errorMessage);
throw new UnsupportedSQLQueryException(errorMessage);
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelRoot in project Mycat2 by MyCATApache.
the class DrdsSqlCompiler method getRelRoot.
public RelNodeContext getRelRoot(SchemaPlus plus, DrdsSql drdsSql) {
CalciteCatalogReader catalogReader = DrdsRunnerHelper.newCalciteCatalogReader(plus);
SqlValidator validator = DrdsRunnerHelper.getSqlValidator(drdsSql, catalogReader);
RelOptCluster cluster = newCluster();
SqlToRelConverter sqlToRelConverter = new SqlToRelConverter(new ViewExpander(), validator, catalogReader, cluster, MycatCalciteSupport.config.getConvertletTable(), MycatCalciteSupport.sqlToRelConverterConfig);
MycatCalciteMySqlNodeVisitor mycatCalciteMySqlNodeVisitor = new MycatCalciteMySqlNodeVisitor();
RelBuilder relBuilder = MycatCalciteSupport.relBuilderFactory.create(sqlToRelConverter.getCluster(), catalogReader);
SQLStatement sqlStatement = null;
SqlNode sqlNode = null;
SqlNode validated = null;
RelDataType parameterRowType = null;
RelRoot root = null;
RelNode decorRelNode = null;
try {
sqlStatement = drdsSql.getParameterizedStatement();
mycatCalciteMySqlNodeVisitor = new MycatCalciteMySqlNodeVisitor();
sqlStatement.accept(mycatCalciteMySqlNodeVisitor);
sqlNode = mycatCalciteMySqlNodeVisitor.getSqlNode();
validated = validator.validate(sqlNode);
parameterRowType = validator.getParameterRowType(sqlNode);
root = sqlToRelConverter.convertQuery(validated, false, true);
decorRelNode = RelDecorrelator.decorrelateQuery(root.rel, relBuilder);
return new RelNodeContext(root.withRel(decorRelNode), sqlToRelConverter, validator, relBuilder, catalogReader, parameterRowType);
} catch (Throwable throwable) {
log.error("sqlStatement:{} sqlNode:{} validated:{} root:{} newRelNode:{}", sqlStatement, sqlNode, validated, root, decorRelNode);
throw throwable;
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelRoot in project ignite-3 by apache.
the class IgnitePlanner method expandView.
/**
* {@inheritDoc}
*/
@Override
public RelRoot expandView(RelDataType rowType, String qryStr, List<String> schemaPath, List<String> viewPath) {
SqlParser parser = SqlParser.create(qryStr, parserCfg);
SqlNode sqlNode;
try {
sqlNode = parser.parseQuery();
} catch (SqlParseException e) {
// throw new IgniteSQLException("parse failed", IgniteQueryErrorCode.PARSING, e);
throw new IgniteException("parse failed", e);
}
CalciteCatalogReader catalogReader = this.catalogReader.withSchemaPath(schemaPath);
SqlValidator validator = new IgniteSqlValidator(operatorTbl, catalogReader, typeFactory, validatorCfg, ctx.parameters());
SqlToRelConverter sqlToRelConverter = sqlToRelConverter(validator, catalogReader, sqlToRelConverterCfg);
RelRoot root = sqlToRelConverter.convertQuery(sqlNode, true, false);
root = root.withRel(sqlToRelConverter.decorrelate(sqlNode, root.rel));
return trimUnusedFields(root);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelRoot in project coral by linkedin.
the class TestUtils method toRel.
static RelNode toRel(String sql, FrameworkConfig config) {
Planner planner = Frameworks.getPlanner(config);
try {
SqlNode sn = planner.parse(sql);
SqlNode validate = planner.validate(sn);
RelRoot rel = planner.rel(validate);
// RelNode relNode = rel.project();
return rel.project();
// return Calcite2TrinoUDFConverter.convertRel(relNode);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelRoot in project dingo by dingodb.
the class TestLogicalPlan method testSortLimit.
@Test
public void testSortLimit() throws SqlParseException {
String sql = "select * from test order by name limit 3";
RelRoot relRoot = parse(sql);
Assert.relNode(relRoot.rel).isA(LogicalSort.class).convention(Convention.NONE).singleInput().isA(LogicalProject.class).convention(Convention.NONE).singleInput().isA(DingoTableScan.class).convention(DingoConventions.DINGO);
}
Aggregations