xtern commented on code in PR #1101:
URL: https://github.com/apache/ignite-3/pull/1101#discussion_r975476103
##########
modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/PlannerTest.java:
##########
@@ -860,6 +866,81 @@ public void correctPlanningWithOrToUnion() throws
Exception {
assertPlan(sql, publicSchema, (k) -> true);
}
+ @Test
+ public void checkTableHintsHandling() throws Exception {
+ IgniteTypeFactory f = new IgniteTypeFactory(IgniteTypeSystem.INSTANCE);
+
+ TestTable person = new TestTable(
+ new RelDataTypeFactory.Builder(f)
+ .add("PK", f.createJavaType(Integer.class))
+ .add("ORG_ID", f.createJavaType(Integer.class))
+ .build()) {
+
+ @Override public IgniteDistribution distribution() {
+ return IgniteDistributions.affinity(0, "ignored", "ignored");
+ }
+ };
+
+ TestTable company = new TestTable(
+ new RelDataTypeFactory.Builder(f)
+ .add("PK", f.createJavaType(Integer.class))
+ .add("ID", f.createJavaType(Integer.class))
+ .build()) {
+
+ @Override public IgniteDistribution distribution() {
+ return IgniteDistributions.affinity(0, "ignored", "ignored");
+ }
+ };
+
+ IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
+
+ publicSchema.addTable("PERSON", person);
+ publicSchema.addTable("COMPANY", company);
+
+ SchemaPlus schema = createRootSchema(false)
+ .add("PUBLIC", publicSchema);
+
+ String sql = "SELECT * FROM person /*+ use_index(ORG_ID), extra */ t1
JOIN company /*+ use_index(ID) */ t2 ON t1.org_id = t2.id";
+
+ PlanningContext ctx = PlanningContext.builder()
+ .parentContext(BaseQueryContext.builder()
+ .logger(log)
+ .frameworkConfig(newConfigBuilder(FRAMEWORK_CONFIG)
+ .defaultSchema(schema)
+ .sqlToRelConverterConfig(FRAMEWORK_CONFIG
+ .getSqlToRelConverterConfig()
+
.withHintStrategyTable(HintStrategyTable.builder()
+ .hintStrategy("use_index",
(hint, rel) -> true)
+ .hintStrategy("extra", (hint,
rel) -> true)
+ .build()
+ ))
+ .build())
+ .build())
+ .query(sql)
+ .build();
+
+ IgniteRel plan = physicalPlan(sql, ctx);
+
+ Map<String, Integer> hintsMap = new HashMap<>();
+
+ plan.accept(new RelShuttleImpl() {
Review Comment:
> I think it worth to provide the proper implementation of
`org.apache.calcite.rel.hint.Hintable#withHints` as well. Otherwise there is a
chance that hints will be lost after applying some transformations
Done, thanks.
##########
modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/PlannerTest.java:
##########
@@ -860,6 +866,81 @@ public void correctPlanningWithOrToUnion() throws
Exception {
assertPlan(sql, publicSchema, (k) -> true);
}
+ @Test
+ public void checkTableHintsHandling() throws Exception {
+ IgniteTypeFactory f = new IgniteTypeFactory(IgniteTypeSystem.INSTANCE);
+
+ TestTable person = new TestTable(
+ new RelDataTypeFactory.Builder(f)
+ .add("PK", f.createJavaType(Integer.class))
+ .add("ORG_ID", f.createJavaType(Integer.class))
+ .build()) {
+
+ @Override public IgniteDistribution distribution() {
+ return IgniteDistributions.affinity(0, "ignored", "ignored");
+ }
+ };
+
+ TestTable company = new TestTable(
+ new RelDataTypeFactory.Builder(f)
+ .add("PK", f.createJavaType(Integer.class))
+ .add("ID", f.createJavaType(Integer.class))
+ .build()) {
+
+ @Override public IgniteDistribution distribution() {
+ return IgniteDistributions.affinity(0, "ignored", "ignored");
+ }
+ };
+
+ IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
+
+ publicSchema.addTable("PERSON", person);
+ publicSchema.addTable("COMPANY", company);
+
+ SchemaPlus schema = createRootSchema(false)
+ .add("PUBLIC", publicSchema);
+
+ String sql = "SELECT * FROM person /*+ use_index(ORG_ID), extra */ t1
JOIN company /*+ use_index(ID) */ t2 ON t1.org_id = t2.id";
+
+ PlanningContext ctx = PlanningContext.builder()
+ .parentContext(BaseQueryContext.builder()
+ .logger(log)
+ .frameworkConfig(newConfigBuilder(FRAMEWORK_CONFIG)
+ .defaultSchema(schema)
+ .sqlToRelConverterConfig(FRAMEWORK_CONFIG
+ .getSqlToRelConverterConfig()
+
.withHintStrategyTable(HintStrategyTable.builder()
+ .hintStrategy("use_index",
(hint, rel) -> true)
+ .hintStrategy("extra", (hint,
rel) -> true)
+ .build()
+ ))
+ .build())
+ .build())
+ .query(sql)
+ .build();
+
+ IgniteRel plan = physicalPlan(sql, ctx);
+
+ Map<String, Integer> hintsMap = new HashMap<>();
+
+ plan.accept(new RelShuttleImpl() {
Review Comment:
Thanks, I have updated the test, please have a look.
--
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]