philo-he commented on code in PR #13670:
URL: https://github.com/apache/gluten/pull/13670#discussion_r4721449193
##########
gluten-flink/planner/src/main/java/org/apache/gluten/rexnode/TypeUtils.java:
##########
@@ -64,9 +64,10 @@ public static boolean isStringType(Type type) {
// Matches the scalar signatures registered under the velox flinksql
// namespace: booleans, numerics, strings, dates, timestamps and decimals.
- // BINARY, ARRAY, MAP and ROW have no flinksql registration and are
- // rejected at the converter level so conversion fails at planning time
- // instead of failing at runtime.
+ // BINARY has flinksql registrations only for the hash family, so it is not a
Review Comment:
Only `ScalarOnlyRexCallConverter` (`IFNULL`) checks this.
`DefaultRexCallConverter` accepts any operand type, and before this PR BYTES
was stopped by `toType`. Now `CONCAT(b1, b2)`, `SUBSTRING(b, 1, 2)`, `LIKE`,
`REPLACE` etc. on BYTES pass planning and, without flinksql VARBINARY
signatures, fail at runtime.
Could we reject calls with a VARBINARY operand/result unless the function is
allowlisted (hash family, string->bytes CAST, CASE/COALESCE/IS NULL)? A UT for
e.g. `CONCAT` on BYTES would pin it.
##########
gluten-flink/runtime/src/main/java/org/apache/gluten/util/LogicalTypeConverter.java:
##########
@@ -67,6 +68,11 @@ private interface VLTypeConverter {
logicalType -> new
io.github.zhztheplayer.velox4j.type.VarCharType()),
Map.entry(
CharType.class, logicalType -> new
io.github.zhztheplayer.velox4j.type.VarCharType()),
+ // BYTES maps to VARBINARY; fixed-length BINARY(n) stays unmapped
+ // because velox cannot preserve its pad/truncate semantics.
+ Map.entry(
+ VarBinaryType.class,
Review Comment:
This maps every `VARBINARY(n)`, not only `BYTES` (`VARBINARY(MAX)`), so the
length is dropped the same way it was for `BINARY(n)`.
Flink truncates to `n` on cast (`StringToBinaryCastRule` /
`BinaryToBinaryCastRule` use `Arrays.copyOf(bytes, n)` when `n < MAX_LENGTH`).
Velox keeps all bytes, so these now return wrong digests instead of failing at
planning:
- `MD5(CAST(s AS VARBINARY(3)))` with `s = 'abcdef'`: Flink hashes `abc`,
gluten hashes `abcdef`
- `MD5(CAST(bytes_col AS VARBINARY(2)))`
Suggest rejecting in the CAST branch of `RexNodeConverter` when the target
is BINARY-family with length < `MAX_LENGTH`, unless the operand is
BINARY-family with length <= target length (Flink's no-op case). Please add UTs
for both queries above.
##########
gluten-flink/ut/src/test/java/org/apache/gluten/table/runtime/stream/custom/HashFunctionsTest.java:
##########
@@ -91,6 +97,151 @@ void testSha1() {
"+I[null]"));
}
+ // BYTES via a column cast (a literal would fold); non-UTF-8 bytes need the
+ // source-column test 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 raw-file BYTES column crossing the Flink -> velox boundary;
+ // "nonutf8" (a NUL + non-UTF-8 byte) proves the digests come from raw bytes.
+ @Test
+ void testMd5Sha1BinarySourceColumn(@TempDir File dataDir) throws Exception {
+ Files.write(new File(dataDir, "ab").toPath(), new byte[] {0x61, 0x62});
+ Files.write(new File(dataDir, "nonutf8").toPath(), new byte[] {0x00,
(byte) 0xFF, 0x10});
+ Files.write(new File(dataDir, "utf8").toPath(),
"你好".getBytes(StandardCharsets.UTF_8));
+ tEnv()
+ .executeSql(
+ "CREATE TABLE binSrc (`value` BYTES) WITH ("
+ + "'connector' = 'filesystem',"
+ + "'path' = '"
+ + dataDir.toURI()
+ + "',"
+ + "'format' = 'raw')");
+ // The print sink prefixes rows with the parallel subtask ("3> +I[...]").
+ List<String> rows =
+ runQuery("select MD5(`value`), SHA1(`value`) from binSrc").stream()
+ .map(row -> row.replaceFirst("^\\d+> ", ""))
+ .collect(java.util.stream.Collectors.toList());
Review Comment:
nit: import `java.util.stream.Collectors` instead of the fully qualified
name.
##########
gluten-flink/planner/src/main/java/org/apache/gluten/rexnode/RexNodeConverter.java:
##########
@@ -311,8 +323,8 @@ public static Variant toVariant(RexLiteral literal) {
// For CHAR, we convert it to VARCHAR
return new VarCharValue(literal.getValueAs(String.class));
case BINARY:
Review Comment:
nit: `case BINARY` is unreachable now, since `toType(literal.getType())`
throws for `BINARY(n)` first. Either drop it, or map `BINARY(n)` literals (a
literal is exactly `n` bytes, so no padding is needed) so bare `X'..'` operands
work.
--
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]