jorgebay / node-cassandra-cql

Node.js driver for Apache Cassandra
MIT License
144 stars 45 forks source link

Inet data types decoding #61

Open guice opened 10 years ago

guice commented 10 years ago

Now that I have selecting working, I found inet column types aren't being decoded:

 sid  | visit_dt                 | aid | browser | cid  | ip              | referrer | terms
------+--------------------------+-----+---------+------+-----------------+----------+-------
 7479 | 2010-04-01 10:31:53-0700 |  -1 |         | 4983 | 117.195.200.117 |          |

Return data:

{ 
  sid: '7479',
  visit_dt: Thu Apr 01 2010 10:31:53 GMT-0700 (PDT),
  aid: -1,
  browser: '',
  cid: '4983',
  ip: <Buffer 75 c3 c8 75>, // <-- Here
  referrer: '',
  terms: '' }

However, accessing each octet individually works:

[r.ip[0], r.ip[1], r.ip[2],r.ip[3]].join('.');

// returns: 117.195.200.117
jorgebay commented 10 years ago

It's intentional, I think an unsigned array of integers (bytes) is the most effective way to represent an IPv4 and IPv6 address.

If you would like, I could change the name of the issue and open it for discussion to see what other people think...

guice commented 10 years ago

Sure. I think a large part of the issue is more a compatibility thing. Everything takes an IP as a string when handling. Having this come back as an array of the hex/octet values is a little "raw" per-say. People would expect to see the IP, as they do when you run a select via cqlsh.