|
47 | 47 | import org.apache.beam.sdk.transforms.SerializableFunction; |
48 | 48 | import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.jdbc.CalcitePrepare; |
49 | 49 | import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.plan.RelOptUtil; |
| 50 | +import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.rel.RelNode; |
50 | 51 | import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.schema.Function; |
51 | 52 | import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.sql.SqlKind; |
| 53 | +import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.tools.RelBuilder; |
52 | 54 | import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.tools.RuleSet; |
53 | 55 | import org.checkerframework.checker.nullness.qual.Nullable; |
| 56 | +import org.slf4j.Logger; |
| 57 | +import org.slf4j.LoggerFactory; |
54 | 58 |
|
55 | 59 | /** |
56 | 60 | * Contains the metadata of tables/UDF functions, and exposes APIs to |
57 | 61 | * query/validate/optimize/translate SQL statements. |
58 | 62 | */ |
59 | 63 | @Internal |
60 | 64 | public class BeamSqlEnv { |
| 65 | + private static final Logger LOG = LoggerFactory.getLogger(BeamSqlEnv.class); |
| 66 | + |
61 | 67 | JdbcConnection connection; |
62 | 68 | QueryPlanner planner; |
63 | 69 |
|
@@ -116,6 +122,31 @@ public BeamRelNode parseQuery(String query, QueryParameters queryParameters) |
116 | 122 | return planner.convertToBeamRel(query, queryParameters); |
117 | 123 | } |
118 | 124 |
|
| 125 | + public QueryPlanner getPlanner() { |
| 126 | + return planner; |
| 127 | + } |
| 128 | + |
| 129 | + public RelBuilder getRelBuilder() { |
| 130 | + return planner.getRelBuilder(); |
| 131 | + } |
| 132 | + |
| 133 | + public BeamRelNode convertToBeamRel(RelNode relNode) { |
| 134 | + return planner.convertToBeamRel(relNode, QueryParameters.ofNone()); |
| 135 | + } |
| 136 | + |
| 137 | + public RelNode parseLogicalPlan(String query) throws ParseException { |
| 138 | + return planner.parseToRel(query, QueryParameters.ofNone()); |
| 139 | + } |
| 140 | + |
| 141 | + public void registerSchemaFunction(String name, Function function) { |
| 142 | + connection.getCurrentSchemaPlus().add(name, function); |
| 143 | + } |
| 144 | + |
| 145 | + public org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.sql.SqlOperatorTable |
| 146 | + getOperatorTable() { |
| 147 | + return planner.getOperatorTable(); |
| 148 | + } |
| 149 | + |
119 | 150 | public boolean isDdl(String sqlStatement) throws ParseException { |
120 | 151 | return planner.parse(sqlStatement).getKind().belongsTo(SqlKind.DDL); |
121 | 152 | } |
@@ -196,6 +227,7 @@ public BeamSqlEnvBuilder setCurrentSchema(String name) { |
196 | 227 |
|
197 | 228 | /** Set the ruleSet used for query optimizer. */ |
198 | 229 | public BeamSqlEnvBuilder setRuleSets(Collection<RuleSet> ruleSets) { |
| 230 | + LOG.info("Setting BeamSqlEnv rulesets to: {}", ruleSets); |
199 | 231 | this.ruleSets = ruleSets; |
200 | 232 | return this; |
201 | 233 | } |
@@ -262,6 +294,7 @@ public BeamSqlEnv build() { |
262 | 294 |
|
263 | 295 | configureSchemas(jdbcConnection); |
264 | 296 |
|
| 297 | + LOG.info("Instantiating planner with ruleSets: {}", ruleSets); |
265 | 298 | QueryPlanner planner = instantiatePlanner(jdbcConnection, ruleSets); |
266 | 299 |
|
267 | 300 | // The planner may choose to add its own builtin functions to the schema, so load user-defined |
|
0 commit comments