ggjh-159 commented on code in PR #13670:
URL: https://github.com/apache/gluten/pull/13670#discussion_r4674815975
##########
gluten-flink/runtime/src/main/java/org/apache/gluten/util/LogicalTypeConverter.java:
##########
@@ -67,6 +69,14 @@ private interface VLTypeConverter {
logicalType -> new
io.github.zhztheplayer.velox4j.type.VarCharType()),
Map.entry(
CharType.class, logicalType -> new
io.github.zhztheplayer.velox4j.type.VarCharType()),
+ // Flink's BYTES/BINARY are both a byte array at runtime (RowData
+ // getBinary), and velox carries them as VARBINARY.
+ Map.entry(
+ VarBinaryType.class,
+ logicalType -> new
io.github.zhztheplayer.velox4j.type.VarbinaryType()),
+ Map.entry(
+ BinaryType.class,
+ logicalType -> new
io.github.zhztheplayer.velox4j.type.VarbinaryType()),
Review Comment:
Mapping BINARY(n) to VarbinaryType drops the fixed-length semantics, so
CAST(x AS BINARY(n)) is now offloaded and silently returns wrong bytes: Flink
zero-pads or truncates to n (CAST('ab' AS BINARY(3)) -> [97, 98, 0],
CAST('abcdef' AS BINARY(3)) -> [97, 98, 99]), while the velox value keeps the
unpadded/untruncated length. With this PR plus the companion velox4j/velox
changes, MD5(CAST('ab' AS BINARY(3))) returns 187ef443... instead of Flink's
5d36fe0e..., and CAST(CAST('ab' AS BINARY(3)) AS VARCHAR) returns 'ab' instead
of 'ab\0' — a digest divergence in the hash family this issue targets, on a
query that used to fail at planning. Either implement the fixed-length
semantics (pad/truncate to n, including CAST targets of BINARY(n)) or restrict
the mapping to VarBinaryType so BINARY(n) is still rejected at planning; in
both cases add a UT pinning MD5(CAST('ab' AS BINARY(3))).
##########
gluten-flink/ut/src/test/java/org/apache/gluten/table/runtime/stream/custom/HashFunctionsTest.java:
##########
@@ -91,6 +95,67 @@ void testSha1() {
"+I[null]"));
}
+ // Flink's hash expressions also accept BYTES and digest the raw bytes. The
+ // BYTES operand comes from a column cast, so the digest is computed at
+ // runtime (a literal would be constant-folded) by the VARBINARY signature.
+ // Non-UTF-8 bytes cannot be built with a cast; see
+ // testMd5Sha1BinarySourceColumn below.
+ @Test
+ void testMd5Sha1Sha256VarbinaryInput() {
+ List<Row> rows =
+ Arrays.asList(Row.of("", 1), Row.of("ab", 2), Row.of("你好", 3),
Row.of(null, 4));
+ createSimpleBoundedValuesTable("tblHashBinary", "s varchar, a int", rows);
+ runAndCheck(
+ "select MD5(CAST(s AS BYTES)), SHA1(CAST(s AS BYTES)), SHA256(CAST(s
AS BYTES))"
+ + " from tblHashBinary where a > 0",
+ Arrays.asList(
+ "+I["
+ + MD5_EMPTY
+ + ", "
+ + SHA1_EMPTY
+ + ",
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855]",
+ "+I[187ef4436122d1cc2f40dc2b92f0eba0, "
+ + "da23614e02469a0d7c7bd1bdab5c9c474b1904dc, "
+ +
"fb8e20fc2e4c3f248c60c39bd652f3c1347298bb977b8b4d5903b85055620603]",
+ "+I[7eca689f0d3389d9dea66ae112e5cfd7, "
+ + "440ee0853ad1e99f962b63e459ef992d7c211722, "
+ +
"670d9743542cae3ea7ebe36af56bd53648b0a1126162e78d81a32934a711302e]",
+ "+I[null, null, null]"));
+ }
+
+ // A genuine BYTES source column: the raw-format filesystem source is not
+ // offloaded, so each file arrives as RowData and crosses the Flink -> velox
+ // boundary through the VARBINARY Arrow writer. "nonutf8" pins a NUL plus a
+ // non-UTF-8 byte, so the digests can only come from the raw bytes.
+ @Test
+ void testMd5Sha1BinarySourceColumn(@TempDir File dataDir) throws Exception {
Review Comment:
The velox -> Arrow -> RowData output path for VARBINARY has no SQL-level
coverage: in this PR's SQL tests BYTES is only an input and every output is
VARCHAR (the accessor is exercised only by the round-trip test), and the
harness's print sink cannot carry VARBINARY (the velox print connector rejects
it in StringFormatter.cpp:74). Please add a test that projects the BYTES column
itself through a collect sink (e.g. over the raw filesystem source already used
in testMd5Sha1BinarySourceColumn) and asserts the byte[] values come back
unchanged.
##########
gluten-flink/runtime/src/main/java/org/apache/gluten/util/LogicalTypeConverter.java:
##########
@@ -67,6 +69,14 @@ private interface VLTypeConverter {
logicalType -> new
io.github.zhztheplayer.velox4j.type.VarCharType()),
Map.entry(
CharType.class, logicalType -> new
io.github.zhztheplayer.velox4j.type.VarCharType()),
+ // Flink's BYTES/BINARY are both a byte array at runtime (RowData
+ // getBinary), and velox carries them as VARBINARY.
+ Map.entry(
+ VarBinaryType.class,
Review Comment:
With VarBinaryType mapped, CAST(bytes AS STRING) is newly offloaded, but
velox reinterprets the bytes as-is while Flink decodes as UTF-8
(BinaryToStringCastRule: new String(bytes, UTF_8), invalid sequences replaced
by U+FFFD). Over a source column X'00FF10', MD5(CAST(value AS STRING)) returns
481e4551... with gluten versus 55436047... in Flink (digest of 00 EF BF BD 10).
Please keep CASTs involving VARBINARY from being offloaded (rejected at
planning like IFNULL) or implement the UTF-8 decoding semantics, and add a test
for CAST(bytes AS STRING) over non-UTF-8 bytes.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]