private CachedStatement buildCachedStatement(final String sql, final Supplier<CalciteConnection> connectionSupplier, final ProcessSession session, final FlowFile flowFile, final RecordReaderFactory recordReaderFactory) throws SQLException { final CalciteConnection connection = connectionSupplier.get(); final SchemaPlus rootSchema = connection.getRootSchema(); final FlowFileTable<?, ?> flowFileTable = new FlowFileTable<>(session, flowFile, recordReaderFactory, getLogger()); rootSchema.add("FLOWFILE", flowFileTable); rootSchema.setCacheEnabled(false); final PreparedStatement stmt = connection.prepareStatement(sql); return new CachedStatement(stmt, flowFileTable, connection); }
private CachedStatement buildCachedStatement(final String sql, final Supplier<CalciteConnection> connectionSupplier, final ProcessSession session, final FlowFile flowFile, final RecordReaderFactory recordReaderFactory) throws SQLException { final CalciteConnection connection = connectionSupplier.get(); final SchemaPlus rootSchema = connection.getRootSchema(); final FlowFileTable<?, ?> flowFileTable = new FlowFileTable<>(session, flowFile, recordReaderFactory, getLogger()); rootSchema.add("FLOWFILE", flowFileTable); rootSchema.setCacheEnabled(false); final PreparedStatement stmt = connection.prepareStatement(sql); return new CachedStatement(stmt, flowFileTable, connection); }
try { final PreparedStatement statement = connection.prepareStatement("VALUES CURRENT_TIMESTAMP"); ResultSet resultSet;
private void checkPreparedOffsetFetch(final int offset, final int fetch, final Matcher<? super ResultSet> matcher) throws Exception { CalciteAssert.hr() .doWithConnection(connection -> { final String sql = "select \"name\"\n" + "from \"hr\".\"emps\"\n" + "order by \"empid\" offset ? fetch next ? rows only"; try (PreparedStatement p = connection.prepareStatement(sql)) { final ParameterMetaData pmd = p.getParameterMetaData(); assertThat(pmd.getParameterCount(), is(2)); assertThat(pmd.getParameterType(1), is(Types.INTEGER)); assertThat(pmd.getParameterType(2), is(Types.INTEGER)); p.setInt(1, offset); p.setInt(2, fetch); try (ResultSet r = p.executeQuery()) { assertThat(r, matcher); } } catch (SQLException e) { throw new RuntimeException(e); } }); }
try { final PreparedStatement statement = connection.prepareStatement("VALUES CURRENT_TIMESTAMP"); ResultSet resultSet;
private void checkPreparedOffsetFetch(final int offset, final int fetch, final Matcher<? super ResultSet> matcher) throws Exception { CalciteAssert.hr() .doWithConnection(connection -> { final String sql = "select \"name\"\n" + "from \"hr\".\"emps\"\n" + "order by \"empid\" offset ? fetch next ? rows only"; try (PreparedStatement p = connection.prepareStatement(sql)) { final ParameterMetaData pmd = p.getParameterMetaData(); assertThat(pmd.getParameterCount(), is(2)); assertThat(pmd.getParameterType(1), is(Types.INTEGER)); assertThat(pmd.getParameterType(2), is(Types.INTEGER)); p.setInt(1, offset); p.setInt(2, fetch); try (ResultSet r = p.executeQuery()) { assertThat(r, matcher); } } catch (SQLException e) { throw new RuntimeException(e); } }); }
try { final PreparedStatement preparedStatement = connection.prepareStatement("select \"deptno\", \"name\" " + "from \"hr\".\"emps\"\n" + "where \"deptno\" < ? and \"name\" like ?"); + "order by 2"; final PreparedStatement preparedStatement2 = connection.prepareStatement(sql2); preparedStatement2.setInt(1, 15); preparedStatement2.setInt(2, 5);
try { final PreparedStatement preparedStatement = connection.prepareStatement("select \"deptno\", \"name\" " + "from \"hr\".\"emps\"\n" + "where \"deptno\" < ? and \"name\" like ?"); + "order by 2"; final PreparedStatement preparedStatement2 = connection.prepareStatement(sql2); preparedStatement2.setInt(1, 15); preparedStatement2.setInt(2, 5);
final String sql = "select * from \"TEST\".\"TENS\" where \"i\" < ?"; final PreparedStatement statement = calciteConnection.prepareStatement(sql); assertThat(scanCount.get(), is(0)); assertThat(enumerateCount.get(), is(0));
CalciteAssert.that(config) .doWithConnection(c -> { try (PreparedStatement s = c.prepareStatement(sql)) { final ResultSetMetaData m = s.getMetaData(); final List<Profiler.Column> columns = new ArrayList<>();
CalciteAssert.that(config) .doWithConnection(c -> { try (PreparedStatement s = c.prepareStatement(sql)) { final ResultSetMetaData m = s.getMetaData(); final List<Profiler.Column> columns = new ArrayList<>();
@Test public void testInsertBind() throws Exception { final List<JdbcTest.Employee> employees = new ArrayList<>(); CalciteAssert.AssertThat with = mutable(employees); with.query("select count(*) as c from \"foo\".\"bar\"") .returns("C=1\n"); with.doWithConnection(c -> { try { final String sql = "insert into \"foo\".\"bar\"\n" + "values (?, 0, ?, 10.0, null)"; try (PreparedStatement p = c.prepareStatement(sql)) { p.setInt(1, 1); p.setString(2, "foo"); final int count = p.executeUpdate(); assertThat(count, is(1)); } } catch (SQLException e) { throw new RuntimeException(e); } }); with.query("select count(*) as c from \"foo\".\"bar\"") .returns("C=2\n"); with.query("select * from \"foo\".\"bar\"") .returnsUnordered("empid=0; deptno=0; name=first; salary=0.0; commission=null", "empid=1; deptno=0; name=foo; salary=10.0; commission=null"); }
final String sql = "select * from \"TEST\".\"TENS\" where \"i\" < ?"; final PreparedStatement statement = calciteConnection.prepareStatement(sql); assertThat(scanCount.get(), is(0)); assertThat(enumerateCount.get(), is(0));
@Test public void testInsertBind() throws Exception { final List<JdbcTest.Employee> employees = new ArrayList<>(); CalciteAssert.AssertThat with = mutable(employees); with.query("select count(*) as c from \"foo\".\"bar\"") .returns("C=1\n"); with.doWithConnection(c -> { try { final String sql = "insert into \"foo\".\"bar\"\n" + "values (?, 0, ?, 10.0, null)"; try (PreparedStatement p = c.prepareStatement(sql)) { p.setInt(1, 1); p.setString(2, "foo"); final int count = p.executeUpdate(); assertThat(count, is(1)); } } catch (SQLException e) { throw new RuntimeException(e); } }); with.query("select count(*) as c from \"foo\".\"bar\"") .returns("C=2\n"); with.query("select * from \"foo\".\"bar\"") .returnsUnordered("empid=0; deptno=0; name=first; salary=0.0; commission=null", "empid=1; deptno=0; name=foo; salary=10.0; commission=null"); }
connection.prepareStatement("explain plan for\n" + "insert into \"adhoc\".V (empno, \"salary\", \"name\")\n" + "values (56, 123.4, 'Fred')"); connection.prepareStatement("explain plan for\n" + "insert into \"adhoc\".V (e, name)\n" + "values (56, 'Fred')");
connection.prepareStatement("explain plan for\n" + "insert into \"adhoc\".V (empno, \"salary\", \"name\")\n" + "values (56, 123.4, 'Fred')"); connection.prepareStatement("explain plan for\n" + "insert into \"adhoc\".V (e, name)\n" + "values (56, 'Fred')");