stevenzwu commented on code in PR #9464:
URL: https://github.com/apache/iceberg/pull/9464#discussion_r1566450101


##########
flink/v1.18/flink/src/main/java/org/apache/iceberg/flink/source/split/IcebergSourceSplit.java:
##########
@@ -157,21 +165,56 @@ byte[] serializeV2() throws IOException {
     return serializedBytesCache;
   }
 
+  private static void writeLongUTF(DataOutputSerializer out, String taskJson, 
int version)

Review Comment:
   this method is inaccurate. `writeTaskJson` is probably more accurate.



##########
flink/v1.18/flink/src/main/java/org/apache/iceberg/flink/source/split/SerializerHelper.java:
##########
@@ -0,0 +1,200 @@
+/*
+ * 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.iceberg.flink.source.split;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.io.UTFDataFormatException;
+import org.apache.flink.core.memory.DataInputDeserializer;
+import org.apache.flink.core.memory.DataOutputSerializer;
+
+/**
+ * Helper class to serialize and deserialize strings longer than 65K. The 
inspiration is mostly
+ * taken from the class 
org.apache.flink.core.memory.DataInputSerializer.readUTF and
+ * org.apache.flink.core.memory.DataOutputSerializer.writeUTF.
+ */
+public class SerializerHelper implements Serializable {

Review Comment:
   this can be package private



##########
flink/v1.18/flink/src/main/java/org/apache/iceberg/flink/source/split/SerializerHelper.java:
##########
@@ -0,0 +1,200 @@
+/*
+ * 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.iceberg.flink.source.split;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.io.UTFDataFormatException;
+import org.apache.flink.core.memory.DataInputDeserializer;
+import org.apache.flink.core.memory.DataOutputSerializer;
+
+/**
+ * Helper class to serialize and deserialize strings longer than 65K. The 
inspiration is mostly
+ * taken from the class 
org.apache.flink.core.memory.DataInputSerializer.readUTF and
+ * org.apache.flink.core.memory.DataOutputSerializer.writeUTF.
+ */
+public class SerializerHelper implements Serializable {
+
+  /**
+   * Similar to {@link DataOutputSerializer#writeUTF(String)}. Except this 
supports larger payloads
+   * which is up to max integer value.
+   *
+   * @param out the output stream to write the string to.
+   * @param str the string value to be written.
+   * @deprecated This method is deprecated because there will be a method 
within the {@link
+   *     DataOutputSerializer} already which does the same thing, so use that 
one instead once that
+   *     is released on Flink version 1.20.
+   *     <p>See * <a 
href="https://issues.apache.org/jira/browse/FLINK-34228";>FLINK-34228</a> * <a
+   *     
href="https://github.com/apache/flink/pull/24191";>https://github.com/apache/flink/pull/24191</a>
+   */
+  @Deprecated
+  public static void writeLongUTF(DataOutputSerializer out, String str) throws 
IOException {
+    int strlen = str.length();
+    long utflen = 0;
+    int c;
+
+    /* use charAt instead of copying String to char array */
+    for (int i = 0; i < strlen; i++) {
+      c = str.charAt(i);
+      utflen += getUTFBytesSize(c);
+
+      if (utflen > Integer.MAX_VALUE) {
+        throw new UTFDataFormatException("Encoded string reached maximum 
length: " + utflen);
+      }
+    }
+    if (utflen > Integer.MAX_VALUE - 4) {
+      throw new UTFDataFormatException("Encoded string is too long: " + 
utflen);
+    }
+
+    out.writeInt((int) utflen);
+    writeUTFBytes(out, str, (int) utflen);
+  }
+
+  /**
+   * Similar to {@link DataInputDeserializer#readUTF()}. Except this supports 
larger payloads which
+   * is up to max integer value.
+   *
+   * @param in the input stream to read the string from.
+   * @return the string value read from the input stream.
+   * @throws IOException if an I/O error occurs when reading from the input 
stream.
+   * @deprecated This method is deprecated because there will be a method 
within the {@link
+   *     DataInputDeserializer} already which does the same thing, so use that 
one instead once that
+   *     is released on Flink version 1.20.
+   *     <p>See * <a 
href="https://issues.apache.org/jira/browse/FLINK-34228";>FLINK-34228</a> * <a
+   *     
href="https://github.com/apache/flink/pull/24191";>https://github.com/apache/flink/pull/24191</a>
+   */
+  @Deprecated

Review Comment:
   why is this marked as deprecated? as mentioned above, making the class 
package private is probably better



##########
flink/v1.18/flink/src/main/java/org/apache/iceberg/flink/source/split/SerializerHelper.java:
##########
@@ -0,0 +1,186 @@
+/*
+ * 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.iceberg.flink.source.split;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.io.UTFDataFormatException;
+import org.apache.flink.core.memory.DataInputDeserializer;
+import org.apache.flink.core.memory.DataOutputSerializer;
+
+/**
+ * Helper class to serialize and deserialize strings longer than 65K. The 
inspiration is mostly
+ * taken from the class 
org.apache.flink.core.memory.DataInputSerializer.readUTF and
+ * org.apache.flink.core.memory.DataOutputSerializer.writeUTF.
+ */
+public class SerializerHelper implements Serializable {
+
+  /**
+   * Similar to {@link DataOutputSerializer#writeUTF(String)}. The size is 
only limited by the
+   * maximum java array size of the buffer.
+   *
+   * @param out the output stream to write the string to.
+   * @param str the string value to be written.
+   * @deprecated This method is deprecated because there will be a method 
within the {@link
+   *     DataOutputSerializer} already which does the same thing, so use that 
one instead once that
+   *     is released on Flink version 1.20.
+   *     <p>See * <a 
href="https://issues.apache.org/jira/browse/FLINK-34228";>FLINK-34228</a> * <a
+   *     
href="https://github.com/apache/flink/pull/24191";>https://github.com/apache/flink/pull/24191</a>
+   */
+  @Deprecated
+  public static void writeLongUTF(DataOutputSerializer out, String str) throws 
IOException {
+    int strlen = str.length();
+    long utflen = 0;
+    int c;
+
+    /* use charAt instead of copying String to char array */
+    for (int i = 0; i < strlen; i++) {
+      c = str.charAt(i);
+      utflen += getUTFBytesSize(c);
+
+      if (utflen > Integer.MAX_VALUE) {
+        throw new UTFDataFormatException("Encoded string reached maximum 
length: " + utflen);
+      }
+    }
+    if (utflen > Integer.MAX_VALUE - 4) {
+      throw new UTFDataFormatException("Encoded string is too long: " + 
utflen);
+    }
+

Review Comment:
   `out.writeInt` only increases the buffer by 4 to hold the integer.
   
   I think we need the resize call here. but this does impose the blocker here 
because `DataInputDeserializer#resize(int minCapacityAdd)` is a private method 
here. I am not sure this can work (just copying the read/writeLongUTF`.
   
   ```
   if (utflen > Integer.MAX_VALUE - 4) {
               throw new UTFDataFormatException("Encoded string is too long: " 
+ utflen);
           } else if (this.position > this.buffer.length - utflen - 2) {
               resize((int) utflen + 4);
           }
   ```
   
   cc @pvary @elkhand 



-- 
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-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to