zstan commented on code in PR #13225:
URL: https://github.com/apache/ignite/pull/13225#discussion_r3852408427


##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/TableFunctionScan.java:
##########
@@ -36,34 +37,57 @@ public class TableFunctionScan<Row> implements 
Iterable<Row> {
     /** */
     private final RowFactory<Row> rowFactory;
 
+    /** */
+    Function<Object, Object> binaryMarshaller;
+
+    /** */
+    private static final String ERR_SIZE_TEMPLATE = "Unable to process table 
function data: row length [%d]" +
+        " doesn't match defined columns number [%d].";
+
     /** */
     public TableFunctionScan(
         RelDataType rowType,
         Supplier<Iterable<?>> dataSupplier,
-        RowFactory<Row> rowFactory
+        RowFactory<Row> rowFactory,
+        Function<Object, Object> marshaller
     ) {
         this.rowType = rowType;
         this.dataSupplier = dataSupplier;
         this.rowFactory = rowFactory;
+        binaryMarshaller = marshaller;
     }
 
     /** {@inheritDoc} */
     @Override public Iterator<Row> iterator() {
         return F.iterator(dataSupplier.get(), this::convertToRow, true);
     }
 
+    /** */
+    private static void rowSizeChecker(int rowSize, int fldCount) {
+        if (rowSize != fldCount)
+            throw new IgniteSQLException(ERR_SIZE_TEMPLATE.formatted(rowSize, 
fldCount));
+    }
+
     /** */
     private Row convertToRow(Object rowContainer) {
         if (rowContainer.getClass() != Object[].class && 
!Collection.class.isAssignableFrom(rowContainer.getClass()))
             throw new IgniteSQLException("Unable to process table function 
data: row type is neither Collection or Object[].");
 
-        Object[] rowArr = rowContainer.getClass() == Object[].class
-            ? (Object[])rowContainer
-            : ((Collection<?>)rowContainer).toArray();
+        if (rowContainer instanceof Object[])
+            rowSizeChecker(((Object[])rowContainer).length, 
rowType.getFieldCount());
+        else
+            rowSizeChecker(((Collection<?>)rowContainer).size(), 
rowType.getFieldCount());
 
-        if (rowArr.length != rowType.getFieldCount()) {
-            throw new IgniteSQLException("Unable to process table function 
data: row length [" + rowArr.length
-                + "] doesn't match defined columns number [" + 
rowType.getFieldCount() + "].");
+        Object[] rowArr;
+
+        if (rowContainer.getClass().isArray()) {
+            rowArr = (Object[])rowContainer;
+            for (int pos = 0; pos < rowArr.length; ++pos)
+                rowArr[pos] = binaryMarshaller.apply(rowArr[pos]);
+        }
+        else {
+            Collection<?> coll = (Collection<?>)rowContainer;
+            rowArr = coll.stream().map(e -> 
binaryMarshaller.apply(e)).toArray();

Review Comment:
   done



-- 
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]

Reply via email to