Runs a relational expression by creating a JDBC connection.
(RelNode rel)
| 36 | |
| 37 | /** Runs a relational expression by creating a JDBC connection. */ |
| 38 | public static PreparedStatement run(RelNode rel) { |
| 39 | final RelShuttle shuttle = new RelHomogeneousShuttle() { |
| 40 | @Override public RelNode visit(TableScan scan) { |
| 41 | final RelOptTable table = scan.getTable(); |
| 42 | if (scan instanceof LogicalTableScan |
| 43 | && Bindables.BindableTableScan.canHandle(table)) { |
| 44 | // Always replace the LogicalTableScan with BindableTableScan |
| 45 | // because it's implementation does not require a "schema" as context. |
| 46 | return Bindables.BindableTableScan.create(scan.getCluster(), table); |
| 47 | } |
| 48 | return super.visit(scan); |
| 49 | } |
| 50 | }; |
| 51 | rel = rel.accept(shuttle); |
| 52 | try (Connection connection = DriverManager.getConnection("jdbc:calcite:")) { |
| 53 | final RelRunner runner = connection.unwrap(RelRunner.class); |
| 54 | return runner.prepareStatement(rel); |
| 55 | } catch (SQLException e) { |
| 56 | throw Util.throwAsRuntime(e); |
| 57 | } |
| 58 | } |
| 59 | } |