Uploaded image for project: 'Apache Cassandra'
  1. Apache Cassandra
  2. CASSANDRA-7529

IN clause does not work correctly outside the QueryBuilder

    XMLWordPrintableJSON

Details

    • Critical

    Description

      There is a strange behaviour of the IN clause with lots of keys when used outside a QueryBuilder. Here is the test I did using the Java Driver 2.0.3 and Cassandra 2.0.7

      CREATE TABLE inlimit (
        key int,
        value text,
        PRIMARY KEY (key)
      ) 
      

      I've populated the table with 105000 entries (key from 0 to 104999).

      cqlsh:test> select count(*) from inlimit limit 200000;
      
       count
      --------
       105000
      

      Here the test:

      String query = "SELECT * FROM inlimit WHERE key IN :key";
      PreparedStatement ps = Cassandra.DB.getSession().prepare(query);
      BoundStatement bs = new BoundStatement(ps);
      List<Integer> l = new ArrayList<>();
      for (int i = 0; i < 100000; i++) {
          l.add(i);
      }
      bs.setList("key", l);
      ResultSet rs = Cassandra.DB.getSession().execute(bs);
      System.out.println("counted rows: " + rs.all().size());
      

      Here the output:

      counted rows: 34464

      While with QueryBuilder everything changes:

              List<Integer> l = new ArrayList<>();
              for (int i = 0; i < 100000; i++) {
                  l.add(i);
              }
              BuiltStatement bs = QueryBuilder.select().all().from("inlimit").where(in("key", l.toArray()));
              ResultSet rs = Cassandra.DB.getSession().execute(bs);
              System.out.println("counted rows: " + rs.all().size());
      

      The new output

      counted rows: 100000

      BTW: I'd suggest to write somewhere if the IN clause has some limitations cause I found this question without answer in many forums.

      Cheers,
      Carlo

      Attachments

        Activity

          People

            Unassigned Unassigned
            kaisersose Carlo Bertuccini
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: