apla / node-clickhouse

Yandex ClickHouse driver for nodejs
MIT License
216 stars 50 forks source link

anyLast returns string #21

Closed SudhakarSA closed 5 years ago

SudhakarSA commented 5 years ago

I have a field called duration which UInt64. If I pass select query with duration:anyLast, it returns string. Here I expect number instead of string. why does it happen?

nezed commented 5 years ago

Can you please provide more detailed example with code-snippet of your ch.query() calls?

SudhakarSA commented 5 years ago

I found the root cause. It seems that type UInt64 only has this issue(return string value instead of number). Query and Result as follows

Query:

SELECT anyLast(uptime) AS "uptime", anyLast(loadAvgFifteenMinute) AS "loadAvgFifteenMinute", 
anyLast(cpuUserPercentage) AS "cpuUserPercentage", anyLast(cpuCores) AS "cpuCores", 
anyLast(memoryUsedBytes) AS "memoryUsedBytes", anyLast(memoryFreeBytes) AS "memoryFreeBytes", 
hostname FROM system

Result:

{ rows:
   [ { 
       uptime: '4740000',
       loadAvgFifteenMinute: 0.17,
       cpuUserPercentage: 6.03,
       cpuCores: 1,
       memoryUsedBytes: '984068096',
       memoryFreeBytes: '1106239488',
       hostname: 'ubuntu'
} ],
  columns:
   [ { name: 'uptime', type: 'UInt64' },
     { name: 'loadAvgFifteenMinute', type: 'Float32' },
     { name: 'cpuUserPercentage', type: 'Float32' },
     { name: 'cpuCores', type: 'UInt8' },
     { name: 'memoryUsedBytes', type: 'UInt64' },
     { name: 'memoryFreeBytes', type: 'UInt64' },
     { name: 'hostname', type: 'String' } ] }

Look at uptime, memoryUsedBytes and memoryFreeBytes values. They are coming as string.

@nezed how to resolve this issue?

apla commented 5 years ago

You cannot use 64bit integers in Javascript directly. Only 52bits