-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
52cdc81
commit 9483af3
Showing
14 changed files
with
161 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* Copyright 2023 Man Group Operations Limited | ||
* | ||
* Use of this software is governed by the Business Source License 1.1 included in the file licenses/BSL.txt. | ||
* | ||
* As of the Change Date specified in that file, in accordance with the Business Source License, use of this software will be governed by the Apache License, version 2.0. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <sparrow/array/array_data.hpp> | ||
#include <sparrow/array.hpp> | ||
#include <sparrow/arrow_interface/array_data_to_arrow_array_converters.hpp> | ||
#include <sparrow/arrow_interface/arrow_array/smart_pointers.hpp> | ||
#include <sparrow/external_array.hpp> | ||
|
||
#include <arcticdb/column_store/memory_segment.hpp> | ||
|
||
|
||
namespace arcticdb { | ||
|
||
sparrow::arrow_array_unique_ptr arrow_data_from_column(const Column& column) { | ||
return column.type().visit_tag([&](auto && impl) -> sparrow::arrow_array_unique_ptr { | ||
using TagType = std::decay_t<decltype(impl)>; | ||
using DataType = TagType::DataTypeTag; | ||
using RawType = DataType::raw_type; | ||
if constexpr (!is_sequence_type(DataType::data_type)) { | ||
sparrow::array_data data; | ||
data.type = sparrow::data_descriptor(sparrow::arrow_traits<RawType>::type_id); | ||
auto column_data = column.data(); | ||
util::check(column_data.num_blocks() == 1, "Expected single block in arrow conversion"); | ||
auto block = column_data.next<TagType>().value(); | ||
const auto row_count = block.row_count(); | ||
sparrow::buffer<RawType> buffer(const_cast<RawType *>(block.release()), row_count); | ||
data.buffers.push_back(buffer); | ||
data.length = static_cast<std::int64_t>(row_count); | ||
data.offset = static_cast<std::int64_t>(0); | ||
return to_arrow_array_unique_ptr(std::move(data)); | ||
} else { | ||
util::raise_rte("Sequence types not implemented"); | ||
} | ||
}); | ||
}; | ||
|
||
std::vector<sparrow::arrow_array_unique_ptr> segment_to_arrow_arrays(SegmentInMemory& segment) { | ||
std::vector<sparrow::arrow_array_unique_ptr> output; | ||
for(auto& column : segment.columns()) { | ||
output.emplace_back(arrow_data_from_column(*column)); | ||
} | ||
return output; | ||
} | ||
|
||
|
||
} // namespace arcticdb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* Copyright 2023 Man Group Operations Limited | ||
* | ||
* Use of this software is governed by the Business Source License 1.1 included in the file licenses/BSL.txt. | ||
* | ||
* As of the Change Date specified in that file, in accordance with the Business Source License, use of this software will be governed by the Apache License, version 2.0. | ||
*/ | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include <arcticdb/util/test/generators.hpp> | ||
#include <arcticdb/arrow/arrow_utils.hpp> | ||
|
||
TEST(Arrow, ConvertColumn) { | ||
using namespace arcticdb; | ||
using TDT = TypeDescriptorTag<DataTypeTag<DataType::UINT16>, DimensionTag<Dimension ::Dim0>>; | ||
Column column(static_cast<TypeDescriptor>(TDT{}), 0, AllocationType::DETACHABLE, Sparsity::NOT_PERMITTED); | ||
for(auto i= 0; i < 10; ++i) { | ||
column.set_scalar<uint16_t>(i, i); | ||
} | ||
|
||
auto data = arrow_data_from_column(column); | ||
ASSERT_EQ(data->n_buffers, 2); | ||
ASSERT_EQ(data->offset, 0); | ||
ASSERT_EQ(data->n_children, 0); | ||
} | ||
|
||
TEST(Arrow, ConvertSegment) { | ||
using namespace arcticdb; | ||
auto desc = stream_descriptor(StreamId{"id"}, stream::RowCountIndex{}, { | ||
scalar_field(DataType::UINT8, "uint8"), | ||
scalar_field(DataType::UINT32, "uint32")}); | ||
|
||
SegmentInMemory segment(desc, 20, AllocationType::DETACHABLE, Sparsity::NOT_PERMITTED, DataTypeMode::INTERNAL); | ||
|
||
auto col1_ptr = segment.column(0).buffer().data(); | ||
auto col2_ptr = reinterpret_cast<uint32_t*>(segment.column(1).buffer().data()); | ||
for(auto j = 0; j < 20; ++j ) { | ||
*col1_ptr++ = j; | ||
*col2_ptr++ = j * 2; | ||
} | ||
|
||
auto vec = segment_to_arrow_arrays(segment); | ||
ASSERT_EQ(vec.size(), 2); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from arcticdb_ext.version_store import OutputFormat | ||
import pandas as pd | ||
import numpy as np | ||
|
||
|
||
def test_basic_roundtrip(lmdb_version_store_v1): | ||
lib = lmdb_version_store_v1 | ||
df = pd.DataFrame({"x": np.arange(10)}) | ||
lib.write("arrow", df) | ||
vit = lib.read("arrow", output_format=OutputFormat.ARROW) | ||
print(vit) |