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

How to retrieve value from a org.bytedeco.arrow.Scalar? #998

Closed
xuchen-plus opened this issue Jan 15, 2021 · 3 comments
Closed

How to retrieve value from a org.bytedeco.arrow.Scalar? #998

xuchen-plus opened this issue Jan 15, 2021 · 3 comments
Labels

Comments

@xuchen-plus
Copy link

After calling an arrow::compute::ScalarAggregationFunction, it returns a Datum object which contains a Scalar object. However, there's no value() method in the generated java wrapper to retrieve the underlying value, e.g. long/int, etc.

My code:

ArrowBuf buf; // this is an int64 ArrowBuf java object initialized in java

// Below are all javacpp calls

ArrowBuffer buffer = new ArrowBuffer(buf.nioBuffer(), capacity);
ExecContext context = new ExecContext();
DataType type = int64();
PrimitiveArray array = new PrimitiveArray(type, capacity, buffer);
Function func = context.func_registry().GetFunction("sum").ValueOrDie();
DatumVector vector = new DatumVector(new Datum(array));
Scalar s = func.Execute(vector, null, context).ValueOrDie().scalar();
// How can I retrieve the `long` value from the Scalar result object here?  Haven't found such methods from either Scalar or Int64Scalar classes.

Please help advice. Thanks very much.

@saudet
Copy link
Member

saudet commented Jan 15, 2021

get() should work for most use cases... Let me know if that's not enough though.

@saudet
Copy link
Member

saudet commented Jan 20, 2021

Ah, sorry about that, I was confusing this with OpenCV. So, it looks like we need to use the internal API to access the data. Something like this should work:

long value = new LongPointer(new PrimitiveScalarBase(s).data()).get();

saudet added a commit that referenced this issue Jan 20, 2021
@xuchen-plus
Copy link
Author

Ah, sorry about that, I was confusing this with OpenCV. So, it looks like we need to use the internal API to access the data. Something like this should work:

long value = new LongPointer(new PrimitiveScalarBase(s).data()).get();

Thanks, this works. And thank you for creating this great project!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants