Not getting desired results using mapd-connector

Using queryAsync() of mapd-connector I’m trying to get the count of rows of a table but I am not getting the result.

Query: SELECT COUNT(*) AS n FROM flights_2008_7M LIMIT 1

Response: [{“n”:{“buffer”:{“type”:“Buffer”,“data”:[0,0,0,0,0,106,245,192]},“offset”:0}}]


due to javascript not having a true integer type (all numeric variables are 64-bit flt-pt), big integer values (which is the returned type for a COUNT(*) ) are stored as a special Thrift type backed by an ArrayBuffer. There are a couple of ways to convert this special Thrift type back to a javascript number. The easiest way:

const count_n = Number(results[0].n);

another way:

const count_n = results[0].n.valueOf()

The former is generally preferred as it would work universally for all returned numeric types (as long as the returned value can be represented by 64-bit floating pt)