0

I am trying to run the query form my local machine using console as below

select state from table limit 10 ALLOW FILTERING;

it's giving me the output.

But when I am trying it form console application I am not getting any result.
Below is the code

  //Create a cluster instance using 3 cassandra nodes.
   var cluster = Cluster.Builder()
   .AddContactPoints("xx.xx.xx.xx")
   .Build();
    var session = cluster.Connect("keyspace");
    var rs = session.Execute("select state from table limit 10 ALLOW FILTERING");
    foreach (var row in rs)
    {
        var value = row.GetValue<string>("state");
    }

Ref: https://docs.datastax.com/en/developer/csharp-driver/3.2/
I am not getting any error as well. I am using "CassandraCSharpDriver"
https://www.nuget.org/packages/CassandraCSharpDriver/

शेखर
  • 17,412
  • 13
  • 61
  • 117
  • 1
    Is that code exactly the one you're using? I'm asking this because the result set returned by session.Execute() does not support multiple enumerations so if you have any LINQ call on the rs variable before the foreach statement, it may cause the foreach to iterate through an empty enumerable. – João Reis Aug 25 '20 at 09:20
  • @JoãoReis only difference is the table name, keyspace and ip nothing else. – शेखर Aug 25 '20 at 09:28
  • 2
    What are you doing with the value (var value = row.GetValue("state");)? I don't see any instruction. It is not related with your problem, but you should not use ALLOW FILTERING – Saifallah KETBI Aug 25 '20 at 11:08
  • @SaifallahKETBI the code is not going inside loop because the query does not returning any data. – शेखर Aug 25 '20 at 12:11
  • Can you try adding a ToList(), i.e., var rs = session.Execute("select state from table limit 10 ALLOW FILTERING").ToList(); and printing rs.Count to the console or log file? And also try something like var count = session.Execute("select count(*) from table").Single().GetValue(0) and print this result. – João Reis Aug 25 '20 at 13:26
  • @JoãoReis I have tried the same but count is 0. – शेखर Aug 26 '20 at 05:42

1 Answers1

0

I found the solution the issue is with the driver version. I was using the latest version which is the default.
I downgraded to 3.11.0 and started working.

My server version is [cqlsh 5.0.1 | Cassandra 3.11.4 | CQL spec 3.4.4 | Native protocol v4]

शेखर
  • 17,412
  • 13
  • 61
  • 117
  • There has to be something else going on, maybe you have contact points of different clusters? If the select count(*) is returning 0 then the server itself is returning that count not the driver. You should enable the driver logs and see the IPs that the driver is connecting to. – João Reis Aug 26 '20 at 12:44
  • @JoãoReis it was strange behavior when I run the command to check connection on server on port it was showing my IP. `netstat -ant | grep ":9042"`. I only downgraded the the nuget package nothing else. – शेखर Aug 26 '20 at 13:46
  • Well in the future if you run into the same issue you should enable the driver logs ( https://docs.datastax.com/en/developer/csharp-driver/3.15/faq/#how-can-i-enable-logging-in-the-driver ) and double check the IPs that the driver is connecting to. If you run the same query in cqlsh against a specific node and it gives different results then the driver is not contacting to that node (or that cluster) because the driver doesn't modify the query or the result at any point. – João Reis Aug 26 '20 at 18:20