Created
July 14, 2019 14:06
-
-
Save tebeka/ce81af9c784aa2a17d41f6d7fd825bbf to your computer and use it in GitHub Desktop.
column_get_bool
This file contains hidden or 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
typedef struct { | |
std::shared_ptr<arrow::Array> chunk; | |
int64_t offset; | |
const char *error; | |
} chunk_t; | |
chunk_t find_chunk(void *vp, long long i, int typ) { | |
chunk_t ct = {nullptr, 0, nullptr}; | |
auto column = (Column *)vp; | |
if (column == nullptr) { | |
ct.error = "null pointer"; | |
return ct; | |
} | |
if (column->ptr->type()->id() != typ) { | |
ct.error = "wrong type"; | |
return ct; | |
} | |
if ((i < 0) || (i >= column->ptr->length())) { | |
ct.error = "index out of range"; | |
return ct; | |
} | |
auto chunks = column->ptr->data(); | |
ct.offset = i; | |
for (int c = 0; c < chunks->num_chunks(); c++) { | |
auto chunk = chunks->chunk(c); | |
if (ct.offset < chunk->length()) { | |
ct.chunk = chunk; | |
return ct; | |
} | |
ct.offset -= chunk->length(); | |
} | |
ct.error = "can't get here"; | |
return ct; | |
} | |
int column_bool_at(void *vp, long long i) { | |
auto res = find_chunk(vp, i, BOOL_DTYPE); | |
if (res.error != nullptr) { | |
return -1; | |
} | |
auto arr = (arrow::BooleanArray *)(res.chunk.get()); | |
return arr->Value(res.offset); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment