atoomula commented on a change in pull request #1386:
URL: https://github.com/apache/samza/pull/1386#discussion_r457129009



##########
File path: 
samza-sql/src/main/java/org/apache/samza/sql/planner/QueryPlanner.java
##########
@@ -110,46 +114,50 @@ private void registerSourceSchemas(SchemaPlus rootSchema) 
{
   }
 
   public RelRoot plan(String query) {
-    try {
-      Connection connection = DriverManager.getConnection("jdbc:calcite:");
-      CalciteConnection calciteConnection = 
connection.unwrap(CalciteConnection.class);
-      SchemaPlus rootSchema = calciteConnection.getRootSchema();
-      registerSourceSchemas(rootSchema);
-
-      List<SamzaSqlScalarFunctionImpl> samzaSqlFunctions = udfMetadata.stream()
-          .map(x -> new SamzaSqlScalarFunctionImpl(x))
-          .collect(Collectors.toList());
-
-      final List<RelTraitDef> traitDefs = new ArrayList<>();
-
-      traitDefs.add(ConventionTraitDef.INSTANCE);
-      traitDefs.add(RelCollationTraitDef.INSTANCE);
-
-      List<SqlOperatorTable> sqlOperatorTables = new ArrayList<>();
-      sqlOperatorTables.add(new SamzaSqlOperatorTable());
-      sqlOperatorTables.add(new SamzaSqlUdfOperatorTable(samzaSqlFunctions));
-
-      // Using lenient so that !=,%,- are allowed.
-      FrameworkConfig frameworkConfig = Frameworks.newConfigBuilder()
-          .parserConfig(SqlParser.configBuilder()
-              .setLex(Lex.JAVA)
-              .setConformance(SqlConformanceEnum.LENIENT)
-              .setCaseSensitive(false) // Make Udfs case insensitive
-              .build())
-          .defaultSchema(rootSchema)
-          .operatorTable(new ChainedSqlOperatorTable(sqlOperatorTables))
-          .sqlToRelConverterConfig(SqlToRelConverter.Config.DEFAULT)
-          .traitDefs(traitDefs)
-          .context(Contexts.EMPTY_CONTEXT)
-          .costFactory(null)
-          .build();
-      Planner planner = Frameworks.getPlanner(frameworkConfig);
-
+    SchemaPlus rootSchema = CalciteSchema.createRootSchema(true, false).plus();
+    registerSourceSchemas(rootSchema);
+
+    List<SamzaSqlScalarFunctionImpl> samzaSqlFunctions =
+        udfMetadata.stream().map(x -> new 
SamzaSqlScalarFunctionImpl(x)).collect(Collectors.toList());
+
+    final List<RelTraitDef> traitDefs = new ArrayList<>();
+
+    traitDefs.add(ConventionTraitDef.INSTANCE);
+    traitDefs.add(RelCollationTraitDef.INSTANCE);
+
+    List<SqlOperatorTable> sqlOperatorTables = new ArrayList<>();
+    sqlOperatorTables.add(new SamzaSqlOperatorTable());
+    sqlOperatorTables.add(new SamzaSqlUdfOperatorTable(samzaSqlFunctions));
+
+    // Using lenient so that !=,%,- are allowed.
+    FrameworkConfig frameworkConfig = Frameworks.newConfigBuilder()
+        .parserConfig(SqlParser.configBuilder()
+            .setLex(Lex.JAVA)
+            .setConformance(SqlConformanceEnum.LENIENT)
+            .setCaseSensitive(false) // Make Udfs case insensitive
+            .build())
+        .defaultSchema(rootSchema)
+        .operatorTable(new ChainedSqlOperatorTable(sqlOperatorTables))
+        .sqlToRelConverterConfig(SqlToRelConverter.Config.DEFAULT)
+        .traitDefs(traitDefs)
+        .context(Contexts.EMPTY_CONTEXT)
+        .programs(
+            Programs.hep(ImmutableList.of(FilterJoinRule.FILTER_ON_JOIN), 
true, DefaultRelMetadataProvider.INSTANCE))
+        .build();
+
+    // Planner is a auto closable
+    try (Planner planner = Frameworks.getPlanner(frameworkConfig)) {
       SqlNode sql = planner.parse(query);
       SqlNode validatedSql = planner.validate(sql);
       RelRoot relRoot = planner.rel(validatedSql);
       LOG.info("query plan:\n" + RelOptUtil.toString(relRoot.rel, 
SqlExplainLevel.ALL_ATTRIBUTES));
-      return relRoot;
+      RelTraitSet relTraitSet = RelTraitSet.createEmpty();

Review comment:
       Could you pull in the latest master branch code ? I have pushed Query 
optimization code which conflicts with your changes.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to