You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2022/01/10 05:50:16 UTC

[GitHub] [iceberg] stevenzwu opened a new pull request #3866: Flink: RecordFactory interface that can create record batch and clone…

stevenzwu opened a new pull request #3866:
URL: https://github.com/apache/iceberg/pull/3866


   … record, which are needed by DataIteratorBatcher


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

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



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


[GitHub] [iceberg] rdblue commented on a change in pull request #3866: Flink: RecordFactory interface that can create record batch and clone…

Posted by GitBox <gi...@apache.org>.
rdblue commented on a change in pull request #3866:
URL: https://github.com/apache/iceberg/pull/3866#discussion_r799672011



##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/reader/RowDataRecordFactory.java
##########
@@ -0,0 +1,57 @@
+/*
+ * 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.reader;
+
+import org.apache.flink.api.common.typeutils.TypeSerializer;
+import org.apache.flink.table.data.GenericRowData;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.runtime.typeutils.InternalSerializers;
+import org.apache.flink.table.types.logical.RowType;
+import org.apache.iceberg.flink.data.RowDataUtil;
+
+class RowDataRecordFactory implements RecordFactory<RowData> {
+  private final RowType rowType;
+  private final TypeSerializer[] fieldSerializers;
+
+  RowDataRecordFactory(final RowType rowType) {
+    this.rowType = rowType;
+    this.fieldSerializers = createFieldSerializers(rowType);
+  }
+
+  static TypeSerializer[] createFieldSerializers(RowType rowType) {
+    return rowType.getChildren().stream()
+        .map(InternalSerializers::create)
+        .toArray(TypeSerializer[]::new);
+  }
+
+  @Override
+  public RowData[] createBatch(int batchSize) {
+    RowData[] arr = new RowData[batchSize];
+    for (int i = 0; i < batchSize; ++i) {
+      arr[i] = new GenericRowData(rowType.getFieldCount());
+    }
+    return arr;
+  }
+
+  @Override
+  public void clone(RowData from, RowData to) {

Review comment:
       You might consider changing this to `clone(RowData from, RowData[] toBatch, int position)`




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

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



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


[GitHub] [iceberg] stevenzwu commented on a change in pull request #3866: Flink: RecordFactory interface that can create record batch and clone…

Posted by GitBox <gi...@apache.org>.
stevenzwu commented on a change in pull request #3866:
URL: https://github.com/apache/iceberg/pull/3866#discussion_r797284217



##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/reader/RowDataRecordFactory.java
##########
@@ -0,0 +1,57 @@
+/*
+ * 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.reader;
+
+import org.apache.flink.api.common.typeutils.TypeSerializer;
+import org.apache.flink.table.data.GenericRowData;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.runtime.typeutils.InternalSerializers;
+import org.apache.flink.table.types.logical.RowType;
+import org.apache.iceberg.flink.data.RowDataUtil;
+
+class RowDataRecordFactory implements RecordFactory<RowData> {
+  private final RowType rowType;
+  private final TypeSerializer[] fieldSerializers;
+
+  RowDataRecordFactory(final RowType rowType) {
+    this.rowType = rowType;
+    this.fieldSerializers = createFieldSerializers(rowType);
+  }
+
+  static TypeSerializer[] createFieldSerializers(RowType rowType) {
+    return rowType.getChildren().stream()
+        .map(InternalSerializers::create)
+        .toArray(TypeSerializer[]::new);
+  }
+
+  @Override
+  public RowData[] createBatch(int batchSize) {
+    RowData[] arr = new RowData[batchSize];
+    for (int i = 0; i < batchSize; ++i) {
+      arr[i] = new GenericRowData(rowType.getFieldCount());

Review comment:
       it is just a getter, which should be optimized by JVM




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

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



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


[GitHub] [iceberg] rdblue merged pull request #3866: Flink: RecordFactory interface that can create record batch and clone…

Posted by GitBox <gi...@apache.org>.
rdblue merged pull request #3866:
URL: https://github.com/apache/iceberg/pull/3866


   


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

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



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


[GitHub] [iceberg] rdblue commented on a change in pull request #3866: Flink: RecordFactory interface that can create record batch and clone…

Posted by GitBox <gi...@apache.org>.
rdblue commented on a change in pull request #3866:
URL: https://github.com/apache/iceberg/pull/3866#discussion_r799671011



##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/reader/RowDataRecordFactory.java
##########
@@ -0,0 +1,57 @@
+/*
+ * 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.reader;
+
+import org.apache.flink.api.common.typeutils.TypeSerializer;
+import org.apache.flink.table.data.GenericRowData;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.runtime.typeutils.InternalSerializers;
+import org.apache.flink.table.types.logical.RowType;
+import org.apache.iceberg.flink.data.RowDataUtil;
+
+class RowDataRecordFactory implements RecordFactory<RowData> {
+  private final RowType rowType;
+  private final TypeSerializer[] fieldSerializers;
+
+  RowDataRecordFactory(final RowType rowType) {
+    this.rowType = rowType;
+    this.fieldSerializers = createFieldSerializers(rowType);
+  }
+
+  static TypeSerializer[] createFieldSerializers(RowType rowType) {
+    return rowType.getChildren().stream()
+        .map(InternalSerializers::create)
+        .toArray(TypeSerializer[]::new);
+  }
+
+  @Override
+  public RowData[] createBatch(int batchSize) {
+    RowData[] arr = new RowData[batchSize];
+    for (int i = 0; i < batchSize; ++i) {
+      arr[i] = new GenericRowData(rowType.getFieldCount());
+    }
+    return arr;
+  }
+
+  @Override
+  public void clone(RowData from, RowData to) {
+    RowDataUtil.clone(from, to, rowType, fieldSerializers);

Review comment:
       I think this needs to return the RowData produced by `clone` to be correct. Otherwise, there are a few modifications to this class or others that cause correctness bugs.




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

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



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


[GitHub] [iceberg] stevenzwu commented on a change in pull request #3866: Flink: RecordFactory interface that can create record batch and clone…

Posted by GitBox <gi...@apache.org>.
stevenzwu commented on a change in pull request #3866:
URL: https://github.com/apache/iceberg/pull/3866#discussion_r794189941



##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/reader/RecordFactory.java
##########
@@ -0,0 +1,40 @@
+/*
+ * 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.reader;
+
+import java.io.Serializable;
+
+/**
+ * In FLIP-27 source, SplitReader#fetch() returns a batch of records.
+ * Since DataIterator for RowData returns an iterator of reused RowData objects,
+ * RecordFactory is needed to (1) create object array that is recyclable via pool.
+ * (2) clone RowData element from DataIterator to the batch array.
+ */
+interface RecordFactory<T> extends Serializable {

Review comment:
       this is used here: https://github.com/apache/iceberg/pull/2105/files#diff-02187a6086713fc38283adb5f3758155ffa24366e37232665b5549a98fa2f95c




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

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



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


[GitHub] [iceberg] rdblue commented on a change in pull request #3866: Flink: RecordFactory interface that can create record batch and clone…

Posted by GitBox <gi...@apache.org>.
rdblue commented on a change in pull request #3866:
URL: https://github.com/apache/iceberg/pull/3866#discussion_r799666778



##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/reader/RowDataRecordFactory.java
##########
@@ -0,0 +1,57 @@
+/*
+ * 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.reader;
+
+import org.apache.flink.api.common.typeutils.TypeSerializer;
+import org.apache.flink.table.data.GenericRowData;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.runtime.typeutils.InternalSerializers;
+import org.apache.flink.table.types.logical.RowType;
+import org.apache.iceberg.flink.data.RowDataUtil;
+
+class RowDataRecordFactory implements RecordFactory<RowData> {
+  private final RowType rowType;
+  private final TypeSerializer[] fieldSerializers;
+
+  RowDataRecordFactory(final RowType rowType) {

Review comment:
       We usually omit `final` unless it is an instance field.




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

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



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


[GitHub] [iceberg] stevenzwu commented on a change in pull request #3866: Flink: RecordFactory interface that can create record batch and clone…

Posted by GitBox <gi...@apache.org>.
stevenzwu commented on a change in pull request #3866:
URL: https://github.com/apache/iceberg/pull/3866#discussion_r794189941



##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/reader/RecordFactory.java
##########
@@ -0,0 +1,40 @@
+/*
+ * 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.reader;
+
+import java.io.Serializable;
+
+/**
+ * In FLIP-27 source, SplitReader#fetch() returns a batch of records.
+ * Since DataIterator for RowData returns an iterator of reused RowData objects,
+ * RecordFactory is needed to (1) create object array that is recyclable via pool.
+ * (2) clone RowData element from DataIterator to the batch array.
+ */
+interface RecordFactory<T> extends Serializable {

Review comment:
       this is used here: https://github.com/apache/iceberg/pull/2105/files#diff-02187a6086713fc38283adb5f3758155ffa24366e37232665b5549a98fa2f95c




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

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



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


[GitHub] [iceberg] stevenzwu commented on a change in pull request #3866: Flink: RecordFactory interface that can create record batch and clone…

Posted by GitBox <gi...@apache.org>.
stevenzwu commented on a change in pull request #3866:
URL: https://github.com/apache/iceberg/pull/3866#discussion_r799921247



##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/reader/RowDataRecordFactory.java
##########
@@ -0,0 +1,57 @@
+/*
+ * 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.reader;
+
+import org.apache.flink.api.common.typeutils.TypeSerializer;
+import org.apache.flink.table.data.GenericRowData;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.runtime.typeutils.InternalSerializers;
+import org.apache.flink.table.types.logical.RowType;
+import org.apache.iceberg.flink.data.RowDataUtil;
+
+class RowDataRecordFactory implements RecordFactory<RowData> {
+  private final RowType rowType;
+  private final TypeSerializer[] fieldSerializers;
+
+  RowDataRecordFactory(final RowType rowType) {
+    this.rowType = rowType;
+    this.fieldSerializers = createFieldSerializers(rowType);
+  }
+
+  static TypeSerializer[] createFieldSerializers(RowType rowType) {
+    return rowType.getChildren().stream()
+        .map(InternalSerializers::create)
+        .toArray(TypeSerializer[]::new);
+  }
+
+  @Override
+  public RowData[] createBatch(int batchSize) {
+    RowData[] arr = new RowData[batchSize];
+    for (int i = 0; i < batchSize; ++i) {
+      arr[i] = new GenericRowData(rowType.getFieldCount());
+    }
+    return arr;
+  }
+
+  @Override
+  public void clone(RowData from, RowData to) {

Review comment:
       I adopted this API. 
   
   The reason I had the RecordFactory interface is to work with both RowData and Avro GenericRecord iterator. Both Netflix and Apple uses Avro GenericRecord. For the DataIterator with Avro GenericRecord, the iterator returns non-reused/fresh object for every record. In the Avro case, the clone impl can directly set the `from` object into the `toBatch` array.




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

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



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


[GitHub] [iceberg] stevenzwu commented on a change in pull request #3866: Flink: RecordFactory interface that can create record batch and clone…

Posted by GitBox <gi...@apache.org>.
stevenzwu commented on a change in pull request #3866:
URL: https://github.com/apache/iceberg/pull/3866#discussion_r794203999



##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/reader/RecordFactory.java
##########
@@ -0,0 +1,40 @@
+/*
+ * 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.reader;
+
+import java.io.Serializable;
+
+/**
+ * In FLIP-27 source, SplitReader#fetch() returns a batch of records.
+ * Since DataIterator for RowData returns an iterator of reused RowData objects,
+ * RecordFactory is needed to (1) create object array that is recyclable via pool.
+ * (2) clone RowData element from DataIterator to the batch array.
+ */
+interface RecordFactory<T> extends Serializable {
+  /**
+   * Create a batch of records
+   */
+  T[] createBatch(int batchSize);
+
+  /**
+   * Clone record
+   */
+  void clone(T from, T to);

Review comment:
       this is used here: https://github.com/stevenzwu/iceberg/blob/flip27IcebergSourceStaging/flink/v1.13/flink/src/main/java/org/apache/iceberg/flink/source/reader/ArrayPoolDataIteratorBatcher.java#L81




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

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



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


[GitHub] [iceberg] stevenzwu commented on a change in pull request #3866: Flink: RecordFactory interface that can create record batch and clone…

Posted by GitBox <gi...@apache.org>.
stevenzwu commented on a change in pull request #3866:
URL: https://github.com/apache/iceberg/pull/3866#discussion_r794204048



##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/reader/RecordFactory.java
##########
@@ -0,0 +1,40 @@
+/*
+ * 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.reader;
+
+import java.io.Serializable;
+
+/**
+ * In FLIP-27 source, SplitReader#fetch() returns a batch of records.
+ * Since DataIterator for RowData returns an iterator of reused RowData objects,
+ * RecordFactory is needed to (1) create object array that is recyclable via pool.
+ * (2) clone RowData element from DataIterator to the batch array.
+ */
+interface RecordFactory<T> extends Serializable {
+  /**
+   * Create a batch of records
+   */
+  T[] createBatch(int batchSize);

Review comment:
       this is used here: https://github.com/stevenzwu/iceberg/blob/flip27IcebergSourceStaging/flink/v1.13/flink/src/main/java/org/apache/iceberg/flink/source/reader/ArrayPoolDataIteratorBatcher.java#L108




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

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



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


[GitHub] [iceberg] stevenzwu commented on a change in pull request #3866: Flink: RecordFactory interface that can create record batch and clone…

Posted by GitBox <gi...@apache.org>.
stevenzwu commented on a change in pull request #3866:
URL: https://github.com/apache/iceberg/pull/3866#discussion_r799920904



##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/reader/RowDataRecordFactory.java
##########
@@ -0,0 +1,57 @@
+/*
+ * 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.reader;
+
+import org.apache.flink.api.common.typeutils.TypeSerializer;
+import org.apache.flink.table.data.GenericRowData;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.runtime.typeutils.InternalSerializers;
+import org.apache.flink.table.types.logical.RowType;
+import org.apache.iceberg.flink.data.RowDataUtil;
+
+class RowDataRecordFactory implements RecordFactory<RowData> {
+  private final RowType rowType;
+  private final TypeSerializer[] fieldSerializers;
+
+  RowDataRecordFactory(final RowType rowType) {

Review comment:
       fixed




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

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



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


[GitHub] [iceberg] kbendick commented on a change in pull request #3866: Flink: RecordFactory interface that can create record batch and clone…

Posted by GitBox <gi...@apache.org>.
kbendick commented on a change in pull request #3866:
URL: https://github.com/apache/iceberg/pull/3866#discussion_r796212660



##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/reader/RowDataRecordFactory.java
##########
@@ -0,0 +1,57 @@
+/*
+ * 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.reader;
+
+import org.apache.flink.api.common.typeutils.TypeSerializer;
+import org.apache.flink.table.data.GenericRowData;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.runtime.typeutils.InternalSerializers;
+import org.apache.flink.table.types.logical.RowType;
+import org.apache.iceberg.flink.data.RowDataUtil;
+
+class RowDataRecordFactory implements RecordFactory<RowData> {
+  private final RowType rowType;
+  private final TypeSerializer[] fieldSerializers;
+
+  RowDataRecordFactory(final RowType rowType) {
+    this.rowType = rowType;
+    this.fieldSerializers = createFieldSerializers(rowType);
+  }
+
+  static TypeSerializer[] createFieldSerializers(RowType rowType) {
+    return rowType.getChildren().stream()
+        .map(InternalSerializers::create)
+        .toArray(TypeSerializer[]::new);
+  }
+
+  @Override
+  public RowData[] createBatch(int batchSize) {
+    RowData[] arr = new RowData[batchSize];
+    for (int i = 0; i < batchSize; ++i) {
+      arr[i] = new GenericRowData(rowType.getFieldCount());

Review comment:
       Can the use of `rowType.getFieldCount()` be removed from the loop? Seems like it only needs to be called once.




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

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



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


[GitHub] [iceberg] kbendick commented on a change in pull request #3866: Flink: RecordFactory interface that can create record batch and clone…

Posted by GitBox <gi...@apache.org>.
kbendick commented on a change in pull request #3866:
URL: https://github.com/apache/iceberg/pull/3866#discussion_r796210307



##########
File path: flink/v1.14/flink/src/main/java/org/apache/iceberg/flink/source/reader/RowDataRecordFactory.java
##########
@@ -0,0 +1,57 @@
+/*
+ * 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.reader;
+
+import org.apache.flink.api.common.typeutils.TypeSerializer;
+import org.apache.flink.table.data.GenericRowData;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.runtime.typeutils.InternalSerializers;
+import org.apache.flink.table.types.logical.RowType;
+import org.apache.iceberg.flink.data.RowDataUtil;
+
+class RowDataRecordFactory implements RecordFactory<RowData> {
+  private final RowType rowType;
+  private final TypeSerializer[] fieldSerializers;
+
+  RowDataRecordFactory(final RowType rowType) {
+    this.rowType = rowType;
+    this.fieldSerializers = createFieldSerializers(rowType);
+  }
+
+  static TypeSerializer[] createFieldSerializers(RowType rowType) {
+    return rowType.getChildren().stream()
+        .map(InternalSerializers::create)
+        .toArray(TypeSerializer[]::new);
+  }

Review comment:
       When is this called in the lifecycle of the job? 




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

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



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