You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by we...@apache.org on 2017/04/28 01:37:18 UTC

arrow git commit: ARROW-907: C++: Construct Table from schema and arrays

Repository: arrow
Updated Branches:
  refs/heads/master 14bec24c5 -> f13a9286c


ARROW-907: C++: Construct Table from schema and arrays

Author: Uwe L. Korn <uw...@xhochy.com>

Closes #610 from xhochy/ARROW-907 and squashes the following commits:

b8ee8dc [Uwe L. Korn] Fix signed comparison
25518b3 [Uwe L. Korn] ARROW-907: C++: Construct Table from schema and arrays


Project: http://git-wip-us.apache.org/repos/asf/arrow/repo
Commit: http://git-wip-us.apache.org/repos/asf/arrow/commit/f13a9286
Tree: http://git-wip-us.apache.org/repos/asf/arrow/tree/f13a9286
Diff: http://git-wip-us.apache.org/repos/asf/arrow/diff/f13a9286

Branch: refs/heads/master
Commit: f13a9286c1444391c04fc0d20909a672122d10c1
Parents: 14bec24
Author: Uwe L. Korn <uw...@xhochy.com>
Authored: Thu Apr 27 21:37:12 2017 -0400
Committer: Wes McKinney <we...@twosigma.com>
Committed: Thu Apr 27 21:37:12 2017 -0400

----------------------------------------------------------------------
 cpp/src/arrow/table-test.cc |  5 +++++
 cpp/src/arrow/table.cc      | 21 +++++++++++++++++++++
 cpp/src/arrow/table.h       |  3 +++
 3 files changed, 29 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/arrow/blob/f13a9286/cpp/src/arrow/table-test.cc
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/table-test.cc b/cpp/src/arrow/table-test.cc
index 0da4c0f..e46fdc7 100644
--- a/cpp/src/arrow/table-test.cc
+++ b/cpp/src/arrow/table-test.cc
@@ -233,6 +233,11 @@ TEST_F(TestTable, Ctors) {
   table_.reset(new Table(schema_, columns_, length));
   ASSERT_OK(table_->ValidateColumns());
   ASSERT_EQ(length, table_->num_rows());
+
+  ASSERT_OK(MakeTable(schema_, arrays_, &table_));
+  ASSERT_OK(table_->ValidateColumns());
+  ASSERT_EQ(length, table_->num_rows());
+  ASSERT_EQ(3, table_->num_columns());
 }
 
 TEST_F(TestTable, Metadata) {

http://git-wip-us.apache.org/repos/asf/arrow/blob/f13a9286/cpp/src/arrow/table.cc
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/table.cc b/cpp/src/arrow/table.cc
index db17da7..c110ec1 100644
--- a/cpp/src/arrow/table.cc
+++ b/cpp/src/arrow/table.cc
@@ -366,4 +366,25 @@ Status Table::ValidateColumns() const {
   return Status::OK();
 }
 
+Status ARROW_EXPORT MakeTable(const std::shared_ptr<Schema>& schema,
+    const std::vector<std::shared_ptr<Array>>& arrays, std::shared_ptr<Table>* table) {
+  // Make sure the length of the schema corresponds to the length of the vector
+  if (schema->num_fields() != static_cast<int>(arrays.size())) {
+    std::stringstream ss;
+    ss << "Schema and Array vector have different lengths: " << schema->num_fields()
+       << " != " << arrays.size();
+    return Status::Invalid(ss.str());
+  }
+
+  std::vector<std::shared_ptr<Column>> columns;
+  columns.reserve(schema->num_fields());
+  for (int i = 0; i < schema->num_fields(); i++) {
+    columns.emplace_back(std::make_shared<Column>(schema->field(i), arrays[i]));
+  }
+
+  *table = std::make_shared<Table>(schema, columns);
+
+  return Status::OK();
+}
+
 }  // namespace arrow

http://git-wip-us.apache.org/repos/asf/arrow/blob/f13a9286/cpp/src/arrow/table.h
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/table.h b/cpp/src/arrow/table.h
index efc2077..67710a8 100644
--- a/cpp/src/arrow/table.h
+++ b/cpp/src/arrow/table.h
@@ -208,6 +208,9 @@ class ARROW_EXPORT Table {
 Status ARROW_EXPORT ConcatenateTables(
     const std::vector<std::shared_ptr<Table>>& tables, std::shared_ptr<Table>* table);
 
+Status ARROW_EXPORT MakeTable(const std::shared_ptr<Schema>& schema,
+    const std::vector<std::shared_ptr<Array>>& arrays, std::shared_ptr<Table>* table);
+
 }  // namespace arrow
 
 #endif  // ARROW_TABLE_H