From 199cec989f00367c26ddb3462b2b66ffd41fc760 Mon Sep 17 00:00:00 2001 From: Sarah Gilmore Date: Tue, 11 Jun 2024 13:44:40 -0400 Subject: [PATCH] add feather v1 test point --- cpp/src/arrow/ipc/CMakeLists.txt | 1 + cpp/src/arrow/ipc/feather_v1_test.cc | 86 ++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 cpp/src/arrow/ipc/feather_v1_test.cc diff --git a/cpp/src/arrow/ipc/CMakeLists.txt b/cpp/src/arrow/ipc/CMakeLists.txt index 2fc9b145ccc98..5b1b69a0959de 100644 --- a/cpp/src/arrow/ipc/CMakeLists.txt +++ b/cpp/src/arrow/ipc/CMakeLists.txt @@ -42,6 +42,7 @@ add_arrow_ipc_test(json_simple_test) add_arrow_ipc_test(message_internal_test) add_arrow_ipc_test(read_write_test) add_arrow_ipc_test(tensor_test) +add_arrow_ipc_test(feather_v1_test) # Headers: top level arrow_install_all_headers("arrow/ipc") diff --git a/cpp/src/arrow/ipc/feather_v1_test.cc b/cpp/src/arrow/ipc/feather_v1_test.cc new file mode 100644 index 0000000000000..31a9dc83bb14a --- /dev/null +++ b/cpp/src/arrow/ipc/feather_v1_test.cc @@ -0,0 +1,86 @@ +// 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. + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "arrow/array.h" +#include "arrow/buffer.h" +#include "arrow/ipc/feather.h" +#include "arrow/record_batch.h" +#include "arrow/status.h" +#include "arrow/table.h" +#include "arrow/testing/gtest_util.h" +#include "arrow/type.h" +#include "arrow/io/file.h" +#include "arrow/result.h" +#include "arrow/type_fwd.h" +#include "arrow/type_traits.h" +#include "arrow/array/builder_primitive.h" + +namespace { + template + arrow::Result> make_numeric_array(std::vector values) { + using TypeClass = typename arrow::CTypeTraits::ArrowType; + arrow::NumericBuilder builder; + ARROW_RETURN_NOT_OK(builder.AppendValues(values)); + std::shared_ptr array; + ARROW_RETURN_NOT_OK(builder.Finish(&array)); + return array; + } + + arrow::Result> make_table() { + std::vector doubleValues = {1.0, 2.0, 3.0, 4.0}; + std::vector int32Values = {1, 2, 3, 4}; + + ARROW_ASSIGN_OR_RAISE(auto doubleArray, make_numeric_array(doubleValues)); + + ARROW_ASSIGN_OR_RAISE(auto int32Array, make_numeric_array(int32Values)); + + std::vector> columns = {doubleArray, int32Array}; + auto tableSchema = arrow::schema({arrow::field("A", doubleArray->type()), arrow::field("B", int32Array->type())}); + + return arrow::Table::Make(tableSchema, columns); + } +} + +TEST(WriteFeatherV1File, Smoke) { + auto props = WriteProperties::Defaults(); + + std::string filename = "testfeather.feater"; + ASSERT_TRUE(maybe_table.ok()); + auto table = maybe_table.ValueOrDie(); + std::cout << "Table: " << std::endl; + std::cout << table->ToString() << std::endl; + + auto maybe_output_stream = arrow::io::FileOutputStream::Open(filename); + ASSERT_TRUE(maybe_output_stream.ok()); + auto output_stream = maybe_output_stream.ValueOrDie(); + std::cout << "Made file output stream" << std::endl; + arrow::ipc::feather::WriteProperties write_props; + write_props.version = arrow::ipc::feather::kFeatherV1Version; + auto st = arrow::ipc::feather::WriteTable(*table, output_stream.get(), write_props); + ASSERT_TRUE(st.ok()); + std::cout << "Write feather v1 file" << std::endl; +} \ No newline at end of file