Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial support for loading Apache Arrow data #11

Merged
merged 16 commits into from
Jan 26, 2018
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Clean up differentiation of arrow/non-arrow data
  • Loading branch information
nmichaud committed Jan 22, 2018
commit a8d5264307b5d2392da4880b4ee6fdc93875b3d5
23 changes: 11 additions & 12 deletions packages/perspective/src/cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ _get_aggspecs(val j_aggs)
*/


template<typename T>
void
vecFromTypedArray(const val &typedArray, void* data, t_int32 length) {
val memory = val::module_property("buffer");
Expand All @@ -158,9 +157,9 @@ _fill_col(val dcol, t_col_sptr col, t_col_sptr key_col, bool fill_index)
{
t_int32 nrows = dcol["length"].as<t_int32>();

if (internal::typeSupportsMemoryView<T>()) {
if (!dcol["buffer"].isUndefined()) {
t_lstore* lstore = col->_get_data_lstore();
vecFromTypedArray<T>(dcol, lstore->get_ptr(0), nrows);
vecFromTypedArray(dcol, lstore->get_ptr(0), nrows);
col->valid_raw_fill(true);
} else {
for (auto i = 0; i < nrows; ++i)
Expand All @@ -181,9 +180,9 @@ _fill_col<t_int64>(val dcol, t_col_sptr col, t_col_sptr key_col, bool fill_index
{
t_int32 nrows = dcol["length"].as<t_int32>();

if (internal::typeSupportsMemoryView<t_int32>()) {
if (dcol["constructor"]["name"].as<t_str>() == "Int32Array") {
t_lstore* lstore = col->_get_data_lstore();
vecFromTypedArray<t_int64>(dcol, lstore->get_ptr(0), nrows);
vecFromTypedArray(dcol, lstore->get_ptr(0), nrows);
col->valid_raw_fill(true);
} else {
throw std::logic_error("Unreachable");
Expand All @@ -196,9 +195,9 @@ _fill_col<t_time>(val dcol, t_col_sptr col, t_col_sptr key_col, bool fill_index)
{
t_int32 nrows = dcol["length"].as<t_int32>();

if (internal::typeSupportsMemoryView<t_int32>()) {
if (dcol["constructor"]["name"].as<t_str>() == "Int32Array") {
t_lstore* lstore = col->_get_data_lstore();
vecFromTypedArray<t_int64>(dcol, lstore->get_ptr(0), nrows);
vecFromTypedArray(dcol, lstore->get_ptr(0), nrows);
col->valid_raw_fill(true);
} else {
for (auto i = 0; i < nrows; ++i)
Expand Down Expand Up @@ -237,22 +236,22 @@ _fill_col_dict(t_uint32 nrows, val dcol, val vkeys, t_col_sptr col)
std::vector<T> keys;
keys.reserve(ksize);
keys.resize(ksize);
vecFromTypedArray<T>(vkeys, keys.data(), ksize);
vecFromTypedArray(vkeys, keys.data(), ksize);

val values = dcol["data"]["values"];
val vdata = values["data"];
t_int32 vsize = vdata["length"].as<t_int32>();
std::vector<t_uchar> data;
data.reserve(vsize);
data.resize(vsize);
vecFromTypedArray<t_uchar>(vdata, data.data(), vsize);
vecFromTypedArray(vdata, data.data(), vsize);

val voffsets = values["offsets"];
t_int32 osize = voffsets["length"].as<t_int32>();
std::vector<t_int32> offsets;
offsets.reserve(osize);
offsets.resize(osize);
vecFromTypedArray<t_int32>(voffsets, offsets.data(), osize);
vecFromTypedArray(voffsets, offsets.data(), osize);

t_str elem;

Expand Down Expand Up @@ -303,14 +302,14 @@ _fill_col<std::string>(val dcol, t_col_sptr col, t_col_sptr key_col, bool fill_i
std::vector<t_uint8> data;
data.reserve(vsize);
data.resize(vsize);
vecFromTypedArray<t_uint8>(vdata, data.data(), vsize);
vecFromTypedArray(vdata, data.data(), vsize);

val voffsets = values["offsets"];
t_int32 osize = voffsets["length"].as<t_int32>();
std::vector<t_int32> offsets;
offsets.reserve(osize);
offsets.resize(osize);
vecFromTypedArray<t_int32>(voffsets, offsets.data(), osize);
vecFromTypedArray(voffsets, offsets.data(), osize);

t_str elem;

Expand Down