title: Wide rows in Cassandra using CQL - getting weird error
body: <p>I'm trying to store comments for a blog in Cassandra and have come up with this schema (got the idea from <a href="http://www.datastax.com/dev/blog/metric-collection-and-storage-with-cassandra" rel="nofollow noreferrer">here</a>):</p>
  
  <pre><code>create table comments ( slug varchar, ts timestamp, value text, primary key (slug,ts));
  </code></pre>
  
  <p>Using CQL (I'm using node.js with <a href="https://github.com/simplereach/helenus" rel="nofollow noreferrer">Helenus</a> driver) I'm trying to add some data to it, here's what I've got so far:</p>
  
  <pre><code>var helenus = require('helenus'),
      pool = new helenus.ConnectionPool({
          hosts: ['localhost:9160'],
          keyspace: 'blogks'
      });
  
  pool.on('error', function(err) {
      console.error(err.name, err.message);
  });
  
  
  
  module.exports.addComment = function(slug, comment,callback){
      pool.connect(function(connErr,keyspace){
          if(connErr){
              callback(connErr);
              return;
          }
  
          var cql = "INSERT INTO comments (slug,ts,value) VALUES (?, ?, ?);";
          pool.cql(cql,[slug,serializeDate(new Date()),serializeJSON(comment)],function(err,results){
              callback(err,results);
          });
      });
  }
  
  function serializeDate(date){
      var dateSerializer = new helenus.Marshal('DateType');
      return dateSerializer.serialize(date).toString('hex');
  }
  
  function serializeJSON(data){
      var utf8Serializer = new helenus.Marshal('UTF8Type');
      return utf8Serializer.serialize(JSON.stringify(data)).toString("hex");
  }
  </code></pre>
  
  <p>The idea being you can pass in a comment json object to this method, and push it to cassandra. I'm calling it like this to test:</p>
  
  <pre><code>var comments = require('./comments.js');
  
  comments.addComment("myslug",{id:2,name:"Alex",comment:"Hello!"},function(e,r){
      console.log(e);
      console.log(r);
  })
  </code></pre>
  
  <p>but whenever I do (I tried various CQL drivers), I get this cryptic error message:</p>
  
  <pre><code>[HelenusInvalidRequestException: unable to coerce 'value' to a  formatted date (long)] name: 'HelenusInvalidRequestException'
  </code></pre>
  
  <p>I tried changing the timestamp to be all different data types, but no luck. The very strange thing is that at first, my primary key was just the slug itself, and then it did work. However, I want to store all comments in one row ordered by timestamp, therefore I had to go with this approach of using two columns for the primary key. Any ideas?</p>
  
  <p><strong>EDIT</strong> So based on <a href="https://stackoverflow.com/a/14813741/15861">rs_atl's</a> suggestion, here's what I've tried: </p>
  
  <p>This line: </p>
  
  <pre><code>dateSerializer.serialize(date).toString('hex')
  </code></pre>
  
  <p>did in fact return garbage (0000013ccfacf5c4), I must have misunderstood how to use the API. So here's what I tried instead:</p>
  
  <p>I tried just <code>new Date().getTime()</code> which in JS does in fact return Unix-style epoch, but that didn't work I got the same error. I then tried using <a href="http://momentjs.com/" rel="nofollow noreferrer">moment.js</a> to try and format the string:</p>
  
  <pre><code>moment().format("YYYY-MM-DD HH:mm:ss")
  </code></pre>
  
  <p>which seems to be returning the correct format, but again. Same error. Then I tried this:</p>
  
  <pre><code>moment().format("YYYY-MM-DD HH:mm") + "Z"
  </code></pre>
  
  <p>no luck. I then tried this:</p>
  
  <pre><code>moment().format("YYYY-MM-DD HH:mmZ")
  </code></pre>
  
  <p>which does in fact add the timezone info at the end, but still, no luck. Any ideas?</p>