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

unhexAsBitmap #64338

Closed
Gotham-Joker opened this issue May 24, 2024 · 2 comments
Closed

unhexAsBitmap #64338

Gotham-Joker opened this issue May 24, 2024 · 2 comments
Labels

Comments

@Gotham-Joker
Copy link

Gotham-Joker commented May 24, 2024

Converting a hexadecimal string to a bitmap value.

I am aware that I cannot execute a query with a bitmap parameter using JDBC. For example, if I have the following query using JDBC: "select bitmapToArray(?) as res", is there any solution to pass a variable of type bitmap to the placeholder '?'?
I understand that I can use "select bitmapToArray(bitmapBuild([1,2,3....]))" instead, but when the bitmap is large, it does not work well for JDBC.
If there is no solution available, how about providing a function 'unhexAsBitmap(?)'?

This function would convert a hexadecimal parameter to a bitmap value.

@Gotham-Joker Gotham-Joker changed the title bitmapBuild by hex unhexAsBitmap May 24, 2024
@den-crane
Copy link
Contributor

Hm, why do you need select bitmap ? Is it a part of an insert select?

JDBC supports bitmaps https://github.com/search?q=repo%3AClickHouse%2Fclickhouse-java%20ClickHouseBitmap&type=code

You can use input function or external data (jdbc supports external data) https://clickhouse.com/docs/en/engines/table-engines/special/external-data

And such function already exists unhex

select hex(bitmapBuild([1,2,3]));
┌─hex(bitmapBuild([1, 2, 3]))─┐
│ 0003010203                  │
└─────────────────────────────┘

select bitmapToArray(cast(unhex('0003010203'), 'AggregateFunction(groupBitmap, UInt8)'));
┌─bitmapToArray(CAST(unhex('0003010203'), 'AggregateFunction(groupBitmap, UInt8)'))─┐
│ [1,2,3]                                                                           │
└───────────────────────────────────────────────────────────────────────────────────┘

@Gotham-Joker
Copy link
Author

I require the 'select bitmap' functionality because the bitmap value is evaluated by my Java program. Subsequently, I utilize it to filter data from the 'clickhouse' table, rather than using an insert select scenario.
In conclusion,thank you for providing solution,it is very useful.

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

No branches or pull requests

2 participants