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
3 changes: 3 additions & 0 deletions cpp/cmake_modules/SetupCxxFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ CHECK_CXX_COMPILER_FLAG("-maltivec" CXX_SUPPORTS_ALTIVEC)
# Arm64 compiler flags
CHECK_CXX_COMPILER_FLAG("-march=armv8-a+crc" CXX_SUPPORTS_ARMCRC)

# Support C11
set(CMAKE_C_STANDARD 11)

# This ensures that things like gnu++11 get passed correctly
set(CMAKE_CXX_STANDARD 11)

Expand Down
2 changes: 1 addition & 1 deletion cpp/examples/parquet/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ target_include_directories(parquet-low-level-example2 PRIVATE low-level-api/)
target_link_libraries(parquet-low-level-example parquet_static)
target_link_libraries(parquet-low-level-example2 parquet_static)

add_executable(parquet-arrow-example parquet-arrow/src/reader-writer.cc)
add_executable(parquet-arrow-example parquet-arrow/reader-writer.cc)
target_link_libraries(parquet-arrow-example parquet_shared)

add_dependencies(parquet
Expand Down
2 changes: 1 addition & 1 deletion cpp/examples/parquet/parquet-arrow/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ find_package(Parquet)

include_directories(SYSTEM ${ARROW_INCLUDE_DIR} ${PARQUET_INCLUDE_DIR})

add_executable(parquet-arrow-example src/reader-writer.cc)
add_executable(parquet-arrow-example reader-writer.cc)
target_link_libraries(parquet-arrow-example ${PARQUET_SHARED_LIB} ${ARROW_SHARED_LIB})
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void read_single_column() {
std::unique_ptr<parquet::arrow::FileReader> reader;
PARQUET_THROW_NOT_OK(
parquet::arrow::OpenFile(infile, arrow::default_memory_pool(), &reader));
std::shared_ptr<arrow::Array> array;
std::shared_ptr<arrow::ChunkedArray> array;
PARQUET_THROW_NOT_OK(reader->ReadColumn(0, &array));
PARQUET_THROW_NOT_OK(arrow::PrettyPrint(*array, 4, &std::cout));
std::cout << std::endl;
Expand All @@ -119,7 +119,7 @@ void read_single_column_chunk() {
std::unique_ptr<parquet::arrow::FileReader> reader;
PARQUET_THROW_NOT_OK(
parquet::arrow::OpenFile(infile, arrow::default_memory_pool(), &reader));
std::shared_ptr<arrow::Array> array;
std::shared_ptr<arrow::ChunkedArray> array;
PARQUET_THROW_NOT_OK(reader->RowGroup(0)->Column(0)->Read(&array));
PARQUET_THROW_NOT_OK(arrow::PrettyPrint(*array, 4, &std::cout));
std::cout << std::endl;
Expand Down
15 changes: 11 additions & 4 deletions cpp/src/arrow/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,17 @@ endfunction()

set(ARROW_SRCS
array.cc
buffer.cc

builder.cc
builder-adaptive.cc
builder-binary.cc
builder-dict.cc
array/builder_adaptive.cc
array/builder_base.cc
array/builder_binary.cc
array/builder_decimal.cc
array/builder_dict.cc
array/builder_nested.cc
array/builder_primitive.cc

buffer.cc
compare.cc
memory_pool.cc
pretty_print.cc
Expand Down Expand Up @@ -297,6 +303,7 @@ ADD_ARROW_TEST(tensor-test)
ADD_ARROW_BENCHMARK(builder-benchmark)
ADD_ARROW_BENCHMARK(column-benchmark)

add_subdirectory(array)
add_subdirectory(csv)
add_subdirectory(io)
add_subdirectory(util)
Expand Down
1 change: 1 addition & 0 deletions cpp/src/arrow/allocator-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <cstdint>
#include <limits>
#include <memory>
#include <new>

#include <gtest/gtest.h>
Expand Down
114 changes: 112 additions & 2 deletions cpp/src/arrow/array-binary-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
// specific language governing permissions and limitations
// under the License.

#include <algorithm>
#include <cstdint>
#include <cstring>
#include <limits>
#include <memory>
#include <string>
#include <vector>
Expand All @@ -28,10 +26,14 @@
#include "arrow/array.h"
#include "arrow/buffer.h"
#include "arrow/builder.h"
#include "arrow/memory_pool.h"
#include "arrow/status.h"
#include "arrow/test-common.h"
#include "arrow/test-util.h"
#include "arrow/type.h"
#include "arrow/type_traits.h"
#include "arrow/util/bit-util.h"
#include "arrow/util/checked_cast.h"

namespace arrow {

Expand Down Expand Up @@ -676,4 +678,112 @@ TEST_F(TestStringArray, TestSliceEquality) { CheckSliceEquality<BinaryType>(); }

TEST_F(TestBinaryArray, LengthZeroCtor) { BinaryArray array(0, nullptr, nullptr); }

// ----------------------------------------------------------------------
// ChunkedBinaryBuilder tests

class TestChunkedBinaryBuilder : public ::testing::Test {
public:
void SetUp() {}

void Init(int32_t chunksize) {
builder_.reset(new internal::ChunkedBinaryBuilder(chunksize));
}

protected:
std::unique_ptr<internal::ChunkedBinaryBuilder> builder_;
};

TEST_F(TestChunkedBinaryBuilder, BasicOperation) {
const int32_t chunksize = 1000;
Init(chunksize);

const int elem_size = 10;
uint8_t buf[elem_size];

BinaryBuilder unchunked_builder;

const int iterations = 1000;
for (int i = 0; i < iterations; ++i) {
random_bytes(elem_size, i, buf);

ASSERT_OK(unchunked_builder.Append(buf, elem_size));
ASSERT_OK(builder_->Append(buf, elem_size));
}

std::shared_ptr<Array> unchunked;
ASSERT_OK(unchunked_builder.Finish(&unchunked));

ArrayVector chunks;
ASSERT_OK(builder_->Finish(&chunks));

// This assumes that everything is evenly divisible
ArrayVector expected_chunks;
const int elems_per_chunk = chunksize / elem_size;
for (int i = 0; i < iterations / elems_per_chunk; ++i) {
expected_chunks.emplace_back(unchunked->Slice(i * elems_per_chunk, elems_per_chunk));
}

ASSERT_EQ(expected_chunks.size(), chunks.size());
for (size_t i = 0; i < chunks.size(); ++i) {
AssertArraysEqual(*expected_chunks[i], *chunks[i]);
}
}

TEST_F(TestChunkedBinaryBuilder, NoData) {
Init(1000);

ArrayVector chunks;
ASSERT_OK(builder_->Finish(&chunks));

ASSERT_EQ(1, chunks.size());
ASSERT_EQ(0, chunks[0]->length());
}

TEST_F(TestChunkedBinaryBuilder, LargeElements) {
Init(100);

const int bufsize = 101;
uint8_t buf[bufsize];

const int iterations = 100;
for (int i = 0; i < iterations; ++i) {
random_bytes(bufsize, i, buf);
ASSERT_OK(builder_->Append(buf, bufsize));
}

ArrayVector chunks;
ASSERT_OK(builder_->Finish(&chunks));
ASSERT_EQ(iterations, static_cast<int>(chunks.size()));

int64_t total_data_size = 0;
for (auto chunk : chunks) {
ASSERT_EQ(1, chunk->length());
total_data_size +=
static_cast<int64_t>(static_cast<const BinaryArray&>(*chunk).GetView(0).size());
}
ASSERT_EQ(iterations * bufsize, total_data_size);
}

TEST(TestChunkedStringBuilder, BasicOperation) {
const int chunksize = 100;
internal::ChunkedStringBuilder builder(chunksize);

std::string value = "0123456789";

const int iterations = 100;
for (int i = 0; i < iterations; ++i) {
ASSERT_OK(builder.Append(value));
}

ArrayVector chunks;
ASSERT_OK(builder.Finish(&chunks));

ASSERT_EQ(10, chunks.size());

// Type is correct
for (auto chunk : chunks) {
ASSERT_TRUE(chunk->type()->Equals(*::arrow::utf8()));
}
}

} // namespace arrow
8 changes: 4 additions & 4 deletions cpp/src/arrow/array-dict-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@
// specific language governing permissions and limitations
// under the License.

#include <algorithm>
#include <array>
#include <cstdint>
#include <cstring>
#include <limits>
#include <memory>
#include <ostream>
#include <string>
#include <vector>

#include <gtest/gtest.h>

#include "arrow/array.h"
#include "arrow/buffer.h"
#include "arrow/builder.h"
#include "arrow/memory_pool.h"
#include "arrow/status.h"
#include "arrow/test-common.h"
#include "arrow/test-util.h"
#include "arrow/type.h"
#include "arrow/util/decimal.h"

namespace arrow {

Expand Down
4 changes: 2 additions & 2 deletions cpp/src/arrow/array-list-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
// specific language governing permissions and limitations
// under the License.

#include <algorithm>
#include <cstdint>
#include <cstring>
#include <limits>
#include <memory>
#include <string>
#include <vector>
Expand All @@ -32,6 +30,8 @@
#include "arrow/test-common.h"
#include "arrow/test-util.h"
#include "arrow/type.h"
#include "arrow/util/bit-util.h"
#include "arrow/util/checked_cast.h"

namespace arrow {

Expand Down
4 changes: 1 addition & 3 deletions cpp/src/arrow/array-struct-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,21 @@
// specific language governing permissions and limitations
// under the License.

#include <algorithm>
#include <cstdint>
#include <cstring>
#include <limits>
#include <memory>
#include <string>
#include <vector>

#include <gtest/gtest.h>

#include "arrow/array.h"
#include "arrow/buffer.h"
#include "arrow/builder.h"
#include "arrow/status.h"
#include "arrow/test-common.h"
#include "arrow/test-util.h"
#include "arrow/type.h"
#include "arrow/util/checked_cast.h"

namespace arrow {

Expand Down
2 changes: 0 additions & 2 deletions cpp/src/arrow/array-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <limits>
#include <memory>
#include <numeric>
#include <ostream>
#include <string>
#include <type_traits>
#include <vector>
Expand All @@ -40,7 +39,6 @@
#include "arrow/test-common.h"
#include "arrow/test-util.h"
#include "arrow/type.h"
#include "arrow/type_traits.h"
#include "arrow/util/bit-util.h"
#include "arrow/util/checked_cast.h"
#include "arrow/util/decimal.h"
Expand Down
1 change: 1 addition & 0 deletions cpp/src/arrow/array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "arrow/array.h"

#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <limits>
#include <sstream>
Expand Down
1 change: 0 additions & 1 deletion cpp/src/arrow/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#ifndef ARROW_ARRAY_H
#define ARROW_ARRAY_H

#include <cstddef>
#include <cstdint>
#include <iosfwd>
#include <memory>
Expand Down
27 changes: 27 additions & 0 deletions cpp/src/arrow/array/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 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.

# Headers: top level
install(FILES
builder_adaptive.h
builder_base.h
builder_binary.h
builder_decimal.h
builder_dict.h
builder_nested.h
builder_primitive.h
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/arrow/array")
20 changes: 20 additions & 0 deletions cpp/src/arrow/array/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!---
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.
-->

## Implementation details related to columnnar (array) data structures
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
// specific language governing permissions and limitations
// under the License.

#include "arrow/array/builder_adaptive.h"

#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <utility>

#include "arrow/array.h"
#include "arrow/buffer.h"
#include "arrow/builder.h"
#include "arrow/status.h"
#include "arrow/type.h"
#include "arrow/type_traits.h"
Expand Down
Loading