Search in sources :

Example 1 with AvaticaStatement

use of org.apache.calcite.avatica.AvaticaStatement in project calcite-avatica by apache.

the class RemoteMetaTest method testRemoteExecuteMaxRowCount.

@Test
public void testRemoteExecuteMaxRowCount() throws Exception {
    ConnectionSpec.getDatabaseLock().lock();
    try (AvaticaConnection conn = (AvaticaConnection) DriverManager.getConnection(url)) {
        final AvaticaStatement statement = conn.createStatement();
        prepareAndExecuteInternal(conn, statement, "select * from (values ('a', 1), ('b', 2))", 0);
        ResultSet rs = statement.getResultSet();
        int count = 0;
        while (rs.next()) {
            count++;
        }
        assertEquals("Check maxRowCount=0 and ResultSets is 0 row", count, 0);
        assertEquals("Check result set meta is still there", rs.getMetaData().getColumnCount(), 2);
        rs.close();
        statement.close();
        conn.close();
    } finally {
        ConnectionSpec.getDatabaseLock().unlock();
    }
}
Also used : AvaticaConnection(org.apache.calcite.avatica.AvaticaConnection) ResultSet(java.sql.ResultSet) AvaticaStatement(org.apache.calcite.avatica.AvaticaStatement) Test(org.junit.Test)

Example 2 with AvaticaStatement

use of org.apache.calcite.avatica.AvaticaStatement in project calcite-avatica by apache.

the class RemoteMetaTest method checkLargeQuery.

private void checkLargeQuery(int n) throws Exception {
    try (AvaticaConnection conn = (AvaticaConnection) DriverManager.getConnection(url)) {
        final AvaticaStatement statement = conn.createStatement();
        final String frenchDisko = "It said human existence is pointless\n" + "As acts of rebellious solidarity\n" + "Can bring sense in this world\n" + "La resistance!\n";
        final String sql = "select '" + longString(frenchDisko, n) + "' as s from (values 'x')";
        prepareAndExecuteInternal(conn, statement, sql, -1);
        ResultSet rs = statement.getResultSet();
        int count = 0;
        while (rs.next()) {
            count++;
        }
        assertThat(count, is(1));
        rs.close();
        statement.close();
        conn.close();
    }
}
Also used : AvaticaConnection(org.apache.calcite.avatica.AvaticaConnection) ResultSet(java.sql.ResultSet) StringContains.containsString(org.hamcrest.core.StringContains.containsString) AvaticaStatement(org.apache.calcite.avatica.AvaticaStatement)

Example 3 with AvaticaStatement

use of org.apache.calcite.avatica.AvaticaStatement in project calcite-avatica by apache.

the class AlternatingRemoteMetaTest method testRemoteExecuteMaxRowCount.

@Test
public void testRemoteExecuteMaxRowCount() throws Exception {
    ConnectionSpec.getDatabaseLock().lock();
    try (AvaticaConnection conn = (AvaticaConnection) DriverManager.getConnection(url)) {
        final AvaticaStatement statement = conn.createStatement();
        prepareAndExecuteInternal(conn, statement, "select * from (values ('a', 1), ('b', 2))", 0);
        ResultSet rs = statement.getResultSet();
        int count = 0;
        while (rs.next()) {
            count++;
        }
        assertEquals("Check maxRowCount=0 and ResultSets is 0 row", count, 0);
        assertEquals("Check result set meta is still there", rs.getMetaData().getColumnCount(), 2);
        rs.close();
        statement.close();
        conn.close();
    } finally {
        ConnectionSpec.getDatabaseLock().unlock();
    }
}
Also used : AvaticaConnection(org.apache.calcite.avatica.AvaticaConnection) ResultSet(java.sql.ResultSet) AvaticaStatement(org.apache.calcite.avatica.AvaticaStatement) Test(org.junit.Test)

Example 4 with AvaticaStatement

use of org.apache.calcite.avatica.AvaticaStatement in project calcite-avatica by apache.

the class AlternatingRemoteMetaTest method checkLargeQuery.

private void checkLargeQuery(int n) throws Exception {
    try (AvaticaConnection conn = (AvaticaConnection) DriverManager.getConnection(url)) {
        final AvaticaStatement statement = conn.createStatement();
        final String frenchDisko = "It said human existence is pointless\n" + "As acts of rebellious solidarity\n" + "Can bring sense in this world\n" + "La resistance!\n";
        final String sql = "select '" + longString(frenchDisko, n) + "' as s from (values 'x')";
        prepareAndExecuteInternal(conn, statement, sql, -1);
        ResultSet rs = statement.getResultSet();
        int count = 0;
        while (rs.next()) {
            count++;
        }
        assertThat(count, is(1));
        rs.close();
        statement.close();
        conn.close();
    }
}
Also used : AvaticaConnection(org.apache.calcite.avatica.AvaticaConnection) ResultSet(java.sql.ResultSet) AvaticaStatement(org.apache.calcite.avatica.AvaticaStatement)

Example 5 with AvaticaStatement

use of org.apache.calcite.avatica.AvaticaStatement in project calcite-avatica by apache.

the class RemoteMetaTest method testCancel.

/** Test case for
   * <a href="https://issues.apache.org/jira/browse/CALCITE-1301">[CALCITE-1301]
   * Add cancel flag to AvaticaStatement</a>. */
@Test
public void testCancel() throws Exception {
    ConnectionSpec.getDatabaseLock().lock();
    try (AvaticaConnection conn = (AvaticaConnection) DriverManager.getConnection(url)) {
        final AvaticaStatement statement = conn.createStatement();
        final String sql = "select * from (values ('a', 1), ('b', 2))";
        final ResultSet rs = statement.executeQuery(sql);
        int count = 0;
        loop: for (; ; ) {
            switch(count++) {
                case 0:
                    assertThat(rs.next(), is(true));
                    break;
                case 1:
                    rs.getStatement().cancel();
                    try {
                        boolean x = rs.next();
                        fail("expected exception, got " + x);
                    } catch (SQLException e) {
                        assertThat(e.getMessage(), is("Statement canceled"));
                    }
                    break loop;
                default:
                    fail("count: " + count);
            }
        }
        assertThat(count, is(2));
        assertThat(statement.isClosed(), is(false));
        rs.close();
        assertThat(statement.isClosed(), is(false));
        statement.close();
        assertThat(statement.isClosed(), is(true));
        statement.close();
        assertThat(statement.isClosed(), is(true));
    } finally {
        ConnectionSpec.getDatabaseLock().unlock();
    }
}
Also used : AvaticaConnection(org.apache.calcite.avatica.AvaticaConnection) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) StringContains.containsString(org.hamcrest.core.StringContains.containsString) AvaticaStatement(org.apache.calcite.avatica.AvaticaStatement) Test(org.junit.Test)

Aggregations

AvaticaStatement (org.apache.calcite.avatica.AvaticaStatement)6 ResultSet (java.sql.ResultSet)5 AvaticaConnection (org.apache.calcite.avatica.AvaticaConnection)5 Test (org.junit.Test)3 SQLException (java.sql.SQLException)2 StringContains.containsString (org.hamcrest.core.StringContains.containsString)2 DrillRuntimeException (org.apache.drill.common.exceptions.DrillRuntimeException)1 RpcException (org.apache.drill.exec.rpc.RpcException)1