Hi

I'm trying to figure out the optimal way for extracting scalar values from
a table; I've found two ways, using a dynamic cast or using Datum and cast.
Is one better than the other? The advantage of the dynamic cast, seems at
least, to be a one liner.

auto c_val1 = table.GetColumnByName("Val1");
auto st_c_val1 = s_low->GetScalar(0);
if (st_c_val1.ok()) {

    // method 1 - via dyn cast
    auto val1 =
std::dynamic_pointer_cast<arrow::DoubleScalar>(st_c_val1.ValueOrDie())->value;

    // method 2 - via Datum & cast
    arrow::Datum val(st_c_val1.ValueOrDie());
    auto val1 = val.scalar_as<arrow::DoubleScalar>().value;
}

Also, is there an efficient way to loop through a slice perhaps by
incrementing a pointer? I know a chunked array might mean that the
underlying data isn't stored contiguously so perhaps this is tricky to do.
I imagine the compute functions might do this. Otherwise, it feels each
access to a value in memory requires calls to several functions
(GetScalar/ok/ValueOrDie etc).

Thanks in advance
Blair

Reply via email to