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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
Aggregations