find(Criteria) problem

18 views
Skip to first unread message

Curtis Stanford

unread,
Oct 3, 2015, 10:59:38 PM10/3/15
to Concourse Developers
I'm wondering if I'm doing this right. I have code like this (excuse my Scala code, should be pretty easy to read):

val criteria = Criteria.where()
        .key("persistence_id").operator(Operator.EQUALS).value(persistenceId)
        .and()
        .key("sequence").operator(Operator.BETWEEN).value(1L).value(toSequenceNr)
        .build()
con.find(criteria)

This finds records matching the first condition but not the second. I have to use the following code instead:

con.find("persistence_id", Operator.EQUALS, persistenceId).foreach(id ⇒ {
        val seq = con.get[Long]("sequence", id)
        if (seq >= 1L && seq <= toSequenceNr) // do something here
      })

Am I using the Criteria class correctly? What about the BETWEEN operator? Not sure why it's not working.

Curtis

Jeff Nelson

unread,
Oct 3, 2015, 11:04:25 PM10/3/15
to concour...@googlegroups.com
Which version are you using?

One weird quirk of the BETWEEN operator (because of legacy reasons) is that its inclusive of the lower value in the range, but exclusive of the upper value (e.g >= lower, < upper). If you bump query for toSequenceNr +1, does that yield the result you're looking for?


JEFF NELSON
Founder & CEO | Cinchapi Inc.

Follow us on Twitter | Github | AngelList


--
You received this message because you are subscribed to the Google Groups "Concourse Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to concourse-dev...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Curtis Stanford

unread,
Oct 5, 2015, 12:16:56 AM10/5/15
to Concourse Developers
No, that's not the problem. I don't get any values in the range at all. I have another criteria example that uses EQUALS for the sequenceNr instead of BETWEEN and that doesn't work either. 

I'm using 0.4.4 ? The latest release on github.

Jeff Nelson

unread,
Oct 5, 2015, 6:37:14 AM10/5/15
to concour...@googlegroups.com
Can you send me an example of the data you're storing?


JEFF NELSON
Founder & CEO | Cinchapi Inc.

Follow us on Twitter | Github | AngelList


Curtis Stanford

unread,
Oct 5, 2015, 11:28:59 AM10/5/15
to Concourse Developers
Here's the code for saving a record (is that what you call them)? It's a very simple record saving 3 things for akka persistence. "con" is the Concourse object.

        val id = con.create()
      con.set("persistence_id", Tag.create(message.persistenceId), id)
      con.set("sequence", message.sequenceNr, id)
      val b64 = Base64.getEncoder.encodeToString(bytes)
      con.set("payload", b64, id)

Then, I try to obtain records with a matching persistence_id and a range of sequence numbers as I mentioned before:

      val criteria = Criteria.where()
        .key("persistence_id").operator(Operator.EQUALS).value(persistenceId)
        .and()
        .key("sequence").operator(Operator.BETWEEN).value(1L).value(toSequenceNr)
        .build()
      con.find(criteria).foreach(con.clear(_))

My only thought is maybe the Scala types are screwing it up some how.

Curtis

Jeff Nelson

unread,
Oct 5, 2015, 11:41:58 AM10/5/15
to concour...@googlegroups.com
Assuming you haven't stored any sensitive data, can you send me a dump of your instance.

From the concourse-server installation directory

$ cd bin
$ ./dumptool -i BUFFER

You should see output like the following printed to stdout

Dump for Page /Users/jnelson/demo/concourse/buffer/default/1438276977237000.buf
------
ADD name AS jeff (STRING) IN 1438276977236003 AT 1438276977236005
ADD name AS jeff (STRING) IN 1438276977238000 AT 1438276977238002
ADD name AS jeff (STRING) IN 1438276977238003 AT 1438276977238005
ADD name AS jeff (STRING) IN 1438276977239000 AT 1438276977245000

That'll help me determine if the data types are being translated from Scala correctly and also will help me see if I can reproduce the error on my side.


JEFF NELSON
Founder & CEO | Cinchapi Inc.

