korlov42 commented on a change in pull request #9282:
URL: https://github.com/apache/ignite/pull/9282#discussion_r681714924
##########
File path:
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/planner/PlannerTest.java
##########
@@ -89,504 +85,20 @@
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.testframework.junits.GridTestKernalContext;
import org.apache.ignite.thread.IgniteStripedThreadPoolExecutor;
-import org.jetbrains.annotations.Nullable;
import org.junit.Assert;
import org.junit.Test;
import static org.apache.calcite.tools.Frameworks.createRootSchema;
import static org.apache.calcite.tools.Frameworks.newConfigBuilder;
import static
org.apache.ignite.configuration.IgniteConfiguration.DFLT_THREAD_KEEP_ALIVE_TIME;
import static
org.apache.ignite.internal.processors.query.calcite.CalciteQueryProcessor.FRAMEWORK_CONFIG;
-import static
org.apache.ignite.internal.processors.query.calcite.externalize.RelJsonWriter.toJson;
/**
*
*/
//@WithSystemProperty(key = "calcite.debug", value = "true")
@SuppressWarnings({"TooBroadScope", "FieldCanBeLocal", "TypeMayBeWeakened"})
public class PlannerTest extends AbstractPlannerTest {
- /**
- * @throws Exception If failed.
- */
- @Test
- public void testLogicalPlan() throws Exception {
- IgniteTypeFactory f = new IgniteTypeFactory(IgniteTypeSystem.INSTANCE);
-
- TestTable developer = new TestTable(
- new RelDataTypeFactory.Builder(f)
- .add("ID", f.createJavaType(Integer.class))
- .add("NAME", f.createJavaType(String.class))
- .add("PROJECTID", f.createJavaType(Integer.class))
- .build()) {
- };
-
- TestTable project = new TestTable(
- new RelDataTypeFactory.Builder(f)
- .add("ID", f.createJavaType(Integer.class))
- .add("NAME", f.createJavaType(String.class))
- .add("VER", f.createJavaType(Integer.class))
- .build()) {
- };
-
- IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
-
- publicSchema.addTable("DEVELOPER", developer);
- publicSchema.addTable("PROJECT", project);
-
- SchemaPlus schema = createRootSchema(false)
- .add("PUBLIC", publicSchema);
-
- String sql = "SELECT d.id, d.name, d.projectId, p.id0, p.ver0 " +
- "FROM PUBLIC.Developer d JOIN (" +
- "SELECT pp.id as id0, pp.ver as ver0 FROM PUBLIC.Project pp" +
- ") p " +
- "ON d.projectId = p.id0 + 1" +
- "WHERE (d.projectId + 1) > ?";
-
- RelTraitDef<?>[] traitDefs = {
- ConventionTraitDef.INSTANCE
- };
-
- PlanningContext ctx = PlanningContext.builder()
- .localNodeId(F.first(nodes))
- .originatingNodeId(F.first(nodes))
- .parentContext(Contexts.empty())
- .frameworkConfig(newConfigBuilder(FRAMEWORK_CONFIG)
- .defaultSchema(schema)
- .traitDefs(traitDefs)
- .build())
- .logger(log)
- .query(sql)
- .parameters(2)
- .topologyVersion(AffinityTopologyVersion.NONE)
- .build();
-
- RelRoot relRoot;
-
- try (IgnitePlanner planner = ctx.planner()) {
- assertNotNull(planner);
-
- String qry = ctx.query();
-
- assertNotNull(qry);
-
- // Parse
- SqlNode sqlNode = planner.parse(qry);
-
- // Validate
- sqlNode = planner.validate(sqlNode);
-
- // Convert to Relational operators graph
- relRoot = planner.rel(sqlNode);
- }
-
- assertNotNull(relRoot.rel);
- }
-
- /**
- * @throws Exception If failed.
- */
- @Test
- public void testLogicalPlanDefaultSchema() throws Exception {
- IgniteTypeFactory f = new IgniteTypeFactory(IgniteTypeSystem.INSTANCE);
-
- TestTable developer = new TestTable(
- new RelDataTypeFactory.Builder(f)
- .add("ID", f.createJavaType(Integer.class))
- .add("NAME", f.createJavaType(String.class))
- .add("PROJECTID", f.createJavaType(Integer.class))
- .build()) {
- };
-
- TestTable project = new TestTable(
- new RelDataTypeFactory.Builder(f)
- .add("ID", f.createJavaType(Integer.class))
- .add("NAME", f.createJavaType(String.class))
- .add("VER", f.createJavaType(Integer.class))
- .build()) {
- };
-
- IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
-
- publicSchema.addTable("DEVELOPER", developer);
- publicSchema.addTable("PROJECT", project);
-
- SchemaPlus schema = createRootSchema(false)
- .add("PUBLIC", publicSchema);
-
- String sql = "SELECT d.id, d.name, d.projectId, p.id0, p.ver0 " +
- "FROM Developer d JOIN (" +
- "SELECT pp.id as id0, pp.ver as ver0 FROM Project pp" +
- ") p " +
- "ON d.projectId = p.id0 " +
- "WHERE (d.projectId + 1) > ?";
-
- RelTraitDef<?>[] traitDefs = {
- ConventionTraitDef.INSTANCE
- };
-
- PlanningContext ctx = PlanningContext.builder()
- .localNodeId(F.first(nodes))
- .originatingNodeId(F.first(nodes))
- .parentContext(Contexts.empty())
- .frameworkConfig(newConfigBuilder(FRAMEWORK_CONFIG)
- .defaultSchema(schema)
- .traitDefs(traitDefs)
- .build())
- .logger(log)
- .query(sql)
- .parameters(2)
- .topologyVersion(AffinityTopologyVersion.NONE)
- .build();
-
- RelRoot relRoot;
-
- try (IgnitePlanner planner = ctx.planner()) {
- assertNotNull(planner);
-
- String qry = ctx.query();
-
- assertNotNull(qry);
-
- // Parse
- SqlNode sqlNode = planner.parse(qry);
-
- // Validate
- sqlNode = planner.validate(sqlNode);
-
- // Convert to Relational operators graph
- relRoot = planner.rel(sqlNode);
- }
-
- assertNotNull(relRoot.rel);
- }
-
- /**
- * @throws Exception If failed.
- */
- @Test
- public void testCorrelatedQuery() throws Exception {
- IgniteTypeFactory f = new IgniteTypeFactory(IgniteTypeSystem.INSTANCE);
-
- TestTable developer = new TestTable(
- new RelDataTypeFactory.Builder(f)
- .add("ID", f.createJavaType(Integer.class))
- .add("NAME", f.createJavaType(String.class))
- .add("PROJECTID", f.createJavaType(Integer.class))
- .build()) {
- };
-
- TestTable project = new TestTable(
- new RelDataTypeFactory.Builder(f)
- .add("ID", f.createJavaType(Integer.class))
- .add("NAME", f.createJavaType(String.class))
- .add("VER", f.createJavaType(Integer.class))
- .build()) {
- };
-
- IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
-
- publicSchema.addTable("DEVELOPER", developer);
- publicSchema.addTable("PROJECT", project);
-
- SchemaPlus schema = createRootSchema(false)
- .add("PUBLIC", publicSchema);
-
- String sql = "SELECT d.id, (SELECT p.name FROM Project p WHERE p.id =
d.id) name, d.projectId " +
- "FROM Developer d";
-
- RelTraitDef<?>[] traitDefs = {
- ConventionTraitDef.INSTANCE
- };
-
- PlanningContext ctx = PlanningContext.builder()
- .localNodeId(F.first(nodes))
- .originatingNodeId(F.first(nodes))
- .parentContext(Contexts.empty())
- .frameworkConfig(newConfigBuilder(FRAMEWORK_CONFIG)
- .defaultSchema(schema)
- .traitDefs(traitDefs)
- .build())
- .logger(log)
- .query(sql)
- .parameters(2)
- .topologyVersion(AffinityTopologyVersion.NONE)
- .build();
-
- RelRoot relRoot;
-
- try (IgnitePlanner planner = ctx.planner()) {
- assertNotNull(planner);
-
- String qry = ctx.query();
-
- assertNotNull(qry);
-
- // Parse
- SqlNode sqlNode = planner.parse(qry);
-
- // Validate
- sqlNode = planner.validate(sqlNode);
-
- // Convert to Relational operators graph
- relRoot = planner.rel(sqlNode);
- }
-
- assertNotNull(relRoot.rel);
- }
-
- /**
- * @throws Exception If failed.
- */
- @Test
- public void testHepPlaner() throws Exception {
- IgniteTypeFactory f = new IgniteTypeFactory(IgniteTypeSystem.INSTANCE);
-
- TestTable developer = new TestTable(
- new RelDataTypeFactory.Builder(f)
- .add("ID", f.createJavaType(Integer.class))
- .add("NAME", f.createJavaType(String.class))
- .add("PROJECTID", f.createJavaType(Integer.class))
- .build()) {
- @Override public IgniteIndex getIndex(String idxName) {
- return new IgniteIndex(null, null, null, null) {
- @Override public <Row> Iterable<Row> scan(
- ExecutionContext<Row> execCtx,
- ColocationGroup group,
- Predicate<Row> filters,
- Supplier<Row> lowerIdxConditions,
- Supplier<Row> upperIdxConditions,
- Function<Row, Row> rowTransformer,
- @Nullable ImmutableBitSet requiredColumns
- ) {
- return Linq4j.asEnumerable(Arrays.asList(
- row(execCtx, requiredColumns, 0, "Igor", 0),
- row(execCtx, requiredColumns, 1, "Roman", 0)
- ));
- }
- };
- }
-
- @Override public ColocationGroup colocationGroup(PlanningContext
ctx) {
- return ColocationGroup.forAssignments(Arrays.asList(
- select(nodes, 0, 1),
- select(nodes, 1, 2),
- select(nodes, 2, 0),
- select(nodes, 0, 1),
- select(nodes, 1, 2)
- ));
- }
-
- @Override public IgniteDistribution distribution() {
- return IgniteDistributions.affinity(0, "Developer", "hash");
- }
- };
-
- TestTable project = new TestTable(
- new RelDataTypeFactory.Builder(f)
- .add("ID", f.createJavaType(Integer.class))
- .add("NAME", f.createJavaType(String.class))
- .add("VER", f.createJavaType(Integer.class))
- .build()) {
- @Override public IgniteIndex getIndex(String idxName) {
- return new IgniteIndex(null, null, null, null) {
- @Override public <Row> Iterable<Row> scan(
- ExecutionContext<Row> execCtx,
- ColocationGroup group,
- Predicate<Row> filters,
- Supplier<Row> lowerIdxConditions,
- Supplier<Row> upperIdxConditions,
- Function<Row, Row> rowTransformer,
- @Nullable ImmutableBitSet requiredColumns
- ) {
- return Linq4j.asEnumerable(Arrays.asList(
- row(execCtx, requiredColumns, 0, "Calcite", 1),
- row(execCtx, requiredColumns, 1, "Ignite", 1)
- ));
- }
- };
- }
-
- @Override public ColocationGroup colocationGroup(PlanningContext
ctx) {
- return ColocationGroup.forAssignments(Arrays.asList(
- select(nodes, 0, 1),
- select(nodes, 1, 2),
- select(nodes, 2, 0),
- select(nodes, 0, 1),
- select(nodes, 1, 2)
- ));
- }
-
- @Override public IgniteDistribution distribution() {
- return IgniteDistributions.affinity(0, "Project", "hash");
- }
- };
-
- IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
-
- publicSchema.addTable("DEVELOPER", developer);
- publicSchema.addTable("PROJECT", project);
-
- SchemaPlus schema = createRootSchema(false)
- .add("PUBLIC", publicSchema);
-
- String sql = "SELECT d.id, d.name, d.projectId, p.id0, p.ver0 " +
- "FROM PUBLIC.Developer d JOIN (" +
- "SELECT pp.id as id0, pp.ver as ver0 FROM PUBLIC.Project pp" +
- ") p " +
- "ON d.projectId = p.id0 " +
- "WHERE (d.projectId + 1) > ?";
-
- RelTraitDef<?>[] traitDefs = {
- ConventionTraitDef.INSTANCE
- };
-
- PlanningContext ctx = PlanningContext.builder()
- .localNodeId(F.first(nodes))
- .originatingNodeId(F.first(nodes))
- .parentContext(Contexts.empty())
- .frameworkConfig(newConfigBuilder(FRAMEWORK_CONFIG)
- .defaultSchema(schema)
- .traitDefs(traitDefs)
- .build())
- .logger(log)
- .query(sql)
- .parameters(2)
- .topologyVersion(AffinityTopologyVersion.NONE)
- .build();
-
- RelRoot relRoot;
-
- try (IgnitePlanner planner = ctx.planner()) {
- assertNotNull(planner);
-
- String qry = ctx.query();
-
- assertNotNull(qry);
-
- // Parse
- SqlNode sqlNode = planner.parse(qry);
-
- // Validate
- sqlNode = planner.validate(sqlNode);
-
- // Convert to Relational operators graph
- relRoot = planner.rel(sqlNode);
-
- RelNode rel = relRoot.rel;
-
- // Transformation chain
- rel = planner.transform(PlannerPhase.HEURISTIC_OPTIMIZATION,
rel.getTraitSet(), rel);
-
- relRoot = relRoot.withRel(rel).withKind(sqlNode.getKind());
- }
-
- assertNotNull(relRoot.rel);
- }
-
- /**
- * @throws Exception If failed.
- */
- @Test
- public void testVolcanoPlanerDistributed() throws Exception {
Review comment:
All removed tests were verifying that planner could provide any result
different from NULL. I don't think these tests have any value, since now we
have extended out test coverage with lots of different tests that verifies
every particular feature and uses a much smarter assertions.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]