On 2nd thoughts, the 2nd method could also be done in a single line.

auto low3 =
arrow::Datum(st_s_low.ValueOrDie()).scalar_as<arrow::DoubleScalar>().value;

That said, I'm still keen to hear if there's an advantage to using Datum or
without; and on my 2nd question regarding efficiently looping through a
slice's values.

On Mon, 19 Feb 2024 at 09:24, Blair Azzopardi <blai...@gmail.com> wrote:

> 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