Follow us on Twitter | Github | AngelList


--
You received this message because you are subscribed to the Google Groups "Concourse Developers" group.

Curtis Stanford

unread,
Oct 5, 2015, 11:59:16 AM10/5/15
to Concourse Developers
I'll just post it here. It's just running the akka test suite.
jj

Curtis Stanford

unread,
Oct 5, 2015, 12:15:26 PM10/5/15
to Concourse Developers
I've been looking at this a bit more and the BETWEEN operator actually does work. It's the EQUALS that doesn't seem to work. The long2Long just converts a scala long to a java long.

          val criteria = Criteria.where()
            .key("persistence_id").operator(Operator.EQUALS).value(persistenceId)
            .and()
            .key("sequence").operator(Operator.EQUALS).value(long2Long(seq))
            .build()


On Monday, October 5, 2015 at 9:41:58 AM UTC-6, Jeff Nelson wrote:

Jeff Nelson

unread,
Oct 5, 2015, 6:38:27 PM10/5/15
to concour...@googlegroups.com
Hey Curtis,

Can you run this code snippet and tell me if it works for you:

import org.cinchapi.concourse.Concourse;
import org.cinchapi.concourse.Tag;
import org.cinchapi.concourse.lang.Criteria;
import org.cinchapi.concourse.thrift.Operator;

object Scratch {
  def main(args: Array[String]) {
    val con = Concourse.connect();
    con.set("persistence_id", Tag.create("p-9"), 1);
    println(con.find(Criteria.where().key("persistence_id").operator(Operator.EQUALS).value("p-9")));
  }
}


JEFF NELSON
Founder & CEO | Cinchapi Inc.

Follow us on Twitter | Github | AngelList


Curtis Stanford

unread,
Oct 5, 2015, 6:50:39 PM10/5/15
to Concourse Developers
Yes, it works. If I start with an empty database, I get [1] back.

Jeff Nelson

unread,
Oct 5, 2015, 6:57:52 PM10/5/15
to concour...@googlegroups.com
Earlier you said you determined that the query was failing with the EQUALS clause. Does the code snippet I sent reproduce what your code is essentially doing?

When you write the data, you do
con.set("persistence_id", Tag.create(message.persistenceId), id)

and when you query you do
Criteria.where()
        .key("persistence_id").operator(Operator.EQUALS).value(persistenceId)

Is the persistenceId variable used in the query a String or Tag?


JEFF NELSON
Founder & CEO | Cinchapi Inc.

Follow us on Twitter | Github | AngelList


Curtis Stanford

unread,
Oct 5, 2015, 7:06:07 PM10/5/15
to Concourse Developers
Hi Jeff, try this code. It's in Java, to eliminate any Scala weirdness.

import org.cinchapi.concourse.Concourse;
import org.cinchapi.concourse.lang.Criteria;
import org.cinchapi.concourse.thrift.Operator;

public class Scratch2 {
public static void main(String[] args) {
Concourse con = Concourse.connect();
con.set("sequence", 1L, 1);
System.err.println(con.find(Criteria.where().key("sequence").operator(Operator.EQUALS).value(1L))); // no worky
System.err.println(con.find(Criteria.where().key("sequence").operator(Operator.BETWEEN).value(1L).value(1L))); // no worky
System.err.println(con.find(Criteria.where().key("sequence").operator(Operator.BETWEEN).value(1L).value(2L))); // works!!
}
}

Output is:

[]
[]
[1]

Also, it works if I take out all of the "L"s and just use ints

Curtis

Curtis Stanford

unread,
Oct 5, 2015, 7:06:55 PM10/5/15
to Concourse Developers
The problem is not with strings but with Longs. See my last message.

Jeff Nelson

unread,
Oct 5, 2015, 7:31:08 PM10/5/15
to concour...@googlegroups.com
Ahh you found a bug, but I know how to fix it. I'll get a fix committed and send you a snapshot with the update that you can use.


JEFF NELSON
Founder & CEO | Cinchapi Inc.

Follow us on Twitter | Github | AngelList


Reply all
Reply to author
Forward
0 new messages