sgilmore10 commented on code in PR #37176:
URL: https://github.com/apache/arrow/pull/37176#discussion_r1294892729


##########
matlab/test/arrow/tabular/tRecordBatch.m:
##########
@@ -135,5 +117,110 @@ function ErrorIfIndexIsNonPositive(tc)
             fcn = @() arrowRecordBatch.column(-1);
             tc.verifyError(fcn, "arrow:badsubscript:NonPositive");
         end
+
+        function FromArraysColumnNamesNotProvided(tc)
+        % Verify arrow.tabular.RecordBatch.fromArrays creates the expected
+        % RecordBatch when given a comma-separated list of
+        % arrow.array.Array values.
+            import arrow.tabular.RecordBatch
+
+            TOriginal = createTableWithAllSupportedTypes();
+
+            arrowArrays = cell([1 width(TOriginal)]);
+            for ii = 1:width(TOriginal)
+                arrowArrays{ii} = arrow.array(TOriginal.(ii));
+            end
+
+            arrowRecordBatch = RecordBatch.fromArrays(arrowArrays{:});
+            expectedColumnNames = compose("Column%d", 1:13);
+            TOriginal.Properties.VariableNames = expectedColumnNames;
+            tc.verifyRecordBatch(arrowRecordBatch, expectedColumnNames, 
TOriginal);
+        end
+
+        function FromArraysWithColumnNamesProvided(tc)
+        % Verify arrow.tabular.RecordBatch.fromArrays creates the expected
+        % RecordBatch when given a comma-separated list of
+        % arrow.array.Array values and the ColumnNames nv-pair is provided.
+            import arrow.tabular.RecordBatch
+
+            TOriginal = createTableWithAllSupportedTypes();
+
+            arrowArrays = cell([1 width(TOriginal)]);
+            for ii = 1:width(TOriginal)
+                arrowArrays{ii} = arrow.array(TOriginal.(ii));
+            end
+
+            columnNames = string(char(65:77)')';
+            arrowRecordBatch = RecordBatch.fromArrays(arrowArrays{:}, 
ColumnNames=columnNames);
+            TOriginal.Properties.VariableNames = columnNames;
+            tc.verifyRecordBatch(arrowRecordBatch, columnNames, TOriginal);
+        end
+
+        function FromArraysUnequalArrayLengthsError(tc)
+        % Verify arrow.tabular.RecordBatch.fromArrays throws an error whose
+        % identifier is "arrow:tabular:UnequalArrayLengths" if the arrays
+        % provided don't all have the same length.
+            import arrow.tabular.RecordBatch
+
+            A1 = arrow.array([1, 2]);
+            A2 = arrow.array(["A", "B", "C"]);
+            fcn = @() RecordBatch.fromArrays(A1, A2);
+            tc.verifyError(fcn, "arrow:tabular:UnequalArrayLengths");
+        end
+
+        function FromArraysWrongNumberColumnNamesError(tc)
+        % Verify arrow.tabular.RecordBatch.fromArrays throws an error whose
+        % identifier is "arrow:tabular:WrongNumberColumnNames" if the 
+        % ColumnNames provided doesn't have one element per array.
+            import arrow.tabular.RecordBatch
+
+            A1 = arrow.array([1, 2]);
+            A2 = arrow.array(["A", "B"]);
+            fcn = @() RecordBatch.fromArrays(A1, A2, columnNames=["A", "B", 
"C"]);
+            tc.verifyError(fcn, "arrow:tabular:WrongNumberColumnNames");
+        end
+
+        function FromArraysColumnNamesHasMissingString(tc)
+        % Verify arrow.tabular.RecordBatch.fromArrays throws an error whose
+        % identifier is "MATLAB:validators:mustBeNonmissing" if the 
+        % ColumnNames provided has a missing string value.
+            import arrow.tabular.RecordBatch
+
+            A1 = arrow.array([1, 2]);
+            A2 = arrow.array(["A", "B"]);
+            fcn = @() RecordBatch.fromArrays(A1, A2, columnNames=["A", 
missing]);
+            tc.verifyError(fcn, "MATLAB:validators:mustBeNonmissing");
+        end
     end
+
+    methods
+        function verifyRecordBatch(tc, recordBatch, expectedColumnNames, 
expectedTable)
+            tc.verifyEqual(recordBatch.NumColumns, 
int32(width(expectedTable)));
+            tc.verifyEqual(recordBatch.ColumnNames, expectedColumnNames);
+            convertedTable = recordBatch.table();
+            tc.verifyEqual(convertedTable, expectedTable);
+             for ii = 1:recordBatch.NumColumns
+                column = recordBatch.column(ii);
+                tc.verifyEqual(column.toMATLAB(), expectedTable{:, ii});
+                traits = 
arrow.type.traits.traits(string(class(expectedTable{:, ii})));
+                tc.verifyInstanceOf(column, traits.ArrayClassName);
+             end
+        end
+    end
+end
+
+function T = createTableWithAllSupportedTypes()

Review Comment:
   Sounds good. Here's the issue #37179.



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