ClickHouse / clickhouse-java

ClickHouse Java Clients & JDBC Driver
https://clickhouse.com
Apache License 2.0
1.45k stars 537 forks source link

external data jdbc does not work #891

Open den-crane opened 2 years ago

den-crane commented 2 years ago
    public static void main(String[] args) throws SQLException {
         final String DB_URL = "jdbc:clickhouse://github.demo.trial.altinity.cloud:8443?&ssl=true";
         final String USER = "demo";
         final String PASS = "demo";
         final String QUERY = "SELECT count() FROM (select 3 x) WHERE x IN { tt 'table1' }";

        ClickHouseExternalTable build = ClickHouseExternalTable.builder().name("table1").columns("id Int8")
                .format(ClickHouseFormat.TSV)
                .content(new ByteArrayInputStream("1".getBytes(StandardCharsets.US_ASCII)))
                .build();

        Connection conn = DriverManager.getConnection(DB_URL, USER, PASS);
        PreparedStatement stmt = conn.prepareStatement(QUERY);
        stmt.setObject(1, build);
        ResultSet rs = stmt.executeQuery();

        while (rs.next()) {
            System.out.println(rs.getString(1));
        }
    }

WARNING: don't know how to handle parameter pair: 
Exception in thread "main" java.sql.SQLException: Can't set parameter at index 1 due to no JDBC style '?' placeholder found in the query
zhicwu commented 2 years ago

I know how this sounds like but you need to remove the space between { and tt :)

I'll enhance the parser together with query parameter support, after moving it to clickhouse-jdbc-ext.