1

first of all, I'm new to Cassandra and I did read manuals and did some (basic) tutorials about how to set it up and communicate with it with C#.

I got a select query behind a button click event. When I execute the query I get the following error:

An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in Cassandra.dll 
Additional information: Value to add was out of range.

the code:

    private void bt_select_Click(object sender, EventArgs e)
    {
        Connect();
        Row result = session.Execute("select * from meters where id = 1 AND ConnectionMeterID = 2 ALLOW FILTERING").First();
        CloseConnection();
    }

Note* There actually exists a row with id 1 and ConnectionMeterID 2.

And this is the database:

Create table meters (
ID       int,
ConnectionMeterID    int,
ConnectionMeterRevision     int,
PeriodStart  timestamp,
PeriodEnd    timestamp,
Volume1      float,Volume2       float,Volume3       float,
Volume4      float,Volume5       float,Volume6       float,
Volume7      float,Volume8       float,
DataTypeID   int,
FileID       int,
Remarks      text,
QualityScore  decimal,
LocationID   int,
Removed      int,
PRIMARY KEY (ID, ConnectionMeterID));

Why does that error occur?

EDIT: Stacktrace

<code> 'PloosCassandra.vshost.exe' (CLR v4.0.30319:  PloosCassandra.vshost.exe): Loaded  'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Numerics\v4.0_4.0.0.0__b77a5c5 61934e089\System.Numerics.dll'. Cannot find or open the PDB file.
A first chance exception of type 'System.ArgumentOutOfRangeException'   occurred in Cassandra.dll
System.ArgumentOutOfRangeException: Value to add was out of range.
Parameter name: value
   at System.DateTime.Add(Double value, Int32 scale)
   at System.DateTimeOffset.AddMilliseconds(Double milliseconds)
   at     Cassandra.Serialization.Primitive.DateTimeOffsetSerializer.Deserialize(Byte[]    buffer, Int32 offset)
   at   Cassandra.Serialization.Primitive.DateTimeOffsetSerializer.Deserialize(UInt16   protocolVersion, Byte[] buffer, Int32 offset, Int32 length, IColumnInfo typeInfo)
   at Cassandra.Serialization.TypeSerializer   1.Cassandra.Serialization.ITypeSerializer.Deserialize(UInt16 protocolVersion,   Byte[] buffer, Int32 offset, Int32 length, IColumnInfo typeInfo)
   at Cassandra.Serialization.Serializer.Deserialize(Byte[] buffer, Int32   offset, Int32 length, ColumnTypeCode typeCode, IColumnInfo typeInfo)
   at Cassandra.FrameReader.ReadFromBytes(Byte[] buffer, Int32 offset, Int32   length, ColumnTypeCode typeCode, IColumnInfo typeInfo)
   at Cassandra.OutputRows.ProcessRowItem(FrameReader reader)
   at Cassandra.OutputRows.ProcessRows(RowSet rs, FrameReader reader)
   at Cassandra.OutputRows..ctor(FrameReader reader, Nullable 1 traceId)
   at Cassandra.Responses.ResultResponse..ctor(Frame frame)
   at Cassandra.Responses.ResultResponse.Create(Frame frame)
   at Cassandra.FrameParser.Parse(Frame frame)
   at Cassandra.Connection.<>c__DisplayClasse.  <CreateResponseAction>b__d(MemoryStream stream)
   at Cassandra.Tasks.TaskHelper.WaitToComplete(Task task, Int32 timeout)
   at Cassandra.Tasks.TaskHelper.WaitToComplete[T](Task 1 task, Int32 timeout)
   at Cassandra.Session.Execute(IStatement statement)
   at Cassandra.Session.Execute(String cqlQuery)
   at PloosCassandra.Form1.bt_select_Click(Object sender, EventArgs e) in    c:\Users\rudi\Documents\Visual Studio     2013\Projects\PloosCassandra\PloosCassandra\Form1.cs:line 58
Proliges
  • 371
  • 4
  • 26
  • No exception is complete without a nice stack trace. Debug your application and have it break on exceptions thrown, rather than just unhandled exceptions. – Jeroen Mostert May 03 '16 at 09:29
  • @Proliges from which line you are getting exception?what is you just execute `Select * from meters where ID = 1 AND ConnectionMeterID = 2`? – Navoneel Talukdar May 03 '16 at 10:20
  • @JeroenMostert stacktrace added. – Proliges May 03 '16 at 10:32
  • @Neel Then I get a different error telling me I should allow filtering. – Proliges May 03 '16 at 10:33
  • The stack trace conclusively shows the error has nothing to do with your query, as I suspected it wouldn't have. There's something wrong with the contents of one of your `timestamp` columns somewhere, or the library contains a bug whereby it's unable to parse valid contents. – Jeroen Mostert May 03 '16 at 10:37
  • Note: the query is correct and works when I use it in command prompt. – Proliges May 03 '16 at 10:37
  • I agree with Jeroen.Most probably problem lies in `Connect();` – Navoneel Talukdar May 03 '16 at 10:42
  • @JeroenMostert I think you're right about the timestamp. I think its because I did a weird convertion of a `DateTime` because a `timestamp` is not a date. I add this into the database: `long timeStamp = System.DateTime.Now.Ticks;` – Proliges May 03 '16 at 10:47
  • That's not correct. Cassandra stores time in milliseconds since the epoch (1970-01-01). `DateTime.Ticks` is the number of 100 nanosecond intervals since 0001-01-01. That would explain the overflow. I'm not versed in Cassandra, but presumably there's a standard way to store timestamp values directly as `DateTime`, without having to convert them first. – Jeroen Mostert May 03 '16 at 11:00
  • @JeroenMostert you are right. Thanks for your help. I inserted is as a long into my database with a `DateTime.Now.Ticks` it should be added directly as a DateTime. then there is no problem. – Proliges May 03 '16 at 11:36

1 Answers1

2

I am going to guess that the problem here is that you added it as DateTime.Now.Ticks which in .NET is the number of 100 nanosecond intervals since 1/1/1900 00:00:00. In Cassandra, Java, and pretty much everything else this usually represents the time since the Unix epoch (1/1/1970 00:00:00). Trying converting your timestamp to Unix Time before inserting your data and see if you get the same error. Here is a link to another SO question showing you how to do the conversion:

How to convert a Unix timestamp to DateTime and vice versa?

Community
  • 1
  • 1
bechbd
  • 6,206
  • 3
  • 28
  • 47