You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@fluss.apache.org by "platinumhamburg (via GitHub)" <gi...@apache.org> on 2026/01/16 07:42:04 UTC
[PR] Add roaring bitmap aggregation [fluss]
platinumhamburg opened a new pull request, #2390:
URL: https://github.com/apache/fluss/pull/2390
<!--
*Thank you very much for contributing to Fluss - we are happy that you want to help us improve Fluss. To help the community review your contribution in the best possible way, please go through the checklist below, which will get the contribution into a shape in which it can be best reviewed.*
## Contribution Checklist
- Make sure that the pull request corresponds to a [GitHub issue](https://github.com/apache/fluss/issues). Exceptions are made for typos in JavaDoc or documentation files, which need no issue.
- Name the pull request in the format "[component] Title of the pull request", where *[component]* should be replaced by the name of the component being changed. Typically, this corresponds to the component label assigned to the issue (e.g., [kv], [log], [client], [flink]). Skip *[component]* if you are unsure about which is the best component.
- Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
- Make sure that the change passes the automated tests, i.e., `mvn clean verify` passes.
- Each pull request should address only one issue, not mix up code from multiple issues.
**(The sections below can be removed for hotfixes or typos)**
-->
### Purpose
<!-- Linking this pull request to the issue -->
Linked issue: close #2389 2389
<!-- What is the purpose of the change -->
### Brief change log
<!-- Please describe the changes made in this pull request and explain how they address the issue -->
### Tests
<!-- List UT and IT cases to verify this change -->
### API and Format
<!-- Does this change affect API or storage format -->
### Documentation
<!-- Does this change introduce a new feature -->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fluss.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add roaring bitmap aggregation [fluss]
Posted by "platinumhamburg (via GitHub)" <gi...@apache.org>.
platinumhamburg commented on code in PR #2390:
URL: https://github.com/apache/fluss/pull/2390#discussion_r2703040188
##########
fluss-server/src/main/java/org/apache/fluss/server/utils/RoaringBitmapUtils.java:
##########
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.fluss.utils;
+
+import org.roaringbitmap.RoaringBitmap;
+import org.roaringbitmap.longlong.Roaring64Bitmap;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+/** Utility methods for serializing roaring bitmaps. */
+public final class RoaringBitmapUtils {
+
+ private RoaringBitmapUtils() {
+ // Utility class, no instantiation
+ }
+
+ public static byte[] serializeRoaringBitmap32(RoaringBitmap bitmap) throws IOException {
+ bitmap.runOptimize();
+ ByteBuffer buffer = ByteBuffer.allocate(bitmap.serializedSizeInBytes());
+ bitmap.serialize(buffer);
+ return buffer.array();
+ }
+
+ public static void deserializeRoaringBitmap32(RoaringBitmap bitmap, byte[] bytes)
+ throws IOException {
+ bitmap.deserialize(ByteBuffer.wrap(bytes));
+ }
+
+ public static byte[] serializeRoaringBitmap64(Roaring64Bitmap bitmap) throws IOException {
+ bitmap.runOptimize();
+ try (ByteArrayOutputStream output = new ByteArrayOutputStream();
+ DataOutputStream dataOutput = new DataOutputStream(output)) {
+ bitmap.serialize(dataOutput);
Review Comment:
This is due to API limitations in Roaring64Bitmap:
RoaringBitmap64 returns sizeInBytes as a long, while the maximum allocation size of a ByteBuffer is Integer.MAX_VALUE. This can lead to a dangerous narrowing conversion, so we should avoid this pattern as much as possible.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fluss.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add roaring bitmap aggregation [fluss]
Posted by "platinumhamburg (via GitHub)" <gi...@apache.org>.
platinumhamburg commented on code in PR #2390:
URL: https://github.com/apache/fluss/pull/2390#discussion_r2703040188
##########
fluss-common/src/main/java/org/apache/fluss/utils/RoaringBitmapUtils.java:
##########
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.fluss.utils;
+
+import org.roaringbitmap.RoaringBitmap;
+import org.roaringbitmap.longlong.Roaring64Bitmap;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+/** Utility methods for serializing roaring bitmaps. */
+public final class RoaringBitmapUtils {
+
+ private RoaringBitmapUtils() {
+ // Utility class, no instantiation
+ }
+
+ public static byte[] serializeRoaringBitmap32(RoaringBitmap bitmap) throws IOException {
+ bitmap.runOptimize();
+ ByteBuffer buffer = ByteBuffer.allocate(bitmap.serializedSizeInBytes());
+ bitmap.serialize(buffer);
+ return buffer.array();
+ }
+
+ public static void deserializeRoaringBitmap32(RoaringBitmap bitmap, byte[] bytes)
+ throws IOException {
+ bitmap.deserialize(ByteBuffer.wrap(bytes));
+ }
+
+ public static byte[] serializeRoaringBitmap64(Roaring64Bitmap bitmap) throws IOException {
+ bitmap.runOptimize();
+ try (ByteArrayOutputStream output = new ByteArrayOutputStream();
+ DataOutputStream dataOutput = new DataOutputStream(output)) {
+ bitmap.serialize(dataOutput);
Review Comment:
This is due to API limitations in Roaring64Bitmap:
- RoaringBitmap(32-bit) provides a serialize(ByteBuffer) method, which is the officially recommended serialization approach.
- Roaring64Bitmap (64-bit) does not provide a serialize(ByteBuffer) method — it only supports serialize(DataOutput).
This isn't a design choice on our part, but rather an API difference in the RoaringBitmap library itself. The Paimon project uses the same approach.
I've added Javadoc comments to the code explaining this difference for future maintainers.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fluss.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add roaring bitmap aggregation [fluss]
Posted by "wuchong (via GitHub)" <gi...@apache.org>.
wuchong merged PR #2390:
URL: https://github.com/apache/fluss/pull/2390
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fluss.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add roaring bitmap aggregation [fluss]
Posted by "platinumhamburg (via GitHub)" <gi...@apache.org>.
platinumhamburg commented on PR #2390:
URL: https://github.com/apache/fluss/pull/2390#issuecomment-3766157689
Thanks @wuchong for the detailed review. I’ve addressed all of your comments—please take another look when you have time.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fluss.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add roaring bitmap aggregation [fluss]
Posted by "wuchong (via GitHub)" <gi...@apache.org>.
wuchong commented on code in PR #2390:
URL: https://github.com/apache/fluss/pull/2390#discussion_r2702183227
##########
fluss-common/pom.xml:
##########
@@ -62,6 +62,12 @@
<artifactId>fluss-shaded-arrow</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.roaringbitmap</groupId>
+ <artifactId>RoaringBitmap</artifactId>
+ <version>${roaringbitmap.version}</version>
Review Comment:
I noticed that the RoaringBitmap dependency is currently only used in `fluss-server`. To minimize downstream impact, could we move it from `fluss-common` into `fluss-server`?
Placing it in `fluss-common` forces all clients and connectors to inherit this dependency, which is highly likely to cause version conflicts—Paimon uses RoaringBitmap 1.2.1, while Flink uses 1.3.0, for example.
On the other hand, we may eventually need RoaringBitmap in fluss-common once we support local aggregation (e.g., in SQL or client-side pre-aggregation). To prepare for that while avoiding conflicts, I’ve opened an issue in the `fluss-shaded` repository to shade the `org.roaringbitmap` package:
https://github.com/apache/fluss-shaded/issues/4
For now, scoping the dependency to `fluss-server` seems like the safest approach.
##########
fluss-common/src/main/java/org/apache/fluss/utils/RoaringBitmapUtils.java:
##########
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.fluss.utils;
+
+import org.roaringbitmap.RoaringBitmap;
+import org.roaringbitmap.longlong.Roaring64Bitmap;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+/** Utility methods for serializing roaring bitmaps. */
+public final class RoaringBitmapUtils {
+
+ private RoaringBitmapUtils() {
+ // Utility class, no instantiation
+ }
+
+ public static byte[] serializeRoaringBitmap32(RoaringBitmap bitmap) throws IOException {
+ bitmap.runOptimize();
+ ByteBuffer buffer = ByteBuffer.allocate(bitmap.serializedSizeInBytes());
+ bitmap.serialize(buffer);
+ return buffer.array();
+ }
+
+ public static void deserializeRoaringBitmap32(RoaringBitmap bitmap, byte[] bytes)
+ throws IOException {
+ bitmap.deserialize(ByteBuffer.wrap(bytes));
+ }
+
+ public static byte[] serializeRoaringBitmap64(Roaring64Bitmap bitmap) throws IOException {
+ bitmap.runOptimize();
+ try (ByteArrayOutputStream output = new ByteArrayOutputStream();
+ DataOutputStream dataOutput = new DataOutputStream(output)) {
+ bitmap.serialize(dataOutput);
Review Comment:
I’m curious about the choice to use `DataOutputStream` for serializing rbm64, whereas `serializeRoaringBitmap32` uses ByteBuffer.
Is there a specific reason for this difference in serialization strategy?
The Javadoc of RoaringBitmap#serialize(java.nio.ByteBuffer) says:
> Serialize this bitmap to a ByteBuffer. This is the preferred method to serialize to a byte array (byte[]) or to a String
##########
pom.xml:
##########
@@ -91,6 +91,7 @@
<arrow.version>15.0.0</arrow.version>
<paimon.version>1.3.1</paimon.version>
<iceberg.version>1.10.0</iceberg.version>
+ <roaringbitmap.version>1.2.1</roaringbitmap.version>
Review Comment:
It seems the latest stable version is 1.3.0, and both Iceberg[1], Flink [2] use that version. Should we upgrade version to that?
[1] https://github.com/apache/iceberg/blob/e93eaab330581999d8fd8e4e6f5f885446cf28c3/gradle/libs.versions.toml#L86
[2] https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=399278679#FLIP556:IntroduceBITMAPDataType-InternalImplementationDetails
##########
git-issue-roaringbitmap-agg.md:
##########
@@ -0,0 +1,15 @@
+Title: Add RoaringBitmap aggregation support to Fluss merge engine
Review Comment:
remove this file?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fluss.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org