Java Code Examples for org.apache.calcite.avatica.AvaticaStatement#executeQuery()

The following examples show how to use org.apache.calcite.avatica.AvaticaStatement#executeQuery() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JdbcRemoteTest.java    From Quicksql with MIT License 6 votes vote down vote up
@Test
public void testQueryMetaData() {
    try {
        AvaticaConnection conn = getConnection();
        final AvaticaStatement statement = conn.createStatement();
        ResultSet rs = statement.executeQuery("select * from (values (1, 'a'), (2, 'b'))");
        if (rs.getMetaData() != null) {
            System.out.println(rs.getMetaData().getColumnCount());
            System.out.println(rs.getMetaData().getColumnName(1));
            System.out.println(rs.getMetaData().getColumnName(2));
        }
        close(rs, statement,conn);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 2
Source File: RemoteMetaTest.java    From calcite-avatica with Apache License 2.0 6 votes vote down vote up
@Test public void testUnicodeCharacters() throws Exception {
  ConnectionSpec.getDatabaseLock().lock();
  try (AvaticaConnection conn = (AvaticaConnection) DriverManager.getConnection(url)) {
    final AvaticaStatement statement = conn.createStatement();
    ResultSet rs = statement.executeQuery(
        "select * from (values ('您好', 'こんにちは', '안녕하세요'))");
    assertThat(rs.next(), is(true));
    assertEquals("您好", rs.getString(1));
    assertEquals("こんにちは", rs.getString(2));
    assertEquals("안녕하세요", rs.getString(3));
    rs.close();
    statement.close();
    conn.close();
  } finally {
    ConnectionSpec.getDatabaseLock().unlock();
  }
}
 
Example 3
Source File: JdbcRemoteTest.java    From Quicksql with MIT License 5 votes vote down vote up
@Test
public void testExecuteQuery() {
    try {
        AvaticaConnection conn = getConnection();
        final AvaticaStatement statement = conn.createStatement();
        ResultSet rs = statement.executeQuery("select * from (values (1, 'a'), (2, 'b'))");
        while (rs.next()) {
            System.out.println(rs.getString(1));
            System.out.println(rs.getString(2));
        }
        close(rs, statement,conn);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 4
Source File: JdbcRemoteTest.java    From Quicksql with MIT License 5 votes vote down vote up
@Test
public void testInsertQuery() {
    try {
        AvaticaConnection conn = getConnection();
        final AvaticaStatement statement = conn.createStatement();
        ResultSet rs = statement.executeQuery("INSERT INTO `hdfs://cluster:9000/` IN HDFS SELECT 1");
        while (rs.next()) {
            System.out.println(rs.getInt(1));
        }
        close(rs, statement,conn);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 5
Source File: RemoteMetaTest.java    From calcite-avatica with Apache License 2.0 5 votes vote down vote up
/** 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();
  }
}