Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AggregateFunction column in external table didn't work #32171

Open
zhicwu opened this issue Dec 3, 2021 · 1 comment
Open

AggregateFunction column in external table didn't work #32171

zhicwu opened this issue Dec 3, 2021 · 1 comment

Comments

@zhicwu
Copy link
Contributor

zhicwu commented Dec 3, 2021

Below is the code snippet in Java trying to use bitmap as a query parameter:

try (ClickHouseConnection conn = newConnection(new Properties());
        PreparedStatement stmt = conn.prepareStatement(
                "SELECT bitmapContains(my_bitmap, toUInt32(1)) as v1, bitmapContains(my_bitmap, toUInt32(2)) as v2 from ext_table")) {
    ClickHouseRequest<?> request = stmt.unwrap(ClickHouseRequest.class);
    request.addExternal(ClickHouseExternalTable.builder().name("ext_table")
            .columns("my_bitmap AggregateFunction(groupBitmap,UInt32)").format(ClickHouseFormat.RowBinary)
            .content(new ByteArrayInputStream(ClickHouseBitmap.wrap(1, 3, 5).toBytes())).build());
    ResultSet rs = stmt.executeQuery();
    Assert.assertTrue(rs.next());
    Assert.assertEquals(rs.getInt(1), 1);
    Assert.assertEquals(rs.getInt(2), 0);
    Assert.assertFalse(rs.next());
}

Unfortunately it didn't work because of below check. Is it just a parsing error should be fixed or it's a limitation of external table by design?

std::vector<std::string> vals;
splitInto<' ', ','>(vals, argument, true);
if (vals.size() % 2 != 0)
throw Exception("Odd number of attributes in section structure: " + std::to_string(vals.size()), ErrorCodes::BAD_ARGUMENTS);

@zhicwu
Copy link
Contributor Author

zhicwu commented Dec 6, 2021

Workaround in JDBC:

try (ClickHouseConnection conn = newConnection(new Properties());
        PreparedStatement stmt = conn.prepareStatement(
                "SELECT bitmapContains(my_bitmap, toUInt32(1)) as v1, bitmapContains(my_bitmap, toUInt32(2)) as v2 from {tt 'ext_table'}")) {
    stmt.setObject(1, ClickHouseExternalTable.builder().name("ext_table")
            .columns("my_bitmap AggregateFunction(groupBitmap,UInt32)")
            .format(ClickHouseFormat.RowBinary) // optional as it's same as default
            .content(new ByteArrayInputStream(ClickHouseBitmap.wrap(1, 3, 5).toBytes()))
            .asTempTable() // necessary because of this parsing error
            .build());
    ResultSet rs = stmt.executeQuery();
    Assert.assertTrue(rs.next());
    Assert.assertEquals(rs.getInt(1), 1);
    Assert.assertEquals(rs.getInt(2), 0);
    Assert.assertFalse(rs.next());
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant