Skip to content

Commit 199cec9

Browse files
committed
add feather v1 test point
1 parent 0ff17bf commit 199cec9

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

cpp/src/arrow/ipc/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ add_arrow_ipc_test(json_simple_test)
4242
add_arrow_ipc_test(message_internal_test)
4343
add_arrow_ipc_test(read_write_test)
4444
add_arrow_ipc_test(tensor_test)
45+
add_arrow_ipc_test(feather_v1_test)
4546

4647
# Headers: top level
4748
arrow_install_all_headers("arrow/ipc")

cpp/src/arrow/ipc/feather_v1_test.cc

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
#include <functional>
19+
#include <memory>
20+
#include <string>
21+
#include <tuple>
22+
#include <utility>
23+
#include <iostream>
24+
#include <numeric>
25+
26+
#include <gtest/gtest.h>
27+
28+
#include "arrow/array.h"
29+
#include "arrow/buffer.h"
30+
#include "arrow/ipc/feather.h"
31+
#include "arrow/record_batch.h"
32+
#include "arrow/status.h"
33+
#include "arrow/table.h"
34+
#include "arrow/testing/gtest_util.h"
35+
#include "arrow/type.h"
36+
#include "arrow/io/file.h"
37+
#include "arrow/result.h"
38+
#include "arrow/type_fwd.h"
39+
#include "arrow/type_traits.h"
40+
#include "arrow/array/builder_primitive.h"
41+
42+
namespace {
43+
template <typename CType>
44+
arrow::Result<std::shared_ptr<arrow::Array>> make_numeric_array(std::vector<CType> values) {
45+
using TypeClass = typename arrow::CTypeTraits<CType>::ArrowType;
46+
arrow::NumericBuilder<TypeClass> builder;
47+
ARROW_RETURN_NOT_OK(builder.AppendValues(values));
48+
std::shared_ptr<arrow::Array> array;
49+
ARROW_RETURN_NOT_OK(builder.Finish(&array));
50+
return array;
51+
}
52+
53+
arrow::Result<std::shared_ptr<arrow::Table>> make_table() {
54+
std::vector<double> doubleValues = {1.0, 2.0, 3.0, 4.0};
55+
std::vector<int32_t> int32Values = {1, 2, 3, 4};
56+
57+
ARROW_ASSIGN_OR_RAISE(auto doubleArray, make_numeric_array(doubleValues));
58+
59+
ARROW_ASSIGN_OR_RAISE(auto int32Array, make_numeric_array(int32Values));
60+
61+
std::vector<std::shared_ptr<arrow::Array>> columns = {doubleArray, int32Array};
62+
auto tableSchema = arrow::schema({arrow::field("A", doubleArray->type()), arrow::field("B", int32Array->type())});
63+
64+
return arrow::Table::Make(tableSchema, columns);
65+
}
66+
}
67+
68+
TEST(WriteFeatherV1File, Smoke) {
69+
auto props = WriteProperties::Defaults();
70+
71+
std::string filename = "testfeather.feater";
72+
ASSERT_TRUE(maybe_table.ok());
73+
auto table = maybe_table.ValueOrDie();
74+
std::cout << "Table: " << std::endl;
75+
std::cout << table->ToString() << std::endl;
76+
77+
auto maybe_output_stream = arrow::io::FileOutputStream::Open(filename);
78+
ASSERT_TRUE(maybe_output_stream.ok());
79+
auto output_stream = maybe_output_stream.ValueOrDie();
80+
std::cout << "Made file output stream" << std::endl;
81+
arrow::ipc::feather::WriteProperties write_props;
82+
write_props.version = arrow::ipc::feather::kFeatherV1Version;
83+
auto st = arrow::ipc::feather::WriteTable(*table, output_stream.get(), write_props);
84+
ASSERT_TRUE(st.ok());
85+
std::cout << "Write feather v1 file" << std::endl;
86+
}

0 commit comments

Comments
 (0)