private Planner getPlanner() {
    Planner planner = null;
    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(SamzaSqlScalarFunctionImpl::new)
          .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));

      // TODO: Introduce a pluggable rule factory.
      List<RelOptRule> rules = ImmutableList.of(
          FilterProjectTransposeRule.INSTANCE,
          ProjectMergeRule.INSTANCE,
          new SamzaSqlFilterRemoteJoinRule.SamzaSqlFilterIntoRemoteJoinRule(true, RelFactories.LOGICAL_BUILDER,
          systemStreamConfigBySource));

      // 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)
          .programs(Programs.hep(rules, true, DefaultRelMetadataProvider.INSTANCE))
          .build();
      planner = Frameworks.getPlanner(frameworkConfig);
      return planner;
    } catch (Exception e) {
      String errorMsg = "Failed to create planner.";
      LOG.error(errorMsg, e);
      if (planner != null) {
        planner.close();
      }
      throw new SamzaException(errorMsg, e);
    }
  }
QueryPlanner that uses calcite engine to convert the sql query to relational graph.
samza-sql/src/main/java/org/apache/samza/sql/planner/QueryPlanner.java