You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "sgilmore10 (via GitHub)" <gi...@apache.org> on 2023/10/25 17:29:29 UTC

[PR] GH-38418: [MATLAB] Add method for extracting one row of an `arrow.tabular.Table` as a string [arrow]

sgilmore10 opened a new pull request, #38463:
URL: https://github.com/apache/arrow/pull/38463

   <!--
   Thanks for opening a pull request!
   If this is your first pull request you can find detailed information on how 
   to contribute here:
     * [New Contributor's Guide](https://arrow.apache.org/docs/dev/developers/guide/step_by_step/pr_lifecycle.html#reviews-and-merge-of-the-pull-request)
     * [Contributing Overview](https://arrow.apache.org/docs/dev/developers/overview.html)
   
   
   If this is not a [minor PR](https://github.com/apache/arrow/blob/main/CONTRIBUTING.md#Minor-Fixes). Could you open an issue for this pull request on GitHub? https://github.com/apache/arrow/issues/new/choose
   
   Opening GitHub issues ahead of time contributes to the [Openness](http://theapacheway.com/open/#:~:text=Openness%20allows%20new%20users%20the,must%20happen%20in%20the%20open.) of the Apache Arrow project.
   
   Then could you also rename the pull request title in the following format?
   
       GH-${GITHUB_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}
   
   or
   
       MINOR: [${COMPONENT}] ${SUMMARY}
   
   In the case of PARQUET issues on JIRA the title also supports:
   
       PARQUET-${JIRA_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}
   
   -->
   
   ### Rationale for this change
   
   We would like to modify the display of the `arrow.tabular.Table` and `arrow.tabular.RecordBatch` classes to be more "MATLAB-like". In order to do this, we need to add a method to their respective C++ Proxy classes that  returns a single row of the Table/RecordBatch as a MATLAB `string` array.
   
   ### What changes are included in this PR?
   
   Added  new function template:
   ```cpp 
   template <typename TabularLike>
   arrow::matlab::tabular::print_row(const std::shared_ptr<TabularLike>& tabularObject, const int64_t row_index) 
   ```
   This function template returns a string representation of the specified row in `tabbularObject`. 
   
   Added a new proxy method called `getRowString` to both the `Table` and `RecordBatch` C++ proxy classes. These methods invoke `print_row` to return a string representation of one row in the `Table`/`RecordBatch`.  Neither MATLAB class `arrow.tabular.Table` nor `arrow.tabular.RecordBatch` expose these methods directly because they will only be used internally for display. 
   
   Below is an example Output of `getRowString()`:
   
   ```matlab
   >> matlabTable = table([1; 2; 3], ["ABC"; "DE"; "FGH"], datetime(2023, 10, 25) + days(0:2)');
   >> arrowTable = arrow.table(matlabTable);
   >> rowOneAsString = arrowTable.Proxy.getRowString(struct(Index=int64(1)))
   
   rowOneAsString = 
   
       "1 | "ABC" | 2023-10-25 00:00:00.000000"
   ```
   
   
   ### Are these changes tested?
   
   Yes, added a new test class called `tTabularInternal.m`. Because `getRowString()` is not a method on the MATLAB classes `arrow.tabular.Table` and `arrow.tabular.RecordBatch`, this test class calls `getRowString()` on their `Proxy` properties, which are public but hidden.
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   6. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
   -->
   
   ### Are there any user-facing changes?
   
   No.
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please uncomment the line below and explain which changes are breaking.
   -->
   <!-- **This PR includes breaking changes to public APIs.** -->
   
   <!--
   Please uncomment the line below (and provide explanation) if the changes fix either (a) a security vulnerability, (b) a bug that caused incorrect or invalid data to be produced, or (c) a bug that causes a crash (even when the API contract is upheld). We use this to highlight fixes to issues that may affect users without their knowledge. For this reason, fixing bugs that cause errors don't count, since those are usually obvious.
   -->
   <!-- **This PR contains a "Critical Fix".** -->


-- 
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: github-unsubscribe@arrow.apache.org

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


Re: [PR] GH-38418: [MATLAB] Add method for extracting one row of an `arrow.tabular.Table` as a string [arrow]

Posted by "kevingurney (via GitHub)" <gi...@apache.org>.
kevingurney merged PR #38463:
URL: https://github.com/apache/arrow/pull/38463


-- 
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: github-unsubscribe@arrow.apache.org

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


Re: [PR] GH-38418: [MATLAB] Add method for extracting one row of an `arrow.tabular.Table` as a string [arrow]

Posted by "conbench-apache-arrow[bot] (via GitHub)" <gi...@apache.org>.
conbench-apache-arrow[bot] commented on PR #38463:
URL: https://github.com/apache/arrow/pull/38463#issuecomment-1783319428

   After merging your PR, Conbench analyzed the 4 benchmarking runs that have been run so far on merge-commit 818f71d085b6f820903afc6b1f1e577d8e45ff47.
   
   There were no benchmark performance regressions. 🎉
   
   The [full Conbench report](https://github.com/apache/arrow/runs/18131339105) has more details.


-- 
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: github-unsubscribe@arrow.apache.org

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


Re: [PR] GH-38418: [MATLAB] Add method for extracting one row of an `arrow.tabular.Table` as a string [arrow]

Posted by "kevingurney (via GitHub)" <gi...@apache.org>.
kevingurney commented on code in PR #38463:
URL: https://github.com/apache/arrow/pull/38463#discussion_r1372244335


##########
matlab/src/cpp/arrow/matlab/tabular/print_row.h:
##########
@@ -0,0 +1,73 @@
+// 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.
+
+#pragma once
+
+#include "arrow/pretty_print.h"
+
+#include <sstream>
+
+namespace arrow::matlab::tabular {
+
+    namespace {
+        arrow::PrettyPrintOptions make_pretty_print_options() {
+            auto opts = arrow::PrettyPrintOptions::Defaults();
+            opts.skip_new_lines = true;
+            opts.array_delimiters.open = "";
+            opts.array_delimiters.close = "";
+            opts.chunked_array_delimiters.open = "";
+            opts.chunked_array_delimiters.close = "";
+            return opts;
+        }
+    }
+
+    template <typename TabularType>
+    arrow::Result<std::string> print_row(const std::shared_ptr<TabularType>& tabular_object, const int64_t matlab_row_index) {
+        std::stringstream ss;
+        const int64_t row_index = matlab_row_index - 1;
+        if (row_index >= tabular_object->num_rows() || row_index < 0) {
+            ss << "Invalid Row Index: " << matlab_row_index;
+            return arrow::Status::Invalid(ss.str());
+        }
+
+        const auto opts = make_pretty_print_options();
+        const auto num_columns = tabular_object->num_columns();
+        const auto& columns = tabular_object->columns();
+
+        for (int32_t i = 0; i < num_columns; ++i) {
+            const auto& column = columns[i];
+            const auto type_id = column->type()->id();
+            if (arrow::is_primitive(type_id) || arrow::is_string(type_id)) {
+                auto slice = column->Slice(row_index, 1);
+                ARROW_RETURN_NOT_OK(arrow::PrettyPrint(*slice, opts, &ss));
+            } else if (type_id == arrow::Type::type::STRUCT) {
+                ss << "<Struct>";

Review Comment:
   Could you add a comment here exlpaining that these are "placeholders", since we don't have a straightforward of representing List/Struct for a horizontal display?



##########
matlab/src/cpp/arrow/matlab/tabular/print_row.h:
##########
@@ -0,0 +1,73 @@
+// 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.
+
+#pragma once
+
+#include "arrow/pretty_print.h"
+
+#include <sstream>
+
+namespace arrow::matlab::tabular {
+
+    namespace {
+        arrow::PrettyPrintOptions make_pretty_print_options() {
+            auto opts = arrow::PrettyPrintOptions::Defaults();
+            opts.skip_new_lines = true;
+            opts.array_delimiters.open = "";
+            opts.array_delimiters.close = "";
+            opts.chunked_array_delimiters.open = "";
+            opts.chunked_array_delimiters.close = "";
+            return opts;
+        }
+    }
+
+    template <typename TabularType>
+    arrow::Result<std::string> print_row(const std::shared_ptr<TabularType>& tabular_object, const int64_t matlab_row_index) {

Review Comment:
   Just my personal opinion. When I think of "Printing", I usually think of printing to screen. Maybe we could call this `get_row_as_string` or `row_as_string` instead? I don't think it's too important which name we go with, but just wanted to suggest some alternate names.



##########
matlab/test/arrow/tabular/tTabularInternal.m:
##########
@@ -0,0 +1,110 @@
+%TTABULARINTERNAL Unit tests for internal functionality of tabular types.
+
+% 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.
+
+classdef tTabularInternal < matlab.unittest.TestCase
+
+    properties(TestParameter)
+        TabularObjectWithAllTypes
+
+        TabularObjectWithOneColumn
+
+        TabularObjectWithThreeRows
+    end
+
+    methods (TestParameterDefinition, Static)
+        function TabularObjectWithAllTypes = initializeTabularObjectWithAllTypes()
+            arrays = arrow.internal.test.tabular.createAllSupportedArrayTypes(NumRows=1);
+            arrowTable = arrow.tabular.Table.fromArrays(arrays{:});
+            arrowRecordBatch = arrow.tabular.Table.fromArrays(arrays{:});
+            TabularObjectWithAllTypes = struct(Table=arrowTable, ...
+                RecordBatch=arrowRecordBatch);
+        end
+
+        function TabularObjectWithOneColumn = initializeTabularObjectWithOneColumn()
+            t = table((1:3)');
+            arrowTable = arrow.table(t);
+            arrowRecordBatch = arrow.recordBatch(t);
+            TabularObjectWithOneColumn = struct(Table=arrowTable, ...
+                RecordBatch=arrowRecordBatch);
+        end
+
+        function TabularObjectWithThreeRows = initializeTabularObjectWithThreeRows()
+            t = table((1:3)', ["A"; "B"; "C"]);
+            arrowTable = arrow.table(t);
+            arrowRecordBatch = arrow.recordBatch(t);
+            TabularObjectWithThreeRows = struct(Table=arrowTable, ...
+                RecordBatch=arrowRecordBatch);
+        end
+    end
+
+    methods (Test)
+        function RowWithAllTypes(testCase, TabularObjectWithAllTypes)
+            % Verify getRowString successfully returns the expected string
+            % when called on a Table/RecordBatch that contains all
+            % supported array types.
+            proxy = TabularObjectWithAllTypes.Proxy;
+            columnStrs = ["false", "2024-02-23", "2023-08-24", "78", "38", ...
+                          "24", "48", "89", "102", "<List>", """107""", "<Struct>", ...
+                          "00:03:44", "00:00:07.000000", "2024-02-10 00:00:00.000000", ...
+                          "107", "143", "36", "51"];
+            expectedString = strjoin(columnStrs, " | ");
+            actualString = proxy.getRowString(struct(Index=int64(1)));
+            testCase.verifyEqual(actualString, expectedString);
+        end
+
+        function RowWithOneColumn(testCase, TabularObjectWithOneColumn)
+            % Verify getRowString successfully returns the expected string
+            % when called on a Table/RecordBatch with one column.
+            proxy = TabularObjectWithOneColumn.Proxy;
+            expectedString = "1";
+            actualString = proxy.getRowString(struct(Index=int64(1)));
+            testCase.verifyEqual(actualString, expectedString);
+        end
+
+        function RowIndex(testCase, TabularObjectWithThreeRows)
+            % Verify getRowString returns the expected string when provided

Review Comment:
   I think there is a typo in this comment.



##########
matlab/src/cpp/arrow/matlab/tabular/print_row.h:
##########
@@ -0,0 +1,73 @@
+// 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.
+
+#pragma once
+
+#include "arrow/pretty_print.h"
+
+#include <sstream>
+
+namespace arrow::matlab::tabular {
+
+    namespace {
+        arrow::PrettyPrintOptions make_pretty_print_options() {
+            auto opts = arrow::PrettyPrintOptions::Defaults();
+            opts.skip_new_lines = true;
+            opts.array_delimiters.open = "";
+            opts.array_delimiters.close = "";
+            opts.chunked_array_delimiters.open = "";
+            opts.chunked_array_delimiters.close = "";
+            return opts;
+        }
+    }
+
+    template <typename TabularType>
+    arrow::Result<std::string> print_row(const std::shared_ptr<TabularType>& tabular_object, const int64_t matlab_row_index) {
+        std::stringstream ss;
+        const int64_t row_index = matlab_row_index - 1;
+        if (row_index >= tabular_object->num_rows() || row_index < 0) {
+            ss << "Invalid Row Index: " << matlab_row_index;
+            return arrow::Status::Invalid(ss.str());
+        }
+
+        const auto opts = make_pretty_print_options();
+        const auto num_columns = tabular_object->num_columns();
+        const auto& columns = tabular_object->columns();
+
+        for (int32_t i = 0; i < num_columns; ++i) {
+            const auto& column = columns[i];
+            const auto type_id = column->type()->id();
+            if (arrow::is_primitive(type_id) || arrow::is_string(type_id)) {
+                auto slice = column->Slice(row_index, 1);
+                ARROW_RETURN_NOT_OK(arrow::PrettyPrint(*slice, opts, &ss));
+            } else if (type_id == arrow::Type::type::STRUCT) {
+                ss << "<Struct>";
+            } else if (type_id == arrow::Type::type::LIST) {
+                ss << "<List>";
+            } else {
+                return arrow::Status::NotImplemented("Invalid Datatype: " + column->type()->ToString());

Review Comment:
   ```suggestion
                   return arrow::Status::NotImplemented("Datatype " + column->type()->ToString() + "is not currently supported for display.");
   ```



##########
matlab/src/cpp/arrow/matlab/tabular/proxy/record_batch.cc:
##########
@@ -58,6 +59,7 @@ namespace arrow::matlab::tabular::proxy {
         REGISTER_METHOD(RecordBatch, getColumnByIndex);
         REGISTER_METHOD(RecordBatch, getColumnByName);
         REGISTER_METHOD(RecordBatch, getSchema);
+        REGISTER_METHOD(RecordBatch, getRowString);

Review Comment:
   ```suggestion
           REGISTER_METHOD(RecordBatch, getRowAsString);
   ```



-- 
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: github-unsubscribe@arrow.apache.org

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


Re: [PR] GH-38418: [MATLAB] Add method for extracting one row of an `arrow.tabular.Table` as a string [arrow]

Posted by "kevingurney (via GitHub)" <gi...@apache.org>.
kevingurney commented on code in PR #38463:
URL: https://github.com/apache/arrow/pull/38463#discussion_r1373563754


##########
matlab/src/cpp/arrow/matlab/error/error.h:
##########
@@ -202,4 +202,5 @@ namespace arrow::matlab::error {
     static const char* INDEX_OUT_OF_RANGE = "arrow:index:OutOfRange";
     static const char* BUFFER_VIEW_OR_COPY_FAILED = "arrow:buffer:ViewOrCopyFailed";
     static const char* ARRAY_PRETTY_PRINT_FAILED = "arrow:array:PrettyPrintFailed";
+    static const char* TABULAR_PRINT_ROW_FAILED = "arrow:tabular:PrintRowFailed";

Review Comment:
   ```suggestion
   static const char* TABULAR_GET_STRING_AS_ROW_FAILED = "arrow:tabular:GetStringAsRowFailed";
   ```



##########
matlab/test/arrow/tabular/tTabularInternal.m:
##########
@@ -62,46 +62,46 @@ function RowWithAllTypes(testCase, TabularObjectWithAllTypes)
                           "00:03:44", "00:00:07.000000", "2024-02-10 00:00:00.000000", ...
                           "107", "143", "36", "51"];
             expectedString = strjoin(columnStrs, " | ");
-            actualString = proxy.getRowString(struct(Index=int64(1)));
+            actualString = proxy.getRowAsString(struct(Index=int64(1)));
             testCase.verifyEqual(actualString, expectedString);
         end
 
         function RowWithOneColumn(testCase, TabularObjectWithOneColumn)
-            % Verify getRowString successfully returns the expected string
+            % Verify getRowAsString successfully returns the expected string
             % when called on a Table/RecordBatch with one column.
             proxy = TabularObjectWithOneColumn.Proxy;
             expectedString = "1";
-            actualString = proxy.getRowString(struct(Index=int64(1)));
+            actualString = proxy.getRowAsString(struct(Index=int64(1)));
             testCase.verifyEqual(actualString, expectedString);
         end
 
         function RowIndex(testCase, TabularObjectWithThreeRows)
-            % Verify getRowString returns the expected string when provided
-            % for each row index value supplied.
+            % Verify getRowAsString returns the expected string for 
+            % the provided row index.
             proxy = TabularObjectWithThreeRows.Proxy;
 
-            actualString = proxy.getRowString(struct(Index=int64(1)));
+            actualString = proxy.getRowAsString(struct(Index=int64(1)));
             expectedString = "1 | ""A""";
             testCase.verifyEqual(actualString, expectedString);
 
-            actualString = proxy.getRowString(struct(Index=int64(2)));
+            actualString = proxy.getRowAsString(struct(Index=int64(2)));
             expectedString = "2 | ""B""";
             testCase.verifyEqual(actualString, expectedString);
 
-            actualString = proxy.getRowString(struct(Index=int64(3)));
+            actualString = proxy.getRowAsString(struct(Index=int64(3)));
             expectedString = "3 | ""C""";
             testCase.verifyEqual(actualString, expectedString);
         end
 
         function PrintRowFailed(testCase, TabularObjectWithThreeRows)

Review Comment:
   Can you rename this to `GetStringAsRowFailed`?



-- 
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: github-unsubscribe@arrow.apache.org

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


Re: [PR] GH-38418: [MATLAB] Add method for extracting one row of an `arrow.tabular.Table` as a string [arrow]

Posted by "sgilmore10 (via GitHub)" <gi...@apache.org>.
sgilmore10 commented on code in PR #38463:
URL: https://github.com/apache/arrow/pull/38463#discussion_r1372289510


##########
matlab/src/cpp/arrow/matlab/tabular/print_row.h:
##########
@@ -0,0 +1,73 @@
+// 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.
+
+#pragma once
+
+#include "arrow/pretty_print.h"
+
+#include <sstream>
+
+namespace arrow::matlab::tabular {
+
+    namespace {
+        arrow::PrettyPrintOptions make_pretty_print_options() {
+            auto opts = arrow::PrettyPrintOptions::Defaults();
+            opts.skip_new_lines = true;
+            opts.array_delimiters.open = "";
+            opts.array_delimiters.close = "";
+            opts.chunked_array_delimiters.open = "";
+            opts.chunked_array_delimiters.close = "";
+            return opts;
+        }
+    }
+
+    template <typename TabularType>
+    arrow::Result<std::string> print_row(const std::shared_ptr<TabularType>& tabular_object, const int64_t matlab_row_index) {

Review Comment:
   I agree. I didn't love `print_row` as the function name myself. I'll rename it to `get_row_as_string`



-- 
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: github-unsubscribe@arrow.apache.org

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


Re: [PR] GH-38418: [MATLAB] Add method for extracting one row of an `arrow.tabular.Table` as a string [arrow]

Posted by "sgilmore10 (via GitHub)" <gi...@apache.org>.
sgilmore10 commented on code in PR #38463:
URL: https://github.com/apache/arrow/pull/38463#discussion_r1372289775


##########
matlab/src/cpp/arrow/matlab/tabular/print_row.h:
##########
@@ -0,0 +1,73 @@
+// 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.
+
+#pragma once
+
+#include "arrow/pretty_print.h"
+
+#include <sstream>
+
+namespace arrow::matlab::tabular {
+
+    namespace {
+        arrow::PrettyPrintOptions make_pretty_print_options() {
+            auto opts = arrow::PrettyPrintOptions::Defaults();
+            opts.skip_new_lines = true;
+            opts.array_delimiters.open = "";
+            opts.array_delimiters.close = "";
+            opts.chunked_array_delimiters.open = "";
+            opts.chunked_array_delimiters.close = "";
+            return opts;
+        }
+    }
+
+    template <typename TabularType>
+    arrow::Result<std::string> print_row(const std::shared_ptr<TabularType>& tabular_object, const int64_t matlab_row_index) {
+        std::stringstream ss;
+        const int64_t row_index = matlab_row_index - 1;
+        if (row_index >= tabular_object->num_rows() || row_index < 0) {
+            ss << "Invalid Row Index: " << matlab_row_index;
+            return arrow::Status::Invalid(ss.str());
+        }
+
+        const auto opts = make_pretty_print_options();
+        const auto num_columns = tabular_object->num_columns();
+        const auto& columns = tabular_object->columns();
+
+        for (int32_t i = 0; i < num_columns; ++i) {
+            const auto& column = columns[i];
+            const auto type_id = column->type()->id();
+            if (arrow::is_primitive(type_id) || arrow::is_string(type_id)) {
+                auto slice = column->Slice(row_index, 1);
+                ARROW_RETURN_NOT_OK(arrow::PrettyPrint(*slice, opts, &ss));
+            } else if (type_id == arrow::Type::type::STRUCT) {
+                ss << "<Struct>";

Review Comment:
   Will do!



-- 
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: github-unsubscribe@arrow.apache.org

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


Re: [PR] GH-38418: [MATLAB] Add method for extracting one row of an `arrow.tabular.Table` as a string [arrow]

Posted by "kevingurney (via GitHub)" <gi...@apache.org>.
kevingurney commented on PR #38463:
URL: https://github.com/apache/arrow/pull/38463#issuecomment-1781809173

   +1


-- 
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: github-unsubscribe@arrow.apache.org

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