memsql / dbbench

Database Benchmark Tool
Apache License 2.0
156 stars 32 forks source link

Recommend using COALESCE if query outputs NULLs. #7

Closed PeterFaiman closed 7 years ago

PeterFaiman commented 7 years ago

Partially addresses issue #6.

Test:

CREATE TABLE test(s VARCHAR(64)); INSERT INTO test(s) VALUES ('test'), (NULL), ('test');

without COALESCE test.ini:

[test] query=SELECT s FROM test query-results-file=/tmp/test.csv count=1

result:

2017/07/26 09:47:58 Connected 2017/07/26 09:47:58 starting test 2017/07/26 09:47:58 error for query SELECT s FROM test in test: sql: Scan error on column index 0: unsupported Scan, storing driver.Value type into type *string, NULL cannot be uniquely encoded as a CSV value, consider using the SQL function COALESCE to convert NULLs to some default value

with COALESCE test.ini:

[test] query=SELECT COALESCE(s, 'NULL') FROM test query-results-file=/tmp/test.csv count=1

result:

2017/07/26 09:47:36 Connected 2017/07/26 09:47:36 starting test 2017/07/26 09:47:36 stopping test 2017/07/26 09:47:36 test: latency 845.736µs±0s; 1 transactions (1182.402 TPS); 3 rows (3547.206 RPS)

awreece commented 7 years ago

LGTM

I'm uneasy about the string matching for error, but since that's our only option let's just leave a passive aggressive comment and move on

PeterFaiman commented 7 years ago

I updated the commit message to clarify behavior, it now reads:

Recommend COALESCE on error writing NULL to CSV.

This error only occurs when saving values to a query-results-file CSV. This makes the error message clarify the limitation of writing NULLs to CSV files, rather than just displaying a cryptic error about casting.

...