arrow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From w...@apache.org
Subject arrow git commit: ARROW-1336: [C++] Add arrow::schema factory function, simply some awkward constructors
Date Tue, 08 Aug 2017 02:06:32 GMT
Repository: arrow
Updated Branches:
  refs/heads/master 2015198f1 -> 02ab74841


ARROW-1336: [C++] Add arrow::schema factory function, simply some awkward constructors

Author: Wes McKinney <wes.mckinney@twosigma.com>

Closes #948 from wesm/ARROW-1336 and squashes the following commits:

a901b375 [Wes McKinney] Add arrow::schema factory function, simply awkward constructors with
initializer list


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

Branch: refs/heads/master
Commit: 02ab74841d1a2f3f15aeab20fc4acbc5d737047d
Parents: 2015198
Author: Wes McKinney <wes.mckinney@twosigma.com>
Authored: Mon Aug 7 22:06:28 2017 -0400
Committer: Wes McKinney <wes.mckinney@twosigma.com>
Committed: Mon Aug 7 22:06:28 2017 -0400

----------------------------------------------------------------------
 cpp/src/arrow/ipc/feather-test.cc        |  2 +-
 cpp/src/arrow/ipc/ipc-json-test.cc       |  4 +--
 cpp/src/arrow/ipc/ipc-read-write-test.cc |  4 +--
 cpp/src/arrow/ipc/json-internal.cc       |  3 +--
 cpp/src/arrow/ipc/metadata.cc            |  2 +-
 cpp/src/arrow/ipc/test-common.h          | 36 +++++++++++++--------------
 cpp/src/arrow/python/builtin_convert.cc  |  4 +--
 cpp/src/arrow/table-test.cc              | 27 ++++++++++----------
 cpp/src/arrow/type-test.cc               | 25 ++++++++-----------
 cpp/src/arrow/type.cc                    | 14 +++++++++++
 cpp/src/arrow/type.h                     | 33 ++++++++++++++++++++++++
 11 files changed, 97 insertions(+), 57 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/arrow/blob/02ab7484/cpp/src/arrow/ipc/feather-test.cc
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/ipc/feather-test.cc b/cpp/src/arrow/ipc/feather-test.cc
index b76b518..e74a60d 100644
--- a/cpp/src/arrow/ipc/feather-test.cc
+++ b/cpp/src/arrow/ipc/feather-test.cc
@@ -354,7 +354,7 @@ TEST_F(TestTableWriter, TimeTypes) {
   auto f1 = field("f1", time32(TimeUnit::MILLI));
   auto f2 = field("f2", timestamp(TimeUnit::NANO));
   auto f3 = field("f3", timestamp(TimeUnit::SECOND, "US/Los_Angeles"));
-  std::shared_ptr<Schema> schema(new Schema({f0, f1, f2, f3}));
+  auto schema = ::arrow::schema({f0, f1, f2, f3});
 
   std::vector<int64_t> values_vec = {0, 1, 2, 3, 4, 5, 6};
   std::shared_ptr<Array> values;

http://git-wip-us.apache.org/repos/asf/arrow/blob/02ab7484/cpp/src/arrow/ipc/ipc-json-test.cc
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/ipc/ipc-json-test.cc b/cpp/src/arrow/ipc/ipc-json-test.cc
index 1d5a699..ddb2e37 100644
--- a/cpp/src/arrow/ipc/ipc-json-test.cc
+++ b/cpp/src/arrow/ipc/ipc-json-test.cc
@@ -247,8 +247,8 @@ TEST(TestJsonFileReadWrite, BasicRoundTrip) {
   auto v2_type = int32();
   auto v3_type = utf8();
 
-  std::shared_ptr<Schema> schema(
-      new Schema({field("f1", v1_type), field("f2", v2_type), field("f3", v3_type)}));
+  auto schema =
+      ::arrow::schema({field("f1", v1_type), field("f2", v2_type), field("f3", v3_type)});
 
   std::unique_ptr<JsonWriter> writer;
   ASSERT_OK(JsonWriter::Open(schema, &writer));

http://git-wip-us.apache.org/repos/asf/arrow/blob/02ab7484/cpp/src/arrow/ipc/ipc-read-write-test.cc
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/ipc/ipc-read-write-test.cc b/cpp/src/arrow/ipc/ipc-read-write-test.cc
index a6246c9..0452961 100644
--- a/cpp/src/arrow/ipc/ipc-read-write-test.cc
+++ b/cpp/src/arrow/ipc/ipc-read-write-test.cc
@@ -303,7 +303,7 @@ TEST_P(TestIpcRoundTrip, ZeroLengthArrays) {
 TEST_F(TestWriteRecordBatch, SliceTruncatesBuffers) {
   auto CheckArray = [this](const std::shared_ptr<Array>& array) {
     auto f0 = field("f0", array->type());
-    auto schema = std::shared_ptr<Schema>(new Schema({f0}));
+    auto schema = ::arrow::schema({f0});
     RecordBatch batch(schema, array->length(), {array});
     auto sliced_batch = batch.Slice(0, 5);
 
@@ -421,7 +421,7 @@ class RecursionLimits : public ::testing::Test, public io::MemoryMapFixture
{
 
     auto f0 = field("f0", type);
 
-    *schema = std::shared_ptr<Schema>(new Schema({f0}));
+    *schema = ::arrow::schema({f0});
 
     std::vector<std::shared_ptr<Array>> arrays = {array};
     *batch = std::make_shared<RecordBatch>(*schema, batch_length, arrays);

http://git-wip-us.apache.org/repos/asf/arrow/blob/02ab7484/cpp/src/arrow/ipc/json-internal.cc
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/ipc/json-internal.cc b/cpp/src/arrow/ipc/json-internal.cc
index 49fb6ac..bc2b0d1 100644
--- a/cpp/src/arrow/ipc/json-internal.cc
+++ b/cpp/src/arrow/ipc/json-internal.cc
@@ -129,8 +129,7 @@ class SchemaWriter {
     writer_->Key("data");
 
     // Make a dummy record batch. A bit tedious as we have to make a schema
-    auto schema = std::shared_ptr<Schema>(
-        new Schema({arrow::field("dictionary", dictionary->type())}));
+    auto schema = ::arrow::schema({arrow::field("dictionary", dictionary->type())});
     RecordBatch batch(schema, dictionary->length(), {dictionary});
     RETURN_NOT_OK(WriteRecordBatch(batch, writer_));
     writer_->EndObject();

http://git-wip-us.apache.org/repos/asf/arrow/blob/02ab7484/cpp/src/arrow/ipc/metadata.cc
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/ipc/metadata.cc b/cpp/src/arrow/ipc/metadata.cc
index d764e20..faf01a5 100644
--- a/cpp/src/arrow/ipc/metadata.cc
+++ b/cpp/src/arrow/ipc/metadata.cc
@@ -1035,7 +1035,7 @@ Status GetSchema(const void* opaque_schema, const DictionaryMemo&
dictionary_mem
     }
   }
 
-  *out = std::make_shared<Schema>(fields, metadata);
+  *out = ::arrow::schema(std::move(fields), metadata);
   return Status::OK();
 }
 

http://git-wip-us.apache.org/repos/asf/arrow/blob/02ab7484/cpp/src/arrow/ipc/test-common.h
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/ipc/test-common.h b/cpp/src/arrow/ipc/test-common.h
index ed33e6e..c1e79d4 100644
--- a/cpp/src/arrow/ipc/test-common.h
+++ b/cpp/src/arrow/ipc/test-common.h
@@ -179,7 +179,7 @@ Status MakeBooleanBatchSized(const int length, std::shared_ptr<RecordBatch>*
out
   // Make the schema
   auto f0 = field("f0", boolean());
   auto f1 = field("f1", boolean());
-  std::shared_ptr<Schema> schema(new Schema({f0, f1}));
+  auto schema = ::arrow::schema({f0, f1});
 
   std::shared_ptr<Array> a0, a1;
   RETURN_NOT_OK(MakeRandomBooleanArray(length, true, &a0));
@@ -196,7 +196,7 @@ Status MakeIntBatchSized(int length, std::shared_ptr<RecordBatch>*
out) {
   // Make the schema
   auto f0 = field("f0", int32());
   auto f1 = field("f1", int32());
-  std::shared_ptr<Schema> schema(new Schema({f0, f1}));
+  auto schema = ::arrow::schema({f0, f1});
 
   // Example data
   std::shared_ptr<Array> a0, a1;
@@ -237,7 +237,7 @@ Status MakeStringTypesRecordBatch(std::shared_ptr<RecordBatch>*
out) {
   auto binary_type = binary();
   auto f0 = field("f0", string_type);
   auto f1 = field("f1", binary_type);
-  std::shared_ptr<Schema> schema(new Schema({f0, f1}));
+  auto schema = ::arrow::schema({f0, f1});
 
   std::shared_ptr<Array> a0, a1;
   MemoryPool* pool = default_memory_pool();
@@ -259,7 +259,7 @@ Status MakeStringTypesRecordBatch(std::shared_ptr<RecordBatch>*
out) {
 Status MakeNullRecordBatch(std::shared_ptr<RecordBatch>* out) {
   const int64_t length = 500;
   auto f0 = field("f0", null());
-  std::shared_ptr<Schema> schema(new Schema({f0}));
+  auto schema = ::arrow::schema({f0});
   std::shared_ptr<Array> a0 = std::make_shared<NullArray>(length);
   out->reset(new RecordBatch(schema, length, {a0}));
   return Status::OK();
@@ -270,7 +270,7 @@ Status MakeListRecordBatch(std::shared_ptr<RecordBatch>* out) {
   auto f0 = field("f0", kListInt32);
   auto f1 = field("f1", kListListInt32);
   auto f2 = field("f2", int32());
-  std::shared_ptr<Schema> schema(new Schema({f0, f1, f2}));
+  auto schema = ::arrow::schema({f0, f1, f2});
 
   // Example data
 
@@ -293,7 +293,7 @@ Status MakeZeroLengthRecordBatch(std::shared_ptr<RecordBatch>* out)
{
   auto f0 = field("f0", kListInt32);
   auto f1 = field("f1", kListListInt32);
   auto f2 = field("f2", int32());
-  std::shared_ptr<Schema> schema(new Schema({f0, f1, f2}));
+  auto schema = ::arrow::schema({f0, f1, f2});
 
   // Example data
   MemoryPool* pool = default_memory_pool();
@@ -313,7 +313,7 @@ Status MakeNonNullRecordBatch(std::shared_ptr<RecordBatch>* out)
{
   auto f0 = field("f0", kListInt32);
   auto f1 = field("f1", kListListInt32);
   auto f2 = field("f2", int32());
-  std::shared_ptr<Schema> schema(new Schema({f0, f1, f2}));
+  auto schema = ::arrow::schema({f0, f1, f2});
 
   // Example data
   MemoryPool* pool = default_memory_pool();
@@ -345,7 +345,7 @@ Status MakeDeeplyNestedList(std::shared_ptr<RecordBatch>* out) {
   }
 
   auto f0 = field("f0", type);
-  std::shared_ptr<Schema> schema(new Schema({f0}));
+  auto schema = ::arrow::schema({f0});
   std::vector<std::shared_ptr<Array>> arrays = {array};
   out->reset(new RecordBatch(schema, batch_length, arrays));
   return Status::OK();
@@ -364,7 +364,7 @@ Status MakeStruct(std::shared_ptr<RecordBatch>* out) {
       {list_schema->field(0), list_schema->field(1), list_schema->field(2)}));
   auto f0 = field("non_null_struct", type);
   auto f1 = field("null_struct", type);
-  std::shared_ptr<Schema> schema(new Schema({f0, f1}));
+  auto schema = ::arrow::schema({f0, f1});
 
   // construct individual nullable/non-nullable struct arrays
   std::shared_ptr<Array> no_nulls(new StructArray(type, list_batch->num_rows(),
columns));
@@ -397,7 +397,7 @@ Status MakeUnion(std::shared_ptr<RecordBatch>* out) {
   auto f1 = field("sparse", sparse_type);
   auto f2 = field("dense", dense_type);
 
-  std::shared_ptr<Schema> schema(new Schema({f0, f1, f2}));
+  auto schema = ::arrow::schema({f0, f1, f2});
 
   // Create data
   std::vector<std::shared_ptr<Array>> sparse_children(2);
@@ -520,9 +520,9 @@ Status MakeDictionary(std::shared_ptr<RecordBatch>* out) {
   auto a4 = std::make_shared<DictionaryArray>(f4_type, indices4);
 
   // construct batch
-  std::shared_ptr<Schema> schema(new Schema(
+  auto schema = ::arrow::schema(
       {field("dict1", f0_type), field("sparse", f1_type), field("dense", f2_type),
-       field("list of encoded string", f3_type), field("encoded list<int8>", f4_type)}));
+       field("list of encoded string", f3_type), field("encoded list<int8>", f4_type)});
 
   std::vector<std::shared_ptr<Array>> arrays = {a0, a1, a2, a3, a4};
 
@@ -560,8 +560,8 @@ Status MakeDictionaryFlat(std::shared_ptr<RecordBatch>* out) {
   auto a2 = std::make_shared<DictionaryArray>(f2_type, indices2);
 
   // construct batch
-  std::shared_ptr<Schema> schema(new Schema(
-      {field("dict1", f0_type), field("sparse", f1_type), field("dense", f2_type)}));
+  auto schema = ::arrow::schema(
+      {field("dict1", f0_type), field("sparse", f1_type), field("dense", f2_type)});
 
   std::vector<std::shared_ptr<Array>> arrays = {a0, a1, a2};
   out->reset(new RecordBatch(schema, length, arrays));
@@ -572,7 +572,7 @@ Status MakeDates(std::shared_ptr<RecordBatch>* out) {
   std::vector<bool> is_valid = {true, true, true, false, true, true, true};
   auto f0 = field("f0", date32());
   auto f1 = field("f1", date64());
-  std::shared_ptr<Schema> schema(new Schema({f0, f1}));
+  auto schema = ::arrow::schema({f0, f1});
 
   std::vector<int32_t> date32_values = {0, 1, 2, 3, 4, 5, 6};
   std::shared_ptr<Array> date32_array;
@@ -594,7 +594,7 @@ Status MakeTimestamps(std::shared_ptr<RecordBatch>* out) {
   auto f0 = field("f0", timestamp(TimeUnit::MILLI));
   auto f1 = field("f1", timestamp(TimeUnit::NANO, "America/New_York"));
   auto f2 = field("f2", timestamp(TimeUnit::SECOND));
-  std::shared_ptr<Schema> schema(new Schema({f0, f1, f2}));
+  auto schema = ::arrow::schema({f0, f1, f2});
 
   std::vector<int64_t> ts_values = {1489269000000, 1489270000000, 1489271000000,
                                     1489272000000, 1489272000000, 1489273000000};
@@ -615,7 +615,7 @@ Status MakeTimes(std::shared_ptr<RecordBatch>* out) {
   auto f1 = field("f1", time64(TimeUnit::NANO));
   auto f2 = field("f2", time32(TimeUnit::SECOND));
   auto f3 = field("f3", time64(TimeUnit::NANO));
-  std::shared_ptr<Schema> schema(new Schema({f0, f1, f2, f3}));
+  auto schema = ::arrow::schema({f0, f1, f2, f3});
 
   std::vector<int32_t> t32_values = {1489269000, 1489270000, 1489271000,
                                      1489272000, 1489272000, 1489273000};
@@ -649,7 +649,7 @@ Status MakeFWBinary(std::shared_ptr<RecordBatch>* out) {
   std::vector<bool> is_valid = {true, true, true, false};
   auto f0 = field("f0", fixed_size_binary(4));
   auto f1 = field("f1", fixed_size_binary(0));
-  std::shared_ptr<Schema> schema(new Schema({f0, f1}));
+  auto schema = ::arrow::schema({f0, f1});
 
   std::shared_ptr<Array> a1, a2;
 

http://git-wip-us.apache.org/repos/asf/arrow/blob/02ab7484/cpp/src/arrow/python/builtin_convert.cc
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/python/builtin_convert.cc b/cpp/src/arrow/python/builtin_convert.cc
index 218fe29..b693b3e 100644
--- a/cpp/src/arrow/python/builtin_convert.cc
+++ b/cpp/src/arrow/python/builtin_convert.cc
@@ -534,8 +534,8 @@ class UTF8Converter : public TypedConverterVisitor<StringBuilder, UTF8Converter>
     if (obj == Py_None) {
       return typed_builder_->AppendNull();
     } else if (PyBytes_Check(obj)) {
-      tmp.reset(PyUnicode_FromStringAndSize(PyBytes_AS_STRING(obj),
-                                            PyBytes_GET_SIZE(obj)));
+      tmp.reset(
+          PyUnicode_FromStringAndSize(PyBytes_AS_STRING(obj), PyBytes_GET_SIZE(obj)));
       RETURN_IF_PYERROR();
       bytes_obj = obj;
     } else if (!PyUnicode_Check(obj)) {

http://git-wip-us.apache.org/repos/asf/arrow/blob/02ab7484/cpp/src/arrow/table-test.cc
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/table-test.cc b/cpp/src/arrow/table-test.cc
index 8dba8c0..1ba7a2f 100644
--- a/cpp/src/arrow/table-test.cc
+++ b/cpp/src/arrow/table-test.cc
@@ -214,7 +214,7 @@ class TestTable : public TestBase {
 };
 
 TEST_F(TestTable, EmptySchema) {
-  auto empty_schema = shared_ptr<Schema>(new Schema({}));
+  auto empty_schema = ::arrow::schema({});
   table_.reset(new Table(empty_schema, columns_));
   ASSERT_OK(table_->ValidateColumns());
   ASSERT_EQ(0, table_->num_rows());
@@ -373,18 +373,17 @@ TEST_F(TestTable, RemoveColumn) {
   std::shared_ptr<Table> result;
   ASSERT_OK(table.RemoveColumn(0, &result));
 
-  auto ex_schema =
-      std::shared_ptr<Schema>(new Schema({schema_->field(1), schema_->field(2)}));
+  auto ex_schema = ::arrow::schema({schema_->field(1), schema_->field(2)});
   std::vector<std::shared_ptr<Column>> ex_columns = {table.column(1), table.column(2)};
   ASSERT_TRUE(result->Equals(Table(ex_schema, ex_columns)));
 
   ASSERT_OK(table.RemoveColumn(1, &result));
-  ex_schema = std::shared_ptr<Schema>(new Schema({schema_->field(0), schema_->field(2)}));
+  ex_schema = ::arrow::schema({schema_->field(0), schema_->field(2)});
   ex_columns = {table.column(0), table.column(2)};
   ASSERT_TRUE(result->Equals(Table(ex_schema, ex_columns)));
 
   ASSERT_OK(table.RemoveColumn(2, &result));
-  ex_schema = std::shared_ptr<Schema>(new Schema({schema_->field(0), schema_->field(1)}));
+  ex_schema = ::arrow::schema({schema_->field(0), schema_->field(1)});
   ex_columns = {table.column(0), table.column(1)};
   ASSERT_TRUE(result->Equals(Table(ex_schema, ex_columns)));
 }
@@ -410,27 +409,27 @@ TEST_F(TestTable, AddColumn) {
 
   // Add column 0 in different places
   ASSERT_OK(table.AddColumn(0, columns_[0], &result));
-  auto ex_schema = std::shared_ptr<Schema>(new Schema(
-      {schema_->field(0), schema_->field(0), schema_->field(1), schema_->field(2)}));
+  auto ex_schema = ::arrow::schema(
+      {schema_->field(0), schema_->field(0), schema_->field(1), schema_->field(2)});
   std::vector<std::shared_ptr<Column>> ex_columns = {table.column(0), table.column(0),
                                                      table.column(1), table.column(2)};
   ASSERT_TRUE(result->Equals(Table(ex_schema, ex_columns)));
 
   ASSERT_OK(table.AddColumn(1, columns_[0], &result));
-  ex_schema = std::shared_ptr<Schema>(new Schema(
-      {schema_->field(0), schema_->field(0), schema_->field(1), schema_->field(2)}));
+  ex_schema = ::arrow::schema(
+      {schema_->field(0), schema_->field(0), schema_->field(1), schema_->field(2)});
   ex_columns = {table.column(0), table.column(0), table.column(1), table.column(2)};
   ASSERT_TRUE(result->Equals(Table(ex_schema, ex_columns)));
 
   ASSERT_OK(table.AddColumn(2, columns_[0], &result));
-  ex_schema = std::shared_ptr<Schema>(new Schema(
-      {schema_->field(0), schema_->field(1), schema_->field(0), schema_->field(2)}));
+  ex_schema = ::arrow::schema(
+      {schema_->field(0), schema_->field(1), schema_->field(0), schema_->field(2)});
   ex_columns = {table.column(0), table.column(1), table.column(0), table.column(2)};
   ASSERT_TRUE(result->Equals(Table(ex_schema, ex_columns)));
 
   ASSERT_OK(table.AddColumn(3, columns_[0], &result));
-  ex_schema = std::shared_ptr<Schema>(new Schema(
-      {schema_->field(0), schema_->field(1), schema_->field(2), schema_->field(0)}));
+  ex_schema = ::arrow::schema(
+      {schema_->field(0), schema_->field(1), schema_->field(2), schema_->field(0)});
   ex_columns = {table.column(0), table.column(1), table.column(2), table.column(0)};
   ASSERT_TRUE(result->Equals(Table(ex_schema, ex_columns)));
 }
@@ -470,7 +469,7 @@ TEST_F(TestRecordBatch, Validate) {
   auto f1 = field("f1", uint8());
   auto f2 = field("f2", int16());
 
-  auto schema = std::shared_ptr<Schema>(new Schema({f0, f1, f2}));
+  auto schema = ::arrow::schema({f0, f1, f2});
 
   auto a0 = MakePrimitive<Int32Array>(length);
   auto a1 = MakePrimitive<UInt8Array>(length);

http://git-wip-us.apache.org/repos/asf/arrow/blob/02ab7484/cpp/src/arrow/type-test.cc
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/type-test.cc b/cpp/src/arrow/type-test.cc
index 6b86b4d..4ac5c85 100644
--- a/cpp/src/arrow/type-test.cc
+++ b/cpp/src/arrow/type-test.cc
@@ -97,15 +97,14 @@ TEST_F(TestSchema, Basics) {
 
   auto f2 = field("f2", utf8());
 
-  vector<shared_ptr<Field>> fields = {f0, f1, f2};
-  auto schema = std::make_shared<Schema>(fields);
+  auto schema = ::arrow::schema({f0, f1, f2});
 
   ASSERT_EQ(3, schema->num_fields());
   ASSERT_TRUE(f0->Equals(schema->field(0)));
   ASSERT_TRUE(f1->Equals(schema->field(1)));
   ASSERT_TRUE(f2->Equals(schema->field(2)));
 
-  auto schema2 = std::make_shared<Schema>(fields);
+  auto schema2 = ::arrow::schema({f0, f1, f2});
 
   vector<shared_ptr<Field>> fields3 = {f0, f1_optional, f2};
   auto schema3 = std::make_shared<Schema>(fields3);
@@ -119,8 +118,7 @@ TEST_F(TestSchema, ToString) {
   auto f2 = field("f2", utf8());
   auto f3 = field("f3", list(int16()));
 
-  vector<shared_ptr<Field>> fields = {f0, f1, f2, f3};
-  auto schema = std::make_shared<Schema>(fields);
+  auto schema = ::arrow::schema({f0, f1, f2, f3});
 
   std::string result = schema->ToString();
   std::string expected = R"(f0: int32
@@ -137,8 +135,7 @@ TEST_F(TestSchema, GetFieldByName) {
   auto f2 = field("f2", utf8());
   auto f3 = field("f3", list(int16()));
 
-  vector<shared_ptr<Field>> fields = {f0, f1, f2, f3};
-  auto schema = std::make_shared<Schema>(fields);
+  auto schema = ::arrow::schema({f0, f1, f2, f3});
 
   std::shared_ptr<Field> result;
 
@@ -158,13 +155,12 @@ TEST_F(TestSchema, GetFieldIndex) {
   auto f2 = field("f2", utf8());
   auto f3 = field("f3", list(int16()));
 
-  vector<shared_ptr<Field>> fields = {f0, f1, f2, f3};
-  auto schema = std::make_shared<Schema>(fields);
+  auto schema = ::arrow::schema({f0, f1, f2, f3});
 
-  ASSERT_EQ(0, schema->GetFieldIndex(fields[0]->name()));
-  ASSERT_EQ(1, schema->GetFieldIndex(fields[1]->name()));
-  ASSERT_EQ(2, schema->GetFieldIndex(fields[2]->name()));
-  ASSERT_EQ(3, schema->GetFieldIndex(fields[3]->name()));
+  ASSERT_EQ(0, schema->GetFieldIndex(f0->name()));
+  ASSERT_EQ(1, schema->GetFieldIndex(f1->name()));
+  ASSERT_EQ(2, schema->GetFieldIndex(f2->name()));
+  ASSERT_EQ(3, schema->GetFieldIndex(f3->name()));
   ASSERT_EQ(-1, schema->GetFieldIndex("not-found"));
 }
 
@@ -172,10 +168,9 @@ TEST_F(TestSchema, TestMetadataConstruction) {
   auto f0 = field("f0", int32());
   auto f1 = field("f1", uint8(), false);
   auto f2 = field("f2", utf8());
-  vector<shared_ptr<Field>> fields = {f0, f1, f2};
   auto metadata = std::shared_ptr<KeyValueMetadata>(
       new KeyValueMetadata({"foo", "bar"}, {"bizz", "buzz"}));
-  auto schema = std::make_shared<Schema>(fields, metadata);
+  auto schema = ::arrow::schema({f0, f1, f2}, metadata);
   ASSERT_TRUE(metadata->Equals(*schema->metadata()));
 }
 

http://git-wip-us.apache.org/repos/asf/arrow/blob/02ab7484/cpp/src/arrow/type.cc
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/type.cc b/cpp/src/arrow/type.cc
index edf4d33..4443e8d 100644
--- a/cpp/src/arrow/type.cc
+++ b/cpp/src/arrow/type.cc
@@ -252,6 +252,10 @@ Schema::Schema(const std::vector<std::shared_ptr<Field>>&
fields,
                const std::shared_ptr<const KeyValueMetadata>& metadata)
     : fields_(fields), metadata_(metadata) {}
 
+Schema::Schema(std::vector<std::shared_ptr<Field>>&& fields,
+               const std::shared_ptr<const KeyValueMetadata>& metadata)
+    : fields_(std::move(fields)), metadata_(metadata) {}
+
 bool Schema::Equals(const Schema& other) const {
   if (this == &other) {
     return true;
@@ -343,6 +347,16 @@ std::string Schema::ToString() const {
   return buffer.str();
 }
 
+std::shared_ptr<Schema> schema(const std::vector<std::shared_ptr<Field>>&
fields,
+                               const std::shared_ptr<const KeyValueMetadata>& metadata)
{
+  return std::make_shared<Schema>(fields, metadata);
+}
+
+std::shared_ptr<Schema> schema(std::vector<std::shared_ptr<Field>>&&
fields,
+                               const std::shared_ptr<const KeyValueMetadata>& metadata)
{
+  return std::make_shared<Schema>(std::move(fields), metadata);
+}
+
 // ----------------------------------------------------------------------
 // Visitors and factory functions
 

http://git-wip-us.apache.org/repos/asf/arrow/blob/02ab7484/cpp/src/arrow/type.h
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/type.h b/cpp/src/arrow/type.h
index b28fe92..4917ebb 100644
--- a/cpp/src/arrow/type.h
+++ b/cpp/src/arrow/type.h
@@ -708,6 +708,10 @@ class ARROW_EXPORT Schema {
  public:
   explicit Schema(const std::vector<std::shared_ptr<Field>>& fields,
                   const std::shared_ptr<const KeyValueMetadata>& metadata = nullptr);
+
+  explicit Schema(std::vector<std::shared_ptr<Field>>&& fields,
+                  const std::shared_ptr<const KeyValueMetadata>& metadata = nullptr);
+
   virtual ~Schema() = default;
 
   /// Returns true if all of the schema fields are equal
@@ -772,27 +776,56 @@ std::shared_ptr<DataType> ARROW_EXPORT timestamp(TimeUnit::type
unit);
 std::shared_ptr<DataType> ARROW_EXPORT timestamp(TimeUnit::type unit,
                                                  const std::string& timezone);
 
+/// \brief Create an instance of 32-bit time type
 /// Unit can be either SECOND or MILLI
 std::shared_ptr<DataType> ARROW_EXPORT time32(TimeUnit::type unit);
 
+/// \brief Create an instance of 64-bit time type
 /// Unit can be either MICRO or NANO
 std::shared_ptr<DataType> ARROW_EXPORT time64(TimeUnit::type unit);
 
+/// \brief Create an instance of Struct type
 std::shared_ptr<DataType> ARROW_EXPORT
 struct_(const std::vector<std::shared_ptr<Field>>& fields);
 
+/// \brief Create an instance of Union type
 std::shared_ptr<DataType> ARROW_EXPORT
 union_(const std::vector<std::shared_ptr<Field>>& child_fields,
        const std::vector<uint8_t>& type_codes, UnionMode mode = UnionMode::SPARSE);
 
+/// \brief Create an instance of Dictionary type
 std::shared_ptr<DataType> ARROW_EXPORT
 dictionary(const std::shared_ptr<DataType>& index_type,
            const std::shared_ptr<Array>& values, bool ordered = false);
 
+/// \brief Create a Field instance
+///
+/// \param name the field name
+/// \param type the field value type
+/// \param nullable whether the values are nullable, default true
+/// \param metadata any custom key-value metadata, default nullptr
 std::shared_ptr<Field> ARROW_EXPORT field(
     const std::string& name, const std::shared_ptr<DataType>& type, bool nullable
= true,
     const std::shared_ptr<const KeyValueMetadata>& metadata = nullptr);
 
+/// \brief Create a Schema instance
+///
+/// \param fields the schema's fields
+/// \param metadata any custom key-value metadata, default nullptr
+/// \return schema shared_ptr to Schema
+std::shared_ptr<Schema> ARROW_EXPORT
+schema(const std::vector<std::shared_ptr<Field>>& fields,
+       const std::shared_ptr<const KeyValueMetadata>& metadata = nullptr);
+
+/// \brief Create a Schema instance
+///
+/// \param fields the schema's fields (rvalue reference)
+/// \param metadata any custom key-value metadata, default nullptr
+/// \return schema shared_ptr to Schema
+std::shared_ptr<Schema> ARROW_EXPORT
+schema(std::vector<std::shared_ptr<Field>>&& fields,
+       const std::shared_ptr<const KeyValueMetadata>& metadata = nullptr);
+
 // ----------------------------------------------------------------------
 //
 


Mime
View raw message