luoyuxia commented on code in PR #1409:
URL: https://github.com/apache/fluss/pull/1409#discussion_r2253039359
##########
fluss-common/src/main/java/com/alibaba/fluss/row/encode/iceberg/IcebergBinaryRowWriter.java:
##########
@@ -108,6 +108,10 @@ public void writeInt(int value) {
cursor += 4;
}
Review Comment:
https://github.com/apache/fluss/pull/1409/files#diff-7abad54abe02e1439706ca3b9f55ddc33bbee6501b342fc17606991fb04bf220R69
I saw warning `Condition 'cursor > 0' is always 'false' `, could you please
fix it in this pr?
##########
fluss-common/src/test/java/com/alibaba/fluss/row/encode/iceberg/IcebergKeyEncoderTest.java:
##########
@@ -79,11 +82,23 @@ void testIntegerEncoding() throws IOException {
// Encode with our implementation
byte[] ourEncoded = encoder.encodeKey(row);
+ // This is the equivalent bytes array which the key should be encoded
to.
+ byte[] equivalentBytes = toBytes(testValue);
+ assertThat(ourEncoded).isEqualTo(equivalentBytes);
+
// Encode with Iceberg's implementation
ByteBuffer icebergBuffer =
Conversions.toByteBuffer(Types.IntegerType.get(), testValue);
Review Comment:
Let's forget iceberg's Conversions in here. We can hard code the expected
iceberge encoded bytes.
##########
fluss-common/src/main/java/com/alibaba/fluss/row/encode/iceberg/IcebergBinaryRowWriter.java:
##########
@@ -127,26 +131,42 @@ public void writeDouble(double value) {
}
public void writeString(BinaryString value) {
+ writeString(value, false);
+ }
+
+ public void writeString(BinaryString value, boolean skipPrefix) {
Review Comment:
nit:
`skipPrefix` -> `skipEncodeLength`?
##########
fluss-common/src/test/java/com/alibaba/fluss/row/encode/iceberg/IcebergKeyEncoderTest.java:
##########
@@ -142,9 +165,13 @@ void testDecimalEncoding() throws IOException {
// Encode with our implementation
byte[] ourEncoded = encoder.encodeKey(row);
+ // This is the equivalent bytes array which the key should be encoded
to.
+ byte[] equivalentBytes = testValue.unscaledValue().toByteArray();
+ assertThat(ourEncoded).isEqualTo(equivalentBytes);
+
// Extract the decimal length prefix and bytes from ourEncoded
Review Comment:
also remove this comments.
##########
fluss-common/src/test/java/com/alibaba/fluss/row/encode/iceberg/IcebergBinaryRowWriterTest.java:
##########
@@ -0,0 +1,221 @@
+/*
+ * 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 com.alibaba.fluss.row.encode.iceberg;
+
+import com.alibaba.fluss.row.BinaryString;
+import com.alibaba.fluss.row.Decimal;
+
+import org.junit.jupiter.api.Test;
+
+import java.math.BigDecimal;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/** Unit tests for {@link IcebergBinaryRowWriter}. */
+public class IcebergBinaryRowWriterTest {
Review Comment:
nit:
```suggestion
class IcebergBinaryRowWriterTest {
```
##########
fluss-common/src/test/java/com/alibaba/fluss/testutils/RowUtils.java:
##########
@@ -0,0 +1,170 @@
+/*
+ * 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 com.alibaba.fluss.testutils;
+
+import com.alibaba.fluss.row.BinaryString;
+import com.alibaba.fluss.row.Decimal;
+import com.alibaba.fluss.row.TimestampLtz;
+import com.alibaba.fluss.row.TimestampNtz;
+import com.alibaba.fluss.row.indexed.IndexedRow;
+import com.alibaba.fluss.row.indexed.IndexedRowWriter;
+import com.alibaba.fluss.types.DataType;
+import com.alibaba.fluss.types.DataTypes;
+
+import java.io.IOException;
+import java.math.BigDecimal;
+
+import static com.alibaba.fluss.types.DataTypeChecks.getPrecision;
+
+/** Util class to create {@link IndexedRow} with different data types. */
+public class RowUtils {
Review Comment:
Do we really need this class. I'm afraid of it'll bring maintenance burden.
Can we just use
`GenericRow row = GenericRow.of(value);`
....
in where we call `RowUtils`?
##########
fluss-common/src/main/java/com/alibaba/fluss/row/encode/iceberg/IcebergBinaryRowWriter.java:
##########
@@ -127,26 +131,42 @@ public void writeDouble(double value) {
}
public void writeString(BinaryString value) {
+ writeString(value, false);
+ }
+
+ public void writeString(BinaryString value, boolean skipPrefix) {
Review Comment:
Or just remove `skipPrefix` now, and always skip encode prefix since we
always `skipPrefix` in code path.
##########
fluss-common/src/test/java/com/alibaba/fluss/bucketing/IcebergBucketingFunctionTest.java:
##########
@@ -0,0 +1,265 @@
+/*
+ * 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 com.alibaba.fluss.bucketing;
+
+import com.alibaba.fluss.row.encode.iceberg.IcebergKeyEncoder;
+import com.alibaba.fluss.row.indexed.IndexedRow;
+import com.alibaba.fluss.types.DataType;
+import com.alibaba.fluss.types.DataTypes;
+import com.alibaba.fluss.types.RowType;
+
+import org.apache.iceberg.transforms.Transform;
+import org.apache.iceberg.transforms.Transforms;
+import org.apache.iceberg.types.Types;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.charset.StandardCharsets;
+import java.util.Collections;
+
+import static com.alibaba.fluss.testutils.RowUtils.createRowWithBytes;
+import static com.alibaba.fluss.testutils.RowUtils.createRowWithDate;
+import static com.alibaba.fluss.testutils.RowUtils.createRowWithDecimal;
+import static com.alibaba.fluss.testutils.RowUtils.createRowWithInt;
+import static com.alibaba.fluss.testutils.RowUtils.createRowWithLong;
+import static com.alibaba.fluss.testutils.RowUtils.createRowWithString;
+import static com.alibaba.fluss.testutils.RowUtils.createRowWithTime;
+import static com.alibaba.fluss.testutils.RowUtils.createRowWithTimestampNtz;
+import static org.assertj.core.api.Assertions.assertThat;
+
+/** Unit test for {@link IcebergBucketingFunction}. */
+public class IcebergBucketingFunctionTest {
Review Comment:
nit:
```suggestion
class IcebergBucketingFunctionTest {
```
##########
fluss-common/src/main/java/com/alibaba/fluss/row/encode/iceberg/IcebergBinaryRowWriter.java:
##########
@@ -108,6 +108,10 @@ public void writeInt(int value) {
cursor += 4;
}
Review Comment:
Also, I think we should update the comments of this class now since it's
mainly to encode to be align with Iceberg bucket transform with
`MURMUR3.hashBytes` method of iceberg, right? It's not based on
`Conversions.toByteBuffer()` now. Let's forget iceberg `Conversions` .
##########
fluss-common/src/main/java/com/alibaba/fluss/row/encode/iceberg/IcebergBinaryRowWriter.java:
##########
@@ -108,6 +108,10 @@ public void writeInt(int value) {
cursor += 4;
}
Review Comment:
`Private field 'arity' is assigned but never accessed `
##########
fluss-common/src/test/java/com/alibaba/fluss/row/encode/iceberg/IcebergKeyEncoderTest.java:
##########
@@ -116,9 +135,13 @@ void testStringEncoding() throws IOException {
// Encode with our implementation
byte[] ourEncoded = encoder.encodeKey(row);
+ // This is the equivalent bytes array which the key should be encoded
to.
+ byte[] equivalentBytes = testValue.getBytes(StandardCharsets.UTF_8);
+ assertThat(ourEncoded).isEqualTo(equivalentBytes);
+
// Decode length prefix
Review Comment:
nit:
remove this comment. we don't need decode length prefix since the length
prefix is not encoded.
##########
fluss-common/src/test/java/com/alibaba/fluss/row/encode/iceberg/IcebergKeyEncoderTest.java:
##########
@@ -194,11 +224,23 @@ void testDateEncoding() throws IOException {
// Encode with our implementation
byte[] ourEncoded = encoder.encodeKey(row);
+ // This is the equivalent bytes array which the key should be encoded
to.
+ byte[] equivalentBytes = toBytes(dateValue);
+ assertThat(ourEncoded).isEqualTo(equivalentBytes);
+
// Encode with Iceberg's implementation
ByteBuffer icebergBuffer =
Conversions.toByteBuffer(Types.DateType.get(), dateValue);
byte[] icebergEncoded = toByteArray(icebergBuffer);
- assertThat(ourEncoded).isEqualTo(icebergEncoded);
+ // In Iceberg `Conversions` class, it treats the 'testValue' as an
integer, the output bytes
Review Comment:
nit: dito
Let's also forget the iceberge `Conversions`.
##########
fluss-common/src/main/java/com/alibaba/fluss/row/encode/iceberg/IcebergBinaryRowWriter.java:
##########
@@ -108,6 +108,10 @@ public void writeInt(int value) {
cursor += 4;
}
Review Comment:
`Method 'setNullAt(int)' is never used `
--
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]