[ 
https://issues.apache.org/jira/browse/CASSJAVA-101?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Michael Dinzinger updated CASSJAVA-101:
---------------------------------------
    Description: 
Hello, I noticed the following serious problem, for which I need help. I cannot 
get my head around this behaviour. This is my code:
{code:java}
@Test
public void testCqlSelect() {
        Instant instant = Instant.now();        SimpleStatement stmt1 = 
SimpleStatement
            .newInstance("SELECT * FROM urlfrontier_202504.urlitems "
                   + "WHERE queue_id = ? AND partition_key = ? "
                   + "AND next_fetch_date <= ?",
                     "DEFAULT",
                     "6d",
                     instant);        List<Row> rows1 = 
session.execute(stmt1).all();
        System.out.println("Total rows 1 = " + rows1.size());        
SimpleStatement stmt2 = SimpleStatement
            .newInstance("SELECT * FROM urlfrontier_202504.urlitems "
                   + "WHERE queue_id = ? AND partition_key = ? "
                   + "AND next_fetch_date <= ? AND next_fetch_date >= ?",
                     "DEFAULT",
                     "6d",
                     instant, instant.minusSeconds(60 * 60 * 24 * 8));        
List<Row> rows2 = session.execute(stmt2).all();
        System.out.println("Total rows 2 = " + rows2.size());        
SimpleStatement stmt3 = SimpleStatement
            .newInstance("SELECT COUNT(*) FROM urlfrontier_202504.urlitems "
                   + "WHERE queue_id = ? AND partition_key = ? "
                   + "AND next_fetch_date <= ?",
                     "DEFAULT",
                     "6d",
                     instant);        Row row3 = session.execute(stmt3).one();
        long total = row3.getLong(0);
        System.out.println("Total rows 3 = " + total);
} {code}
 

Output:

Total rows 1 = 0
Total rows 2 = 184827
Total rows 3 = 184827

There shouldn't be a difference between these three SELECTs. And weirdly, when 
running these SELECT commands in the cqlsh, it works as expected. Moreover, the 
second SELECT (so adding a lower bound timestamp, which magically fixes the 
bug) does only work for certain lower bounds, e.g. for instant.minusSeconds(60 
* 60 * 24 * 1_000) it does not work and I get 0, as in the first SELECT. I use 
the latest ScyllaDB version 2025.1.2-0.20250422.502c62d91d48.

These are the definitions of the keyspace and the table in my one-node cluster, 
local ScyllaDB instance.
```
CREATE KEYSPACE IF NOT EXISTS %s
WITH replication = \{'class' : 'SimpleStrategy', 'replication_factor' : 1};

CREATE TABLE IF NOT EXISTS %s.%s (
queue_id ascii,
partition_key ascii,
next_fetch_date timestamp,
url_id ascii,
url text,
url_path frozen\<list<text>>,
fetch_error_count tinyint,
signature ascii,
fetch_interval int,
last_modified text,
etag text,
tags set<ascii>,
PRIMARY KEY ((queue_id, partition_key), next_fetch_date, url_id)
);
```

This is the pom.xml:
```
        <dependencies>
                <dependency>
                        <groupId>org.apache.cassandra</groupId>
                        <artifactId>java-driver-core</artifactId>
                        <version>4.19.0</version>
                </dependency>
                <dependency>
                        <groupId>org.apache.cassandra</groupId>
                        <artifactId>java-driver-query-builder</artifactId>
                        <version>4.19.0</version>
                </dependency>
        </dependencies>
```

I tried adding \{{`.setPageSize(0)` }}to the first SELECT statement, but this 
does not change anything.

  was:
Hello, I noticed the following serious problem, for which I need help. I cannot 
get my head around this behaviour. This is my code:
```
@Test
public void testCqlSelect() {
        Instant instant = Instant.now();

        SimpleStatement stmt1 = SimpleStatement
            .newInstance("SELECT * FROM urlfrontier_202504.urlitems "
                   + "WHERE queue_id = ? AND partition_key = ? "
                   + "AND next_fetch_date <= ?",
                     "DEFAULT",
                     "6d",
                     instant);

        List<Row> rows1 = session.execute(stmt1).all();
        System.out.println("Total rows 1 = " + rows1.size());

        SimpleStatement stmt2 = SimpleStatement
            .newInstance("SELECT * FROM urlfrontier_202504.urlitems "
                   + "WHERE queue_id = ? AND partition_key = ? "
                   + "AND next_fetch_date <= ? AND next_fetch_date >= ?",
                     "DEFAULT",
                     "6d",
                     instant, instant.minusSeconds(60 * 60 * 24 * 8));

        List<Row> rows2 = session.execute(stmt2).all();
        System.out.println("Total rows 2 = " + rows2.size());

        SimpleStatement stmt3 = SimpleStatement
            .newInstance("SELECT COUNT(*) FROM urlfrontier_202504.urlitems "
                   + "WHERE queue_id = ? AND partition_key = ? "
                   + "AND next_fetch_date <= ?",
                     "DEFAULT",
                     "6d",
                     instant);

        Row row3 = session.execute(stmt3).one();
        long total = row3.getLong(0);
        System.out.println("Total rows 3 = " + total);
}
```

Output:

Total rows 1 = 0
Total rows 2 = 184827
Total rows 3 = 184827

There shouldn't be a difference between these three SELECTs. And weirdly, when 
running these SELECT commands in the cqlsh, it works as expected. Moreover, the 
second SELECT (so adding a lower bound timestamp, which magically fixes the 
bug) does only work for certain lower bounds, e.g. for instant.minusSeconds(60 
* 60 * 24 * 1_000) it does not work and I get 0, as in the first SELECT. I use 
the latest ScyllaDB version 2025.1.2-0.20250422.502c62d91d48.

These are the definitions of the keyspace and the table in my one-node cluster, 
local ScyllaDB instance.
```
CREATE KEYSPACE IF NOT EXISTS %s
WITH replication = \{'class' : 'SimpleStrategy', 'replication\_factor' : 1};

CREATE TABLE IF NOT EXISTS %s.%s (
queue\_id ascii,
partition\_key ascii,
next\_fetch\_date timestamp,
url\_id ascii,
url text,
url\_path frozen\<list<text>>,
fetch\_error\_count tinyint,
signature ascii,
fetch\_interval int,
last\_modified text,
etag text,
tags set<ascii>,
PRIMARY KEY ((queue\_id, partition\_key), next\_fetch\_date, url\_id)
);
```

This is the pom.xml:
```
        <dependencies>
                <dependency>
                        <groupId>org.apache.cassandra</groupId>
                        <artifactId>java-driver-core</artifactId>
                        <version>4.19.0</version>
                </dependency>
                <dependency>
                        <groupId>org.apache.cassandra</groupId>
                        <artifactId>java-driver-query-builder</artifactId>
                        <version>4.19.0</version>
                </dependency>
        </dependencies>
```

I tried adding {{`.setPageSize(0)` }}to the first SELECT statement, but this 
does not change anything.


> Select * shows too few results, while Select Count(*) works
> -----------------------------------------------------------
>
>                 Key: CASSJAVA-101
>                 URL: https://issues.apache.org/jira/browse/CASSJAVA-101
>             Project: Apache Cassandra Java driver
>          Issue Type: Bug
>          Components: Core
>            Reporter: Michael Dinzinger
>            Priority: Normal
>
> Hello, I noticed the following serious problem, for which I need help. I 
> cannot get my head around this behaviour. This is my code:
> {code:java}
> @Test
> public void testCqlSelect() {
>         Instant instant = Instant.now();        SimpleStatement stmt1 = 
> SimpleStatement
>             .newInstance("SELECT * FROM urlfrontier_202504.urlitems "
>                    + "WHERE queue_id = ? AND partition_key = ? "
>                    + "AND next_fetch_date <= ?",
>                      "DEFAULT",
>                      "6d",
>                      instant);        List<Row> rows1 = 
> session.execute(stmt1).all();
>         System.out.println("Total rows 1 = " + rows1.size());        
> SimpleStatement stmt2 = SimpleStatement
>             .newInstance("SELECT * FROM urlfrontier_202504.urlitems "
>                    + "WHERE queue_id = ? AND partition_key = ? "
>                    + "AND next_fetch_date <= ? AND next_fetch_date >= ?",
>                      "DEFAULT",
>                      "6d",
>                      instant, instant.minusSeconds(60 * 60 * 24 * 8));        
> List<Row> rows2 = session.execute(stmt2).all();
>         System.out.println("Total rows 2 = " + rows2.size());        
> SimpleStatement stmt3 = SimpleStatement
>             .newInstance("SELECT COUNT(*) FROM urlfrontier_202504.urlitems "
>                    + "WHERE queue_id = ? AND partition_key = ? "
>                    + "AND next_fetch_date <= ?",
>                      "DEFAULT",
>                      "6d",
>                      instant);        Row row3 = session.execute(stmt3).one();
>         long total = row3.getLong(0);
>         System.out.println("Total rows 3 = " + total);
> } {code}
>  
> Output:
> Total rows 1 = 0
> Total rows 2 = 184827
> Total rows 3 = 184827
> There shouldn't be a difference between these three SELECTs. And weirdly, 
> when running these SELECT commands in the cqlsh, it works as expected. 
> Moreover, the second SELECT (so adding a lower bound timestamp, which 
> magically fixes the bug) does only work for certain lower bounds, e.g. for 
> instant.minusSeconds(60 * 60 * 24 * 1_000) it does not work and I get 0, as 
> in the first SELECT. I use the latest ScyllaDB version 
> 2025.1.2-0.20250422.502c62d91d48.
> These are the definitions of the keyspace and the table in my one-node 
> cluster, local ScyllaDB instance.
> ```
> CREATE KEYSPACE IF NOT EXISTS %s
> WITH replication = \{'class' : 'SimpleStrategy', 'replication_factor' : 1};
> CREATE TABLE IF NOT EXISTS %s.%s (
> queue_id ascii,
> partition_key ascii,
> next_fetch_date timestamp,
> url_id ascii,
> url text,
> url_path frozen\<list<text>>,
> fetch_error_count tinyint,
> signature ascii,
> fetch_interval int,
> last_modified text,
> etag text,
> tags set<ascii>,
> PRIMARY KEY ((queue_id, partition_key), next_fetch_date, url_id)
> );
> ```
> This is the pom.xml:
> ```
>         <dependencies>
>                 <dependency>
>                         <groupId>org.apache.cassandra</groupId>
>                         <artifactId>java-driver-core</artifactId>
>                         <version>4.19.0</version>
>                 </dependency>
>                 <dependency>
>                         <groupId>org.apache.cassandra</groupId>
>                         <artifactId>java-driver-query-builder</artifactId>
>                         <version>4.19.0</version>
>                 </dependency>
>         </dependencies>
> ```
> I tried adding \{{`.setPageSize(0)` }}to the first SELECT statement, but this 
> does not change anything.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org
For additional commands, e-mail: commits-h...@cassandra.apache.org

Reply via email to