public static SqlSchema getSourceSqlSchema(RelSchemaProvider relSchemaProvider) {
    SqlSchema sqlSchema = relSchemaProvider.getSqlSchema();

    List<String> fieldNames = new ArrayList<>();
    List<SqlFieldSchema> fieldTypes = new ArrayList<>();
    if (!sqlSchema.containsField(SamzaSqlRelMessage.KEY_NAME)) {
      fieldNames.add(SamzaSqlRelMessage.KEY_NAME);
      // Key is a nullable and optional field. It is defaulted to null in SamzaSqlRelMessage.
      fieldTypes.add(SqlFieldSchema.createPrimitiveSchema(SamzaSqlFieldType.ANY, true, true));
    }

    fieldNames.addAll(
        sqlSchema.getFields().stream().map(SqlSchema.SqlField::getFieldName).collect(Collectors.toList()));
    fieldTypes.addAll(
        sqlSchema.getFields().stream().map(SqlSchema.SqlField::getFieldSchema).collect(Collectors.toList()));

    return new SqlSchema(fieldNames, fieldTypes);
  }
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