use of org.apache.calcite.avatica.AvaticaConnection in project calcite-avatica by apache.
the class Driver method connect.
@Override
public Connection connect(String url, Properties info) throws SQLException {
AvaticaConnection conn = (AvaticaConnection) super.connect(url, info);
if (conn == null) {
// It's not an url for our driver
return null;
}
Service service = conn.getService();
// super.connect(...) should be creating a service and setting it in the AvaticaConnection
assert null != service;
service.apply(new Service.OpenConnectionRequest(conn.id, Service.OpenConnectionRequest.serializeProperties(info)));
return conn;
}
use of org.apache.calcite.avatica.AvaticaConnection in project calcite-avatica by apache.
the class RemoteMetaTest method testRemoteStatementInsert.
@Test
public void testRemoteStatementInsert() throws Exception {
ConnectionSpec.getDatabaseLock().lock();
try {
final String t = AvaticaUtils.unique("TEST_TABLE2");
AvaticaConnection conn = (AvaticaConnection) DriverManager.getConnection(url);
Statement statement = conn.createStatement();
final String create = String.format(Locale.ROOT, "create table if not exists %s (" + " id int not null, msg varchar(255) not null)", t);
int status = statement.executeUpdate(create);
assertEquals(status, 0);
statement = conn.createStatement();
final String update = String.format(Locale.ROOT, "insert into %s values ('%d', '%s')", t, RANDOM.nextInt(Integer.MAX_VALUE), UUID.randomUUID());
status = statement.executeUpdate(update);
assertEquals(status, 1);
} finally {
ConnectionSpec.getDatabaseLock().unlock();
}
}
use of org.apache.calcite.avatica.AvaticaConnection 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.AvaticaConnection in project calcite-avatica by apache.
the class RemoteMetaTest method testArrays.
@Test
public void testArrays() throws SQLException {
ConnectionSpec.getDatabaseLock().lock();
try (AvaticaConnection conn = (AvaticaConnection) DriverManager.getConnection(url);
Statement stmt = conn.createStatement()) {
ResultSet resultSet = stmt.executeQuery("select * from (values ('a', array['b', 'c']));");
assertTrue(resultSet.next());
assertEquals("a", resultSet.getString(1));
Array arr = resultSet.getArray(2);
assertTrue(arr instanceof ArrayImpl);
Object[] values = (Object[]) ((ArrayImpl) arr).getArray();
assertArrayEquals(new String[] { "b", "c" }, values);
} finally {
ConnectionSpec.getDatabaseLock().unlock();
}
}
use of org.apache.calcite.avatica.AvaticaConnection 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();
}
}
Aggregations