Skip to content

[fix](fe) Support SET type deserialization in FE BitmapValue - #68379

Open
iyils wants to merge 1 commit into
apache:masterfrom
iyils:fix-fe-bitmap-set-deserialization
Open

iyils wants to merge 1 commit into
apache:masterfrom
iyils:fix-fe-bitmap-set-deserialization

Conversation

@iyils

@iyils iyils commented Sep 22, 2026

Copy link
Copy Markdown

What problem does this PR solve?

Issue Number: close #68309

Problem Summary:

BE serializes a bitmap holding at most 32 values as BitmapTypeCode::SET (flag 5) whenever enable_set_in_bitmap_value is on, which has been the default since #35730. The FE reader in fe-common's BitmapValue.deserialize() only knew the type codes 0 through 4, so any BE-produced SET bitmap reaching an FE read path hit the default branch and failed with RuntimeException: unknown bitmap type 5. Affected paths are the ones that route BE bytes through fe-common, for example the Hive UDF binary bitmap argument.

Reproduction: with enable_set_in_bitmap_value=true, SELECT bitmap_to_base64(bitmap_from_array([1, 3, 5])) on BE returns BQMBAAAAAAAAAAMAAAAAAAAABQAAAAAAAAA= (type 5, count 3, then little-endian 1, 3, 5). Feeding those bytes to BitmapValue.deserialize() throws instead of yielding {1, 3, 5}.

