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

Predicate Filtering #78

Closed
dorijan opened this issue Apr 2, 2019 · 5 comments · Fixed by #83
Closed

Predicate Filtering #78

dorijan opened this issue Apr 2, 2019 · 5 comments · Fixed by #83
Milestone

Comments

@dorijan
Copy link

dorijan commented Apr 2, 2019

Hi,
since ruby client does not support AGGREGATE query, and, it seems it will not in some time, it is necessary to implement Predicate Filtering so you could filter with more than one index
https://www.aerospike.com/docs/guide/predicate.html

Thank you
Dorijan

@jhecking
Copy link
Contributor

jhecking commented Apr 2, 2019

If you are blocked by this, would you be willing to consider taking a stab at implementing predicate filtering support and submitting a pull request? I could give you some pointers to get you started.

@lijeeshsd
Copy link

Yes, I really need this, so I am interested.

@jhecking
Copy link
Contributor

jhecking commented Apr 2, 2019

The Aerospike Ruby client is largely modeled after the Java client, so that would be the best reference: aerospike/aerospike-client-java@b6355f5

@dorijan
Copy link
Author

dorijan commented Apr 2, 2019

I am trying to understand, does Predicate expression filter uses same query method but predex is defined before execution? I mean this one
https://github.com/aerospike/aerospike-client-ruby/blob/master/lib/aerospike/query/query_command.rb

Or do we need to implement something like where and then predex filter would go as argument?

@jhecking
Copy link
Contributor

jhecking commented Apr 3, 2019

The interface for using predicate expressions would look something like this:

require 'aerospike'
include Aerospike
client = Client.new()

stmt = Statement.new("namespace", "set")
stmt.filters << Filter.Equal('bin1', 'foo')
stmt.predexp = [
  PredExp.stringBin('bin2'),
  PredExp.stringValue('bar'),
  PredExp.stringEqual(),
  PredExp.integerBin('bin3'),
  PredExp.integerValue(42),
  PredExp.integerGreater(),
  PredExp.and(2)
]

rs = client.query(stmt)
rs.each do |rec|
  puts rec
end

This example executes a query that uses the secondary index on "bin1" to find all records where "bin1" equals "foo". It then further narrows down the results to only return records that match the predicate expression "(bin2 == 'bar') && (bin3 > 42)". You use the same Client#query method to execute the query.

To implement this, you would have to create a new PredExp module/class, which is the public interface used to construct a predicate expression. You would also have to extend QueryCommand#write_buffer to serialize the predicate expression into the command buffer that's sent to the server.

The Java client code can be used as reference for both the pieces.

@jhecking jhecking added this to the v2.11.0 milestone May 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants