【问题标题】:Cassandra select query in C#C# 中的 Cassandra 选择查询
【发布时间】:2016-08-28 06:29:40
【问题描述】:

首先,我是 Cassandra 的新手,我确实阅读了手册并做了一些(基本)教程,了解如何设置它并使用 C# 与它通信。

我在按钮单击事件后面得到了一个选择查询。当我执行查询时,出现以下错误:

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

代码:

    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();
    }

注意*实际存在一行id为1、ConnectionMeterID为2的行。

这是数据库:

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));

为什么会出现这个错误?

编辑:堆栈跟踪

<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 你从哪一行得到异常?你刚刚执行了什么Select * from meters where ID = 1 AND ConnectionMeterID = 2?
  • @JeroenMostert 堆栈跟踪已添加。
  • @Neel 然后我得到一个不同的错误,告诉我我应该允许过滤。
  • 堆栈跟踪最终显示该错误与您的查询无关,因为我怀疑它不会有。您的某个 timestamp 列的内容有问题,或者库包含无法解析有效内容的错误。

标签: c# cassandra cql


【解决方案1】:

我猜这里的问题是您将它添加为 DateTime.Now.Ticks,它在 .NET 中是自 1900 年 1 月 1 日 00:00:00 以来的 100 纳秒间隔数。在 Cassandra、Java 和几乎所有其他东西中,这通常代表自 Unix 纪元 (1/1/1970 00:00:00) 以来的时间。在插入数据之前尝试将时间戳转换为 Unix 时间,看看是否会出现相同的错误。这是另一个 SO 问题的链接,向您展示如何进行转换:

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

【讨论】:

    猜你喜欢
    • 2015-05-22
    • 2016-05-18
    • 1970-01-01
    • 1970-01-01
    • 2017-03-12
    • 1970-01-01
    • 2019-03-09
    • 2017-12-05
    • 1970-01-01
    相关资源
    最近更新 更多