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/17 10:01:56 UTC
[PR] [FLINK-39185][table] Introduce BITMAP type for Table API/SQL [flink]
dylanhz opened a new pull request, #27778:
URL: https://github.com/apache/flink/pull/27778
## What is the purpose of the change
This pull request adds Table API/SQL support for the BITMAP data type introduced in [FLIP-556](https://cwiki.apache.org/confluence/display/FLINK/FLIP-556%3A+Introduce+BITMAP+Data+Type). It integrates BITMAP into Flink's type system, internal data format, planner, and code generation, enabling BITMAP columns to be used in SQL queries and Table API programs.
This is the third PR in the FLIP-556 series:
- PR 1 (`FLINK-39183`): Parser support
- PR 2 (`FLINK-39184`): DataStream API support (`flink-core`)
- **PR 3 (`FLINK-39185`): Table API/SQL support (this PR)**
## Brief change log
Suggested review order:
1. **LogicalType system**: Added `BitmapType`, `LogicalTypeRoot.BITMAP`, `LogicalTypeFamily.EXTENSION`, visitor support, cast rules, and type parsing
2. **DataType / API layer**: Added `DataTypes.BITMAP()`, registered type mappings in `ClassDataTypeConverter`, `TypeInfoDataTypeConverter`, and `ValueDataTypeConverter`
3. **Internal data format**: Extended `RowData`/`ArrayData` with `getBitmap()`, implemented in `BinaryRowData`/`BinaryArrayData`/`GenericRowData`/`GenericArrayData`/`NestedRowData`; added `BinarySegmentUtils.readBitmap()` and `BinaryWriter.writeBitmap()`
4. **Planner integration**: Added `BitmapRelDataType`, integrated into `FlinkTypeFactory` (bidirectional conversion between `BitmapType` and `BitmapRelDataType`), extended `CodeGenUtils` for code generation, and updated `ExpressionReducer`
5. **Cast rules**: Added `BitmapToStringCastRule` and `BitmapToBinaryCastRule` (with trim/pad semantics); restricted `CAST(x AS BITMAP)` in `SqlCastFunction`
6. **Data converters**: Added `BitmapBitmapConverter`, `DataFormatConverters.BitmapConverter`, and JSON serialization/deserialization for `BitmapType`
## Verifying this change
This change added tests and can be verified as follows:
- `BitmapSemanticTest`: End-to-end integration tests for BITMAP in SQL/Table API, covering source/sink roundtrip, projection, filtering, UDF invocation, and UDAF aggregation
- `BinaryRowDataTest` / `BinaryArrayDataTest`: Unit tests for BITMAP read/write in binary row and array formats
- `RowDataTest`: Verifies BITMAP field access and `FieldGetter` in `RowData`
- `DataTypesTest`: Verifies `DataTypes.BITMAP()` resolution and class mapping
- `LogicalTypesTest`: Tests `BitmapType` properties, serialization string, and cast compatibility
- `ProjectionCodeGeneratorTest`: Verifies BITMAP field projection in generated code
- `TypeInferenceExtractorTest`: Tests type inference for UDFs that accept/return BITMAP, including rejection of custom Bitmap implementations
## 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 (`RowData`, `ArrayData`, `DataTypes`, `BinaryWriter`)
- The serializers: no
- The runtime per-record code paths (performance sensitive): yes (new `getBitmap`/`writeBitmap` code paths, but only activated for BITMAP type columns)
- 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? not documented (documentation will be added when the full BITMAP type support is complete, including built-in functions)
--
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-39185][table] Introduce BITMAP type for Table API/SQL [flink]
Posted by "lincoln-lil (via GitHub)" <gi...@apache.org>.
lincoln-lil merged PR #27778:
URL: https://github.com/apache/flink/pull/27778
--
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-39185][table] Introduce BITMAP type for Table API/SQL [flink]
Posted by "lincoln-lil (via GitHub)" <gi...@apache.org>.
lincoln-lil commented on PR #27778:
URL: https://github.com/apache/flink/pull/27778#issuecomment-4116520130
> > @dylanhz Thanks for working on this! I've left some comments there, and for the tests, can you add cases covering cast call results, e.g., `CAST(bitmap AS STRING)` and `CAST(bitmap AS VARBINARY)`.
> > Another question for the python part, should we adapt bitmap type in `PythonTableUtils.converter()`?
>
> @lincoln-lil Thanks for the feedback!
>
> 1. Cast tests will be add in the built-in function pr, because we are unable to create a bitmap literal in the table layer currently.
> 2. According to the FLIP roadmap, Python support for BITMAP is planned as future work. I haven't fully designed the complete PyFlink integration yet, so this PR will not introduce any Python-related logic.
Ok, make sense to me.
--
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-39185][table] Introduce BITMAP type for Table API/SQL [flink]
Posted by "lincoln-lil (via GitHub)" <gi...@apache.org>.
lincoln-lil commented on code in PR #27778:
URL: https://github.com/apache/flink/pull/27778#discussion_r2963821388
##########
flink-core/src/main/java/org/apache/flink/types/bitmap/Bitmap.java:
##########
@@ -0,0 +1,164 @@
+/*
+ * 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.types.bitmap;
+
+import org.apache.flink.annotation.PublicEvolving;
+
+import javax.annotation.Nullable;
+
+/**
+ * A compressed data structure for storing sets of 32-bit integers.
+ *
+ * <p>The modifying methods in this interface modify the bitmap in place by default. Consider using
+ * {@link Bitmap#from(Bitmap other)} to create a copied bitmap before modification if immutability
+ * is required.
+ */
+@PublicEvolving
+public interface Bitmap {
+
+ /** Adds the value to the bitmap. */
+ void add(int value);
+
+ /**
+ * Adds all integers in [rangeStart,rangeEnd) to the bitmap.
+ *
+ * @param rangeStart valid range [0L, 0xFFFFFFFFL]
+ * @param rangeEnd valid range [0L, 0xFFFFFFFFL + 1]
+ */
+ void add(long rangeStart, long rangeEnd);
+
+ /** Adds the first n elements of the specified array starting at the specified offset. */
+ void addN(int[] values, int offset, int n);
+
+ /**
+ * Performs an in-place logical AND (intersection) operation with another bitmap.
+ *
+ * <p>Does nothing if {@code other} is null.
+ */
+ void and(@Nullable Bitmap other);
+
+ /**
+ * Performs an in-place logical AND-NOT (difference) operation with another bitmap, which is
+ * equivalent to {@code this AND (NOT other)}.
+ *
+ * <p>Does nothing if {@code other} is null.
+ */
+ void andNot(@Nullable Bitmap other);
+
+ /** Resets to an empty bitmap. */
+ void clear();
+
+ /** Checks whether the value appears in the bitmap. */
+ boolean contains(int value);
+
+ /** Gets the number of distinct values in the bitmap. */
+ int getCardinality();
+
+ /** Gets the number of distinct values in the bitmap. This returns a full 64-bit result. */
+ long getLongCardinality();
+
+ /** Checks whether the bitmap is empty. */
+ boolean isEmpty();
+
+ /**
+ * Performs an in-place logical OR (union) operation with another bitmap.
+ *
+ * <p>Does nothing if {@code other} is null.
+ */
+ void or(@Nullable Bitmap other);
+
+ /** Removes the value from the bitmap. */
+ void remove(int value);
+
+ /**
+ * Converts the bitmap to an array of 32-bit integers, the values are sorted by {@link
+ * Integer#compareUnsigned}. Avoid calling this method if the bitmap is too large.
+ */
+ int[] toArray();
+
+ /**
+ * Converts the bitmap to an array of bytes.
+ *
+ * <p>Following the format defined in <a
+ * href="https://github.com/RoaringBitmap/RoaringFormatSpec">32-bit RoaringBitmap format
+ * specification</a>.
+ */
+ byte[] toBytes();
+
+ /**
+ * Converts the bitmap to a string, the values are sorted by {@link Integer#compareUnsigned}.
+ * The string will be truncated and end with "..." if it is too long.
+ *
+ * <p>For example:
+ *
+ * <ul>
+ * <li>{@code "{}"}, {@code "{1,2,3,4,5}"}
+ * <li>Negative values (converted to unsigned): {@code "{0,1,4294967294,4294967295}"}
+ * <li>String too long: {@code "{1,2,3,...}"}
+ * </ul>
+ */
+ String toString();
+
+ /**
+ * Performs an in-place logical XOR (symmetric difference) operation with another bitmap.
+ *
+ * <p>Does nothing if {@code other} is null.
+ */
+ void xor(@Nullable Bitmap other);
+
+ // ~ Static Methods --------------------------------------------------------------
+
+ /** Gets an empty bitmap. */
+ static Bitmap empty() {
+ return RoaringBitmapData.empty();
+ }
+
+ /** Gets a copied bitmap. Returns null if {@code other} is null. */
+ static Bitmap from(Bitmap other) {
Review Comment:
We should at least add java doc here to clearly note that currently only RoaringBitmapData is supported
##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/logical/BitmapType.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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.types.logical;
+
+import org.apache.flink.annotation.PublicEvolving;
+import org.apache.flink.types.bitmap.Bitmap;
+import org.apache.flink.types.bitmap.RoaringBitmapData;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Data type of bitmap data.
+ *
+ * <p>This type supports storing 32-bit integers in a compressed form. This can be useful for
+ * efficiently representing and querying large sets of integers.
+ *
+ * <p>The serializable string representation of this type is {@code BITMAP}.
+ */
+@PublicEvolving
+public final class BitmapType extends LogicalType {
Review Comment:
Add `serialVersionUID`
--
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-39185][table] Introduce BITMAP type for Table API/SQL [flink]
Posted by "dylanhz (via GitHub)" <gi...@apache.org>.
dylanhz commented on PR #27778:
URL: https://github.com/apache/flink/pull/27778#issuecomment-4114803869
> @dylanhz Thanks for working on this! I've left some comments there, and for the tests, can you add cases covering cast call results, e.g., `CAST(bitmap AS STRING)` and `CAST(bitmap AS VARBINARY)`.
>
> Another question for the python part, should we adapt bitmap type in `PythonTableUtils.converter()`?
@lincoln-lil Thanks for the feedback!
1. Cast tests will be add in the built-in function pr, because we are unable to create a bitmap literal in the table layer currently.
2. According to the FLIP roadmap, Python support for BITMAP is planned as future work. I haven't fully designed the complete PyFlink integration yet, so this PR will not introduce any Python-related logic.
--
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-39185][table] Introduce BITMAP type for Table API/SQL [flink]
Posted by "flinkbot (via GitHub)" <gi...@apache.org>.
flinkbot commented on PR #27778:
URL: https://github.com/apache/flink/pull/27778#issuecomment-4073783253
<!--
Meta data
{
"version" : 1,
"metaDataEntries" : [ {
"hash" : "100e80ee788c13e0077fdc3ec8fea4a8f2b3d16e",
"status" : "UNKNOWN",
"url" : "TBD",
"triggerID" : "100e80ee788c13e0077fdc3ec8fea4a8f2b3d16e",
"triggerType" : "PUSH"
} ]
}-->
## CI report:
* 100e80ee788c13e0077fdc3ec8fea4a8f2b3d16e 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
Re: [PR] [FLINK-39185][table] Introduce BITMAP type for Table API/SQL [flink]
Posted by "lincoln-lil (via GitHub)" <gi...@apache.org>.
lincoln-lil commented on code in PR #27778:
URL: https://github.com/apache/flink/pull/27778#discussion_r2979389942
##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/functions/casting/BitmapToBinaryCastRule.java:
##########
@@ -0,0 +1,88 @@
+/*
+ * 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.planner.functions.casting;
+
+import org.apache.flink.table.planner.codegen.CodeGenUtils;
+import org.apache.flink.table.types.logical.LogicalType;
+import org.apache.flink.table.types.logical.LogicalTypeFamily;
+import org.apache.flink.table.types.logical.LogicalTypeRoot;
+import org.apache.flink.table.types.logical.utils.LogicalTypeChecks;
+import org.apache.flink.types.bitmap.Bitmap;
+
+import static org.apache.flink.table.planner.functions.casting.BinaryToBinaryCastRule.couldPad;
+import static org.apache.flink.table.planner.functions.casting.BinaryToBinaryCastRule.couldTrim;
+import static org.apache.flink.table.planner.functions.casting.BinaryToBinaryCastRule.trimOrPadByteArray;
+import static org.apache.flink.table.planner.functions.casting.CastRuleUtils.arrayLength;
+import static org.apache.flink.table.planner.functions.casting.CastRuleUtils.methodCall;
+
+/** {@link LogicalTypeRoot#BITMAP} to {@link LogicalTypeFamily#BINARY_STRING} cast rule. */
+class BitmapToBinaryCastRule extends AbstractNullAwareCodeGeneratorCastRule<Bitmap, byte[]> {
+
+ static final BitmapToBinaryCastRule INSTANCE = new BitmapToBinaryCastRule();
+
+ private BitmapToBinaryCastRule() {
+ super(
+ CastRulePredicate.builder()
+ .input(LogicalTypeRoot.BITMAP)
+ .target(LogicalTypeFamily.BINARY_STRING)
+ .build());
+ }
+
+ @Override
+ protected String generateCodeBlockInternal(
+ CodeGeneratorCastRule.Context context,
+ String inputTerm,
+ String returnVariable,
+ LogicalType inputLogicalType,
+ LogicalType targetLogicalType) {
+ final int targetLength = LogicalTypeChecks.getLength(targetLogicalType);
+ final String byteArrayTerm =
+ CodeGenUtils.newName(context.getCodeGeneratorContext(), "bitmapBytes");
+
+ if (context.legacyBehaviour()
+ || !(couldTrim(targetLength) || couldPad(targetLogicalType, targetLength))) {
+ return new CastRuleUtils.CodeWriter()
+ .assignStmt(returnVariable, methodCall(inputTerm, "toBytes"))
+ .toString();
+ } else {
+ return new CastRuleUtils.CodeWriter()
+ .declStmt(byte[].class, byteArrayTerm, methodCall(inputTerm, "toBytes"))
+ .ifStmt(
+ arrayLength(byteArrayTerm) + " <= " + targetLength,
+ thenWriter -> {
+ if (couldPad(targetLogicalType, targetLength)) {
+ trimOrPadByteArray(
Review Comment:
IIUC `trimOrPadByteArray` will perform a tail-cut operation (retaining the first N bytes), it may lead to data corruption for Bitmap's RoaringBitmap serialization format (header + container array) which will be undeserializable after truncation?
##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/data/conversion/BitmapBitmapConverter.java:
##########
@@ -0,0 +1,47 @@
+/*
+ * 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.data.conversion;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.types.bitmap.Bitmap;
+import org.apache.flink.types.bitmap.RoaringBitmapData;
+
+/**
+ * Converter for {@link org.apache.flink.table.types.logical.BitmapType BitmapType} of unknown
Review Comment:
nit: The Javadoc says "unknown Bitmap external type", but toInternal() only accepts RoaringBitmapData and rejects all other Bitmap implementations. Consider updating the Javadoc to reflect this constraint, e.g., "Converter for {@link RoaringBitmapData} as the external Bitmap type."
##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/data/RowData.java:
##########
@@ -205,6 +206,11 @@ public interface RowData {
/** Returns the variant value at the given position. */
Variant getVariant(int pos);
+ /** Returns the bitmap value at the given position. */
+ default Bitmap getBitmap(int pos) {
+ throw new UnsupportedOperationException("Bitmap is not supported yet.");
Review Comment:
This error message is slightly misleading, it's not a temporary limitation of the type system, but rather that this particular RowData implementation hasn't provided BITMAP support. Something like "This RowData implementation does not support Bitmap type." would be clearer.
##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/data/RowData.java:
##########
Review Comment:
nit: The type mapping table is missing the new BITMAP entry.
--
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-39185][table] Introduce BITMAP type for Table API/SQL [flink]
Posted by "dylanhz (via GitHub)" <gi...@apache.org>.
dylanhz commented on code in PR #27778:
URL: https://github.com/apache/flink/pull/27778#discussion_r2980838101
##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/functions/casting/BitmapToBinaryCastRule.java:
##########
@@ -0,0 +1,88 @@
+/*
+ * 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.planner.functions.casting;
+
+import org.apache.flink.table.planner.codegen.CodeGenUtils;
+import org.apache.flink.table.types.logical.LogicalType;
+import org.apache.flink.table.types.logical.LogicalTypeFamily;
+import org.apache.flink.table.types.logical.LogicalTypeRoot;
+import org.apache.flink.table.types.logical.utils.LogicalTypeChecks;
+import org.apache.flink.types.bitmap.Bitmap;
+
+import static org.apache.flink.table.planner.functions.casting.BinaryToBinaryCastRule.couldPad;
+import static org.apache.flink.table.planner.functions.casting.BinaryToBinaryCastRule.couldTrim;
+import static org.apache.flink.table.planner.functions.casting.BinaryToBinaryCastRule.trimOrPadByteArray;
+import static org.apache.flink.table.planner.functions.casting.CastRuleUtils.arrayLength;
+import static org.apache.flink.table.planner.functions.casting.CastRuleUtils.methodCall;
+
+/** {@link LogicalTypeRoot#BITMAP} to {@link LogicalTypeFamily#BINARY_STRING} cast rule. */
+class BitmapToBinaryCastRule extends AbstractNullAwareCodeGeneratorCastRule<Bitmap, byte[]> {
+
+ static final BitmapToBinaryCastRule INSTANCE = new BitmapToBinaryCastRule();
+
+ private BitmapToBinaryCastRule() {
+ super(
+ CastRulePredicate.builder()
+ .input(LogicalTypeRoot.BITMAP)
+ .target(LogicalTypeFamily.BINARY_STRING)
+ .build());
+ }
+
+ @Override
+ protected String generateCodeBlockInternal(
+ CodeGeneratorCastRule.Context context,
+ String inputTerm,
+ String returnVariable,
+ LogicalType inputLogicalType,
+ LogicalType targetLogicalType) {
+ final int targetLength = LogicalTypeChecks.getLength(targetLogicalType);
+ final String byteArrayTerm =
+ CodeGenUtils.newName(context.getCodeGeneratorContext(), "bitmapBytes");
+
+ if (context.legacyBehaviour()
+ || !(couldTrim(targetLength) || couldPad(targetLogicalType, targetLength))) {
+ return new CastRuleUtils.CodeWriter()
+ .assignStmt(returnVariable, methodCall(inputTerm, "toBytes"))
+ .toString();
+ } else {
+ return new CastRuleUtils.CodeWriter()
+ .declStmt(byte[].class, byteArrayTerm, methodCall(inputTerm, "toBytes"))
+ .ifStmt(
+ arrayLength(byteArrayTerm) + " <= " + targetLength,
+ thenWriter -> {
+ if (couldPad(targetLogicalType, targetLength)) {
+ trimOrPadByteArray(
Review Comment:
Restricted to `BYTES` only to avoid data corruption from trimming/padding. Also added UT cases in `CastRulesTest` which don't rely on literal.
--
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