Fix: add a SET case that reads the count as an unsigned byte, rejects a count above SET_TYPE_THRESHOLD (32, matching BE's own reader and inline SET capacity), and reads each value as a little-endian uint64. Instead of introducing a distinct in-memory SET representation, the values are folded through add(), which produces exactly the same set semantics in the existing single/bitmap representation and leaves every downstream consumer of BitmapValue unchanged.

Scope note: this fixes flag 5, the code BE emits on the default path. The FE reader still does not know BE's SET_V2 (10), BITMAP32_V2 (12) or BITMAP64_V2 (13) codes, which require bitmap_serialize_version other than 1 on both sides; supporting those is deliberately out of scope here.

Release note

Fixed the FE BitmapValue reader so it can deserialize SET-format bitmaps (flag 5) produced by the BE, removing the unknown bitmap type 5 failure on FE paths that read BE-serialized bitmaps.

Check List (For Author)

  • Test

    • Regression test
    • Unit Test
    • Manual test (add detailed scripts or steps below)
    • No need to test or manual test. Explain why:
      • This is a refactor/code format and no logic has been changed.
      • Previous test can cover this change.
      • No code files have been changed.
      • Other reason
  • Behavior changed:

    • No.
    • Yes. The FE reader now accepts flag 5 (SET) instead of throwing RuntimeException.
  • Does this need documentation?

    • No.
    • Yes.

Check List (For Reviewer who merge this PR)

  • Confirm the release note
  • Confirm test cases
  • Confirm document
  • Add branch pick label

### What problem does this PR solve?

Issue Number: close apache#68309

Problem Summary:

BE serializes a bitmap holding at most 32 values as `BitmapTypeCode::SET` (flag 5) whenever
`enable_set_in_bitmap_value` is on, which has been the default since apache#35730. The FE reader in
`fe-common`'s `BitmapValue.deserialize()` only knew the type codes 0 through 4, so any BE-produced
SET bitmap reaching an FE read path hit the default branch and failed with
`RuntimeException: unknown bitmap type 5`. Affected paths are the ones that route BE bytes through
`fe-common`, for example the Hive UDF binary bitmap argument.

Reproduction: with `enable_set_in_bitmap_value=true`, `SELECT bitmap_to_base64(bitmap_from_array([1, 3, 5]))`
on BE returns `BQMBAAAAAAAAAAMAAAAAAAAABQAAAAAAAAA=` (type 5, count 3, then little-endian 1, 3, 5).
Feeding those bytes to `BitmapValue.deserialize()` throws instead of yielding `{1, 3, 5}`.

Fix: add a `SET` case that reads the count as an unsigned byte, rejects a count above
`SET_TYPE_THRESHOLD` (32, matching BE's own reader and inline SET capacity), and reads each value as a
little-endian uint64. Instead of introducing a distinct in-memory SET representation, the values are
folded through `add()`, which produces exactly the same set semantics in the existing
single/bitmap representation and leaves every downstream consumer of `BitmapValue` unchanged.

Scope note: this fixes flag 5, the code BE emits on the default path. The FE reader still does not
know BE's `SET_V2` (10), `BITMAP32_V2` (12) or `BITMAP64_V2` (13) codes, which require
`bitmap_serialize_version` other than 1 on both sides; supporting those is deliberately out of scope
here.

### Release note

Fixed the FE `BitmapValue` reader so it can deserialize SET-format bitmaps (flag 5) produced by the
BE, removing the `unknown bitmap type 5` failure on FE paths that read BE-serialized bitmaps.

### Check List (For Author)

- Test: Unit Test
    - `BitmapValueTest` covers hard-coded cross-language fixtures exported from BE via
      `bitmap_to_base64` (rather than another Java writer-to-reader round trip, since the Java
      serializer never emits SET): a normal SET, the 32-element boundary, values of 0, 2^32,
      Long.MAX_VALUE and UINT64_MAX, an over-threshold count, truncated input, and duplicate values.
    - `mvn -pl fe-foundation,fe-common test -Dtest=BitmapValueTest` passes (16 tests).
- Behavior changed: Yes (the FE reader now accepts flag 5 instead of throwing)
- Does this need documentation: No
@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@iyils

iyils commented Sep 22, 2026

Copy link
Copy Markdown
Author

run buildall

@iyils

iyils commented Sep 22, 2026

Copy link
Copy Markdown
Author

/review

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-H: Total hot run time: 27862 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit b6091285c0a265f41b4f1a924d6241708ace98d3, data reload: false

------ Round 1 ----------------------------------
============================================
q1	17612	3814	3833	3814
q2	2200	382	321	321
q3	10059	1453	774	774
q4	4682	474	352	352
q5	7465	829	568	568
q6	178	165	138	138
q7	735	811	608	608
q8	9309	1437	1513	1437
q9	5479	4179	4176	4176
q10	6829	1323	1012	1012
q11	432	269	249	249
q12	631	416	299	299
q13	18069	2592	1977	1977
q14	258	254	235	235
q15	q16	729	720	659	659
q17	1748	1091	967	967
q18	6431	5612	5614	5612
q19	1295	1235	1015	1015
q20	493	401	260	260
q21	5759	3286	3075	3075
q22	449	365	314	314
Total cold run time: 100842 ms
Total hot run time: 27862 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4583	4691	4400	4400
q2	737	566	531	531
q3	4763	5144	4511	4511
q4	2272	2313	1426	1426
q5	4546	4342	4593	4342
q6	235	180	126	126
q7	1831	1681	1480	1480
q8	2270	2073	2042	2042
q9	7283	7201	7156	7156
q10	3693	3610	3149	3149
q11	532	375	341	341
q12	698	700	495	495
q13	2264	2584	2004	2004
q14	266	283	259	259
q15	q16	665	735	591	591
q17	7238	6709	6567	6567
q18	11862	11058	11673	11058
q19	1113	1020	1019	1019
q20	2199	2197	1909	1909
q21	4895	4092	4251	4092
q22	520	450	418	418
Total cold run time: 64465 ms
Total hot run time: 57916 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 152649 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpcds-tools
TPC-DS sf100 test result on commit b6091285c0a265f41b4f1a924d6241708ace98d3, data reload: false

query5	4334	594	474	474
query6	436	234	206	206
query7	4850	561	307	307
query8	327	187	164	164
query9	8843	3965	3965	3965
query10	441	304	257	257
query11	5819	3522	3212	3212
query12	148	90	83	83
query13	1263	613	420	420
query14	6482	4458	4146	4146
query14_1	3967	3938	3901	3901
query15	202	193	170	170
query16	1001	443	416	416
query17	878	660	550	550
query18	2477	453	338	338
query19	209	183	142	142
query20	81	82	80	80
query21	227	132	117	117
query22	13000	13012	12767	12767
query23	13939	12874	12459	12459
query23_1	12632	12582	12610	12582
query24	7302	1159	692	692
query24_1	677	732	727	727
query25	582	441	368	368
query26	1289	331	175	175
query27	2678	574	330	330
query28	4590	1972	1977	1972
query29	1646	726	534	534
query30	290	221	181	181
query31	902	773	640	640
query32	147	115	98	98
query33	559	309	252	252
query34	1230	1086	642	642
query35	733	755	639	639
query36	780	766	721	721
query37	147	110	94	94
query38	1829	1783	1667	1667
query39	718	684	662	662
query39_1	652	664	641	641
query40	224	139	102	102
query41	71	71	72	71
query42	96	94	96	94
query43	335	340	299	299
query44	1362	721	727	721
query45	187	174	165	165
query46	1070	1177	737	737
query47	1497	1537	1412	1412
query48	418	404	299	299
query49	591	413	299	299
query50	1019	358	263	263
query51	10157	10463	10428	10428
query52	88	89	76	76
query53	239	254	189	189
query54	273	231	204	204
query55	82	76	71	71
query56	246	233	219	219
query57	1439	1433	1375	1375
query58	280	274	262	262
query59	2005	2046	1860	1860
query60	301	250	234	234
query61	167	169	165	165
query62	393	323	309	309
query63	215	176	165	165
query64	2788	999	792	792
query65	3478	3386	3429	3386
query66	1806	417	309	309
query67	20093	20090	19700	19700
query68	3572	1439	815	815
query69	413	304	261	261
query70	846	796	828	796
query71	301	241	222	222
query72	2745	2467	2217	2217
query73	861	749	448	448
query74	4651	4510	4305	4305
query75	2290	2281	1938	1938
query76	2428	1106	754	754
query77	351	378	299	299
query78	8989	9130	8551	8551
query79	1399	1146	777	777
query80	920	456	363	363
query81	626	327	283	283
query82	644	170	127	127
query83	282	222	213	213
query84	315	147	115	115
query85	1008	455	387	387
query86	365	229	226	226
query87	1992	1962	1848	1848
query88	3589	2720	2749	2720
query89	370	287	247	247
query90	1763	179	178	178
query91	171	161	127	127
query92	104	92	89	89
query93	1594	1580	929	929
query94	594	361	298	298
query95	650	365	353	353
query96	1120	790	347	347
query97	2412	2430	2321	2321
query98	161	156	163	156
query99	732	745	635	635
Total cold run time: 237141 ms
Total hot run time: 152649 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
ClickBench: Total hot run time: 24 s
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/clickbench-tools
ClickBench test result on commit b6091285c0a265f41b4f1a924d6241708ace98d3, data reload: false

query1	0.01	0.01	0.00
query2	0.09	0.05	0.05
query3	0.26	0.14	0.14
query4	1.61	0.15	0.14
query5	0.26	0.23	0.23
query6	1.16	0.92	0.95
query7	0.04	0.01	0.01
query8	0.05	0.03	0.04
query9	0.40	0.35	0.36
query10	0.60	0.57	0.55
query11	0.19	0.14	0.14
query12	0.18	0.15	0.15
query13	0.48	0.47	0.48
query14	0.96	0.93	0.93
query15	0.61	0.59	0.60
query16	0.34	0.33	0.34
query17	1.09	1.06	1.09
query18	0.23	0.22	0.21
query19	1.96	1.93	1.88
query20	0.01	0.01	0.01
query21	15.42	0.20	0.14
query22	4.92	0.05	0.05
query23	16.13	0.31	0.12
query24	2.94	0.41	0.32
query25	0.12	0.04	0.04
query26	0.73	0.20	0.14
query27	0.05	0.03	0.04
query28	3.51	0.77	0.37
query29	12.51	4.06	3.21
query30	0.27	0.15	0.16
query31	2.77	0.57	0.31
query32	3.23	0.61	0.49
query33	3.19	3.24	3.17
query34	15.85	3.91	3.28
query35	3.27	3.24	3.22
query36	0.56	0.45	0.42
query37	0.09	0.07	0.06
query38	0.05	0.04	0.03
query39	0.04	0.03	0.03
query40	0.18	0.15	0.13
query41	0.08	0.03	0.03
query42	0.04	0.03	0.03
query43	0.05	0.04	0.04
Total cold run time: 96.53 s
Total hot run time: 24 s

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] (bitmap) Support SET type (Flag=5) deserialization in FE BitmapValue

2 participants