public RelRoot plan(String query) {
    try (Planner planner = getPlanner()) {
      SqlNode sql = planner.parse(query);
      SqlNode validatedSql = planner.validate(sql);
      RelRoot relRoot = planner.rel(validatedSql);
      LOG.info(
          "query plan without optimization:\n" + RelOptUtil.toString(relRoot.rel, SqlExplainLevel.EXPPLAN_ATTRIBUTES));
      if (!isQueryPlanOptimizerEnabled) {
        LOG.info("Skipping query optimization as it is disabled.");
        return relRoot;
      }
      return optimize(planner, relRoot);
    } catch (Exception e) {
      String errorMsg = SamzaSqlValidator.formatErrorString(query, e);
      LOG.error(errorMsg, e);
      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