Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cpp/src/arrow/ipc/feather-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/arrow/ipc/ipc-json-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/arrow/ipc/ipc-read-write-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions cpp/src/arrow/ipc/json-internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/arrow/ipc/metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
36 changes: 18 additions & 18 deletions cpp/src/arrow/ipc/test-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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

Expand All @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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));
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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};

Expand Down Expand Up @@ -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));
Expand All @@ -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;
Expand All @@ -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};
Expand All @@ -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};
Expand Down Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions cpp/src/arrow/python/builtin_convert.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
27 changes: 13 additions & 14 deletions cpp/src/arrow/table-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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)));
}
Expand All @@ -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)));
}
Expand Down Expand Up @@ -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);
Expand Down
25 changes: 10 additions & 15 deletions cpp/src/arrow/type-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -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;

Expand All @@ -158,24 +155,22 @@ 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"));
}

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()));
}

Expand Down
14 changes: 14 additions & 0 deletions cpp/src/arrow/type.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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

Expand Down
Loading