You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "dylanhz (via GitHub)" <gi...@apache.org> on 2026/03/25 06:24:48 UTC
[PR] Flink 39187 [flink]
dylanhz opened a new pull request, #27821:
URL: https://github.com/apache/flink/pull/27821
<!--
*Thank you very much for contributing to Apache Flink - we are happy that you want to help us improve Flink. 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.*
*Please understand that we do not do this to make contributions to Flink a hassle. In order to uphold a high standard of quality for code contributions, while at the same time managing a large number of contributions, we need contributors to prepare the contributions well, and give reviewers enough contextual information for the review. Please also understand that contributions that do not follow this guide will take longer to review and thus typically be picked up with lower priority by the community.*
## Contribution Checklist
- Make sure that the pull request corresponds to a [JIRA issue](https://issues.apache.org/jira/projects/FLINK/issues). Exceptions are made for typos in JavaDoc or documentation files, which need no JIRA issue.
- Name the pull request in the form "[FLINK-XXXX] [component] Title of the pull request", where *FLINK-XXXX* should be replaced by the actual issue number. Skip *component* if you are unsure about which is the best component.
Typo fixes that have no associated JIRA issue should be named following this pattern: `[hotfix] [docs] Fix typo in event time introduction` or `[hotfix] [javadocs] Expand JavaDoc for PuncuatedWatermarkGenerator`.
- 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. You can set up Azure Pipelines CI to do that following [this guide](https://cwiki.apache.org/confluence/display/FLINK/Azure+Pipelines#AzurePipelines-Tutorial:SettingupAzurePipelinesforaforkoftheFlinkrepository).
- Each pull request should address only one issue, not mix up code from multiple issues.
- Each commit in the pull request has a meaningful commit message (including the JIRA id)
- Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below.
**(The sections below can be removed for hotfixes of typos)**
-->
## What is the purpose of the change
This is the fifth PR for [FLIP-556](https://cwiki.apache.org/confluence/display/FLINK/FLIP-556%3A+Introduce+BITMAP+Data+Type), following [#27817](https://github.com/apache/flink/pull/27817).
This PR introduces built-in aggregate functions for the BITMAP type, including bitmap-returning aggregations and their cardinality-returning variants.
## Brief change log
- [hotfix] Made `RoaringBitmapData` implement `Serializable` and removed unused `wrap` method
- Added `BITMAP_BUILD_AGG` aggregate function with retraction support
- Added `BITMAP_AND_AGG`, `BITMAP_OR_AGG`, `BITMAP_XOR_AGG` aggregate functions with retraction support
- Added cardinality-returning variants (`BITMAP_AND_COUNT`, `BITMAP_OR_COUNT`, `BITMAP_XOR_COUNT`) via abstract base class refactoring
- Added documentation (EN/ZH), Java Table API, and PyFlink bindings for all functions
## Verifying this change
This change added tests and can be verified as follows:
- `BitmapAggFunctionITCase`: Integration tests for all 7 aggregate functions covering null handling, retraction, boundary values, oversize bitmap, and validation errors
- Scala ITCase tests covering batch/streaming group-by, over-window, tumble window, and Table API aggregation scenarios
## Does this pull request potentially affect one of the following parts:
- Dependencies (does it add or upgrade a dependency): no
- The public API, i.e., is any changed class annotated with `@Public(Evolving)`: yes
- The serializers: no
- The runtime per-record code paths (performance sensitive): no
- Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: no
- The S3 file system connector: no
## Documentation
- Does this pull request introduce a new feature? yes
- If yes, how is the feature documented? JavaDocs
--
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@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-39187][table] Add core built-in aggregate functions for BITMAP [flink]
Posted by "lincoln-lil (via GitHub)" <gi...@apache.org>.
lincoln-lil merged PR #27821:
URL: https://github.com/apache/flink/pull/27821
--
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@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-39187][table] Add core built-in aggregate functions for BITMAP [flink]
Posted by "lincoln-lil (via GitHub)" <gi...@apache.org>.
lincoln-lil commented on code in PR #27821:
URL: https://github.com/apache/flink/pull/27821#discussion_r2988373591
##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/functions/aggregate/AbstractBitmapOrWithRetractAggFunction.java:
##########
@@ -0,0 +1,264 @@
+/*
+ * 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.flink.table.runtime.functions.aggregate;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.api.dataview.MapView;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.logical.LogicalType;
+import org.apache.flink.types.bitmap.Bitmap;
+import org.apache.flink.types.bitmap.RoaringBitmapData;
+import org.apache.flink.util.FlinkRuntimeException;
+
+import javax.annotation.Nullable;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+
+import static org.apache.flink.table.types.utils.DataTypeUtils.toInternalDataType;
+
+/** Abstract base class for BITMAP_OR_AGG and BITMAP_OR_CARDINALITY_AGG with retraction. */
+@Internal
+public abstract class AbstractBitmapOrWithRetractAggFunction<T>
+ extends BuiltInAggregateFunction<
+ T, AbstractBitmapOrWithRetractAggFunction.BitmapOrWithRetractAccumulator> {
+
+ private final transient DataType valueDataType;
+
+ public AbstractBitmapOrWithRetractAggFunction(LogicalType valueType) {
+ this.valueDataType = toInternalDataType(valueType);
+ }
+
+ // --------------------------------------------------------------------------------------------
+ // Planning
+ // --------------------------------------------------------------------------------------------
+
+ @Override
+ public List<DataType> getArgumentDataTypes() {
+ return Collections.singletonList(valueDataType);
+ }
+
+ @Override
+ public DataType getAccumulatorDataType() {
+ return DataTypes.STRUCTURED(
+ BitmapOrWithRetractAccumulator.class,
+ DataTypes.FIELD("bitmapCount", DataTypes.INT().notNull()),
+ DataTypes.FIELD("bitmap", DataTypes.BITMAP().notNull()),
+ DataTypes.FIELD(
+ "valueCount",
+ MapView.newMapViewDataType(
+ DataTypes.INT().notNull(), DataTypes.INT().notNull())));
+ }
+
+ // --------------------------------------------------------------------------------------------
+ // Accumulator
+ // --------------------------------------------------------------------------------------------
+
+ /** Accumulator for BITMAP_OR_AGG and BITMAP_OR_CARDINALITY_AGG with retraction. */
+ public static class BitmapOrWithRetractAccumulator {
+
+ public int bitmapCount = 0;
+ // bitmap should reflect the actual data based on valueCount
+ public RoaringBitmapData bitmap = RoaringBitmapData.empty();
+ public MapView<Integer, Integer> valueCount = new MapView<>();
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null || getClass() != obj.getClass()) {
+ return false;
+ }
+ BitmapOrWithRetractAccumulator that = (BitmapOrWithRetractAccumulator) obj;
+ return bitmapCount == that.bitmapCount
+ && Objects.equals(bitmap, that.bitmap)
+ && Objects.equals(valueCount, that.valueCount);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(bitmapCount, bitmap, valueCount);
+ }
+ }
+
+ @Override
+ public BitmapOrWithRetractAccumulator createAccumulator() {
+ return new BitmapOrWithRetractAccumulator();
+ }
+
+ public void resetAccumulator(BitmapOrWithRetractAccumulator acc) {
+ acc.bitmapCount = 0;
+ acc.bitmap.clear();
+ acc.valueCount.clear();
+ }
+
+ // --------------------------------------------------------------------------------------------
+ // Runtime
+ // --------------------------------------------------------------------------------------------
+
+ public void accumulate(BitmapOrWithRetractAccumulator acc, @Nullable Bitmap bitmap)
+ throws Exception {
+ if (bitmap == null) {
+ return;
+ }
+
+ acc.bitmapCount++;
+
+ RoaringBitmapData rbm32 = (RoaringBitmapData) bitmap;
Review Comment:
ditto
##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/functions/aggregate/AbstractBitmapAndWithRetractAggFunction.java:
##########
@@ -0,0 +1,261 @@
+/*
+ * 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.flink.table.runtime.functions.aggregate;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.api.dataview.MapView;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.logical.LogicalType;
+import org.apache.flink.types.bitmap.Bitmap;
+import org.apache.flink.types.bitmap.RoaringBitmapData;
+import org.apache.flink.util.FlinkRuntimeException;
+
+import javax.annotation.Nullable;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+
+import static org.apache.flink.table.types.utils.DataTypeUtils.toInternalDataType;
+
+/** Abstract base class for BITMAP_AND_AGG and BITMAP_AND_CARDINALITY_AGG with retraction. */
+@Internal
+public abstract class AbstractBitmapAndWithRetractAggFunction<T>
+ extends BuiltInAggregateFunction<
+ T, AbstractBitmapAndWithRetractAggFunction.BitmapAndWithRetractAccumulator> {
+
+ private final transient DataType valueDataType;
+
+ public AbstractBitmapAndWithRetractAggFunction(LogicalType valueType) {
+ this.valueDataType = toInternalDataType(valueType);
+ }
+
+ // --------------------------------------------------------------------------------------------
+ // Planning
+ // --------------------------------------------------------------------------------------------
+
+ @Override
+ public List<DataType> getArgumentDataTypes() {
+ return Collections.singletonList(valueDataType);
+ }
+
+ @Override
+ public DataType getAccumulatorDataType() {
+ return DataTypes.STRUCTURED(
+ BitmapAndWithRetractAccumulator.class,
+ DataTypes.FIELD("bitmapCount", DataTypes.INT().notNull()),
+ DataTypes.FIELD(
+ "valueCount",
+ MapView.newMapViewDataType(
+ DataTypes.INT().notNull(), DataTypes.INT().notNull())));
+ }
+
+ // --------------------------------------------------------------------------------------------
+ // Accumulator
+ // --------------------------------------------------------------------------------------------
+
+ /** Accumulator for BITMAP_AND_AGG and BITMAP_AND_CARDINALITY_AGG with retraction. */
+ public static class BitmapAndWithRetractAccumulator {
+
+ public int bitmapCount = 0;
+ public MapView<Integer, Integer> valueCount = new MapView<>();
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null || getClass() != obj.getClass()) {
+ return false;
+ }
+ BitmapAndWithRetractAccumulator that = (BitmapAndWithRetractAccumulator) obj;
+ return bitmapCount == that.bitmapCount && Objects.equals(valueCount, that.valueCount);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(bitmapCount, valueCount);
+ }
+ }
+
+ @Override
+ public BitmapAndWithRetractAccumulator createAccumulator() {
+ return new BitmapAndWithRetractAccumulator();
+ }
+
+ public void resetAccumulator(BitmapAndWithRetractAccumulator acc) {
+ acc.bitmapCount = 0;
+ acc.valueCount.clear();
+ }
+
+ // --------------------------------------------------------------------------------------------
+ // Runtime
+ // --------------------------------------------------------------------------------------------
+
+ public void accumulate(BitmapAndWithRetractAccumulator acc, @Nullable Bitmap bitmap)
+ throws Exception {
+ if (bitmap == null) {
+ return;
+ }
+
+ acc.bitmapCount++;
+
+ RoaringBitmapData rbm32 = (RoaringBitmapData) bitmap;
Review Comment:
Use `RoaringBitmapData.toRoaringBitmapData()` seems better?
--
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@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-39187][table] Add core built-in aggregate functions for BITMAP [flink]
Posted by "dylanhz (via GitHub)" <gi...@apache.org>.
dylanhz commented on PR #27821:
URL: https://github.com/apache/flink/pull/27821#issuecomment-4131346487
> And for the AND_AGG and OR_AGG with retraction functions, we'd better document the perf cliff when dealing large bitmaps (use non-heap statebackend), WDYT?
@lincoln-lil Thanks for the review! Here's a summary of updates per commit:
- **Commit 1 (hotfix):** Made `RoaringBitmapData.toRoaringBitmapData()` public for use by aggregate functions
- **Commit 3 (AND/OR/XOR_AGG):** Replaced direct `(RoaringBitmapData)` casts with `RoaringBitmapData.toRoaringBitmapData()`; added performance note for `BITMAP_AND_AGG` and `BITMAP_OR_AGG` retraction variants in docs, Table API, and PyFlink API
- **Commit 4 (cardinality):** Same performance note added for `BITMAP_AND_CARDINALITY_AGG` and `BITMAP_OR_CARDINALITY_AGG`
--
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@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-39187][table] Add core built-in aggregate functions for BITMAP [flink]
Posted by "dylanhz (via GitHub)" <gi...@apache.org>.
dylanhz commented on PR #27821:
URL: https://github.com/apache/flink/pull/27821#issuecomment-4132012808
@lincoln-lil Doc changes: Added a new `bitmapagg` section (after `aggregate`) in `sql_functions.yml` / `sql_functions_zh.yml` for all 8 bitmap aggregate functions, separated from scalar bitmap functions. Added corresponding "Bitmap Aggregate Functions" subsection in `built-in-functions.md` (EN + ZH).
--
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@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-39187][table] Add core built-in aggregate functions for BITMAP [flink]
Posted by "flinkbot (via GitHub)" <gi...@apache.org>.
flinkbot commented on PR #27821:
URL: https://github.com/apache/flink/pull/27821#issuecomment-4124130285
<!--
Meta data
{
"version" : 1,
"metaDataEntries" : [ {
"hash" : "9e71bfd10a62ffcd8e15c1976e77ec25d0b3c833",
"status" : "UNKNOWN",
"url" : "TBD",
"triggerID" : "9e71bfd10a62ffcd8e15c1976e77ec25d0b3c833",
"triggerType" : "PUSH"
} ]
}-->
## CI report:
* 9e71bfd10a62ffcd8e15c1976e77ec25d0b3c833 UNKNOWN
<details>
<summary>Bot commands</summary>
The @flinkbot bot supports the following commands:
- `@flinkbot run azure` re-run the last Azure build
</details>
--
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@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org