Skip to content

Commit 237e847

Browse files
authored
chore(ci): add test for null values (#627)
1 parent 8ec9c36 commit 237e847

File tree

12 files changed

+134
-151
lines changed

12 files changed

+134
-151
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ prompt = ":) "
165165
| `expand` | Expand table format display, default auto, could be on/off/auto. |
166166
| `time` | Whether to show the time elapsed when executing queries. |
167167
| `multi_line` | Whether to allow multi-line input. |
168-
| `replace_newline` | whether replace '\n' with '\\\n'. |
168+
| `quote_string` | Whether to quote string values in table output format. |
169169

170170
## Commands in REPL
171171

bindings/nodejs/tests/binding.js

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -270,59 +270,61 @@ When("Create a test table", async function () {
270270

271271
Then("Insert and Select should be equal", async function () {
272272
await this.conn.exec(`INSERT INTO test VALUES
273-
(-1, 1, 1.0, '1', '1', '2011-03-06', '2011-03-06 06:20:00'),
274-
(-2, 2, 2.0, '2', '2', '2012-05-31', '2012-05-31 11:20:00'),
275-
(-3, 3, 3.0, '3', '2', '2016-04-04', '2016-04-04 11:30:00')`);
273+
(-1, 1, 1.0, '\\'', NULL, '2011-03-06', '2011-03-06 06:20:00'),
274+
(-2, 2, 2.0, '"', '', '2012-05-31', '2012-05-31 11:20:00'),
275+
(-3, 3, 3.0, '\\\\', 'NULL', '2016-04-04', '2016-04-04 11:30:00')`);
276276
const rows = await this.conn.queryIter("SELECT * FROM test");
277277
const ret = [];
278278
for await (const row of rows) {
279279
ret.push(row.values());
280280
}
281281
const expected = [
282-
[-1, 1, 1.0, "1", "1", new Date("2011-03-06"), new Date("2011-03-06T06:20:00Z")],
283-
[-2, 2, 2.0, "2", "2", new Date("2012-05-31"), new Date("2012-05-31T11:20:00Z")],
284-
[-3, 3, 3.0, "3", "2", new Date("2016-04-04"), new Date("2016-04-04T11:30:00Z")],
282+
[-1, 1, 1.0, "'", null, new Date("2011-03-06"), new Date("2011-03-06T06:20:00Z")],
283+
[-2, 2, 2.0, '"', "", new Date("2012-05-31"), new Date("2012-05-31T11:20:00Z")],
284+
[-3, 3, 3.0, "\\", "NULL", new Date("2016-04-04"), new Date("2016-04-04T11:30:00Z")],
285285
];
286286
assert.deepEqual(ret, expected);
287287
});
288288

289289
Then("Stream load and Select should be equal", async function () {
290290
const values = [
291-
["-1", "1", "1.0", "1", "1", "2011-03-06", "2011-03-06T06:20:00Z"],
292-
["-2", "2", "2.0", "2", "2", "2012-05-31", "2012-05-31T11:20:00Z"],
293-
["-3", "3", "3.0", "3", "2", "2016-04-04", "2016-04-04T11:30:00Z"],
291+
["-1", "1", "1.0", "'", "\\N", "2011-03-06", "2011-03-06T06:20:00Z"],
292+
["-2", "2", "2.0", '"', "", "2012-05-31", "2012-05-31T11:20:00Z"],
293+
["-3", "3", "3.0", "\\", "NULL", "2016-04-04", "2016-04-04T11:30:00Z"],
294294
];
295295
const progress = await this.conn.streamLoad(`INSERT INTO test VALUES`, values);
296296
assert.equal(progress.writeRows, 3);
297-
assert.equal(progress.writeBytes, 193);
297+
assert.equal(progress.writeBytes, 194);
298298

299299
const rows = await this.conn.queryIter("SELECT * FROM test");
300300
const ret = [];
301301
for await (const row of rows) {
302302
ret.push(row.values());
303303
}
304304
const expected = [
305-
[-1, 1, 1.0, "1", "1", new Date("2011-03-06"), new Date("2011-03-06T06:20:00Z")],
306-
[-2, 2, 2.0, "2", "2", new Date("2012-05-31"), new Date("2012-05-31T11:20:00Z")],
307-
[-3, 3, 3.0, "3", "2", new Date("2016-04-04"), new Date("2016-04-04T11:30:00Z")],
305+
[-1, 1, 1.0, "'", null, new Date("2011-03-06"), new Date("2011-03-06T06:20:00Z")],
306+
[-2, 2, 2.0, '"', null, new Date("2012-05-31"), new Date("2012-05-31T11:20:00Z")],
307+
[-3, 3, 3.0, "\\", "NULL", new Date("2016-04-04"), new Date("2016-04-04T11:30:00Z")],
308308
];
309309
assert.deepEqual(ret, expected);
310310
});
311311

312312
Then("Load file and Select should be equal", async function () {
313-
const progress = await this.conn.loadFile(`INSERT INTO test VALUES`, "tests/data/test.csv", { type: "CSV" });
313+
const progress = await this.conn.loadFile(`INSERT INTO test VALUES`, "tests/data/test.csv", {
314+
type: "CSV",
315+
});
314316
assert.equal(progress.writeRows, 3);
315-
assert.equal(progress.writeBytes, 193);
317+
assert.equal(progress.writeBytes, 194);
316318

317319
const rows = await this.conn.queryIter("SELECT * FROM test");
318320
const ret = [];
319321
for await (const row of rows) {
320322
ret.push(row.values());
321323
}
322324
const expected = [
323-
[-1, 1, 1.0, "1", "1", new Date("2011-03-06"), new Date("2011-03-06T06:20:00Z")],
324-
[-2, 2, 2.0, "2", "2", new Date("2012-05-31"), new Date("2012-05-31T11:20:00Z")],
325-
[-3, 3, 3.0, "3", "2", new Date("2016-04-04"), new Date("2016-04-04T11:30:00Z")],
325+
[-1, 1, 1.0, "'", null, new Date("2011-03-06"), new Date("2011-03-06T06:20:00Z")],
326+
[-2, 2, 2.0, '"', null, new Date("2012-05-31"), new Date("2012-05-31T11:20:00Z")],
327+
[-3, 3, 3.0, "\\", "NULL", new Date("2016-04-04"), new Date("2016-04-04T11:30:00Z")],
326328
];
327329
assert.deepEqual(ret, expected);
328330
});

bindings/python/src/blocking.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,9 @@ fn format_csv(parameters: Vec<Bound<'_, PyAny>>) -> PyResult<Vec<u8>> {
420420
}
421421

422422
fn to_csv_field(v: Bound<PyAny>) -> PyResult<String> {
423+
if v.is_none() {
424+
return Ok("".to_string());
425+
}
423426
match v.downcast::<PyAny>() {
424427
Ok(v) => {
425428
if let Ok(v) = v.extract::<String>() {

bindings/python/tests/asyncio/steps/binding.py

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,7 @@ async def _(context):
126126
@async_run_until_complete
127127
async def _(context):
128128
rows = await context.conn.query_iter("SELECT number FROM numbers(5)")
129-
ret = []
130-
async for row in rows:
131-
ret.append(row.values()[0])
129+
ret = [row.values()[0] for row in rows]
132130
expected = [0, 1, 2, 3, 4]
133131
assert ret == expected, f"ret: {ret}"
134132

@@ -137,21 +135,19 @@ async def _(context):
137135
@async_run_until_complete
138136
async def _(context):
139137
await context.conn.exec(
140-
"""
138+
r"""
141139
INSERT INTO test VALUES
142-
(-1, 1, 1.0, '1', '1', '2011-03-06', '2011-03-06 06:20:00'),
143-
(-2, 2, 2.0, '2', '2', '2012-05-31', '2012-05-31 11:20:00'),
144-
(-3, 3, 3.0, '3', '2', '2016-04-04', '2016-04-04 11:30:00')
140+
(-1, 1, 1.0, '\'', NULL, '2011-03-06', '2011-03-06 06:20:00'),
141+
(-2, 2, 2.0, '"', '', '2012-05-31', '2012-05-31 11:20:00'),
142+
(-3, 3, 3.0, '\\', 'NULL', '2016-04-04', '2016-04-04 11:30:00')
145143
"""
146144
)
147145
rows = await context.conn.query_iter("SELECT * FROM test")
148-
ret = []
149-
async for row in rows:
150-
ret.append(row.values())
146+
ret = [row.values() for row in rows]
151147
expected = [
152-
(-1, 1, 1.0, "1", "1", date(2011, 3, 6), datetime(2011, 3, 6, 6, 20)),
153-
(-2, 2, 2.0, "2", "2", date(2012, 5, 31), datetime(2012, 5, 31, 11, 20)),
154-
(-3, 3, 3.0, "3", "2", date(2016, 4, 4), datetime(2016, 4, 4, 11, 30)),
148+
(-1, 1, 1.0, "'", None, date(2011, 3, 6), datetime(2011, 3, 6, 6, 20)),
149+
(-2, 2, 2.0, '"', "", date(2012, 5, 31), datetime(2012, 5, 31, 11, 20)),
150+
(-3, 3, 3.0, "\\", "NULL", date(2016, 4, 4), datetime(2016, 4, 4, 11, 30)),
155151
]
156152
assert ret == expected, f"ret: {ret}"
157153

@@ -160,42 +156,40 @@ async def _(context):
160156
@async_run_until_complete
161157
async def _(context):
162158
values = [
163-
["-1", "1", "1.0", "1", "1", "2011-03-06", "2011-03-06T06:20:00Z"],
164-
["-2", "2", "2.0", "2", "2", "2012-05-31", "2012-05-31T11:20:00Z"],
165-
["-3", "3", "3.0", "3", "2", "2016-04-04", "2016-04-04T11:30:00Z"],
159+
["-1", "1", "1.0", "'", "\\N", "2011-03-06", "2011-03-06T06:20:00Z"],
160+
["-2", "2", "2.0", '"', "", "2012-05-31", "2012-05-31T11:20:00Z"],
161+
["-3", "3", "3.0", "\\", "NULL", "2016-04-04", "2016-04-04T11:30:00Z"],
166162
]
167163
progress = await context.conn.stream_load("INSERT INTO test VALUES", values)
168164
assert progress.write_rows == 3, f"progress.write_rows: {progress.write_rows}"
169-
assert progress.write_bytes == 193, f"progress.write_bytes: {progress.write_bytes}"
165+
assert progress.write_bytes == 194, f"progress.write_bytes: {progress.write_bytes}"
170166

171167
rows = await context.conn.query_iter("SELECT * FROM test")
172-
ret = []
173-
async for row in rows:
174-
ret.append(row.values())
168+
ret = [row.values() for row in rows]
175169
expected = [
176-
(-1, 1, 1.0, "1", "1", date(2011, 3, 6), datetime(2011, 3, 6, 6, 20)),
177-
(-2, 2, 2.0, "2", "2", date(2012, 5, 31), datetime(2012, 5, 31, 11, 20)),
178-
(-3, 3, 3.0, "3", "2", date(2016, 4, 4), datetime(2016, 4, 4, 11, 30)),
170+
(-1, 1, 1.0, "'", None, date(2011, 3, 6), datetime(2011, 3, 6, 6, 20)),
171+
(-2, 2, 2.0, '"', None, date(2012, 5, 31), datetime(2012, 5, 31, 11, 20)),
172+
(-3, 3, 3.0, "\\", "NULL", date(2016, 4, 4), datetime(2016, 4, 4, 11, 30)),
179173
]
180174
assert ret == expected, f"ret: {ret}"
181175

182176

183177
@then("Load file and Select should be equal")
184178
async def _(context):
185179
progress = await context.conn.load_file(
186-
"INSERT INTO test VALUES", "tests/data/test.csv", {"type": "CSV"}
180+
"INSERT INTO test VALUES",
181+
"tests/data/test.csv",
182+
{"type": "CSV"},
187183
)
188184
assert progress.write_rows == 3, f"progress.write_rows: {progress.write_rows}"
189-
assert progress.write_bytes == 193, f"progress.write_bytes: {progress.write_bytes}"
185+
assert progress.write_bytes == 194, f"progress.write_bytes: {progress.write_bytes}"
190186

191187
rows = await context.conn.query_iter("SELECT * FROM test")
192-
ret = []
193-
for row in rows:
194-
ret.append(row.values())
188+
ret = [row.values() for row in rows]
195189
expected = [
196-
(-1, 1, 1.0, "1", "1", date(2011, 3, 6), datetime(2011, 3, 6, 6, 20)),
197-
(-2, 2, 2.0, "2", "2", date(2012, 5, 31), datetime(2012, 5, 31, 11, 20)),
198-
(-3, 3, 3.0, "3", "2", date(2016, 4, 4), datetime(2016, 4, 4, 11, 30)),
190+
(-1, 1, 1.0, "'", None, date(2011, 3, 6), datetime(2011, 3, 6, 6, 20)),
191+
(-2, 2, 2.0, '"', None, date(2012, 5, 31), datetime(2012, 5, 31, 11, 20)),
192+
(-3, 3, 3.0, "\\", "NULL", date(2016, 4, 4), datetime(2016, 4, 4, 11, 30)),
199193
]
200194
assert ret == expected, f"ret: {ret}"
201195

@@ -205,9 +199,7 @@ async def _(context):
205199
await context.conn.exec("create or replace temp table temp_1(a int)")
206200
await context.conn.exec("INSERT INTO temp_1 VALUES (1),(2)")
207201
rows = await context.conn.query_iter("SELECT * FROM temp_1")
208-
ret = []
209-
for row in rows:
210-
ret.append(row.values())
202+
ret = [row.values() for row in rows]
211203
expected = [(1), (2)]
212204
assert ret == expected, f"ret: {ret}"
213205
await context.conn.exec("DROP TABLE temp_1")

bindings/python/tests/blocking/steps/binding.py

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -114,74 +114,68 @@ async def _(context):
114114
@then("Select numbers should iterate all rows")
115115
def _(context):
116116
rows = context.conn.query_iter("SELECT number FROM numbers(5)")
117-
ret = []
118-
for row in rows:
119-
ret.append(row.values()[0])
117+
ret = [row.values()[0] for row in rows]
120118
expected = [0, 1, 2, 3, 4]
121119
assert ret == expected, f"ret: {ret}"
122120

123121

124122
@then("Insert and Select should be equal")
125123
def _(context):
126124
context.conn.exec(
127-
"""
125+
r"""
128126
INSERT INTO test VALUES
129-
(-1, 1, 1.0, '1', '1', '2011-03-06', '2011-03-06 06:20:00'),
130-
(-2, 2, 2.0, '2', '2', '2012-05-31', '2012-05-31 11:20:00'),
131-
(-3, 3, 3.0, '3', '2', '2016-04-04', '2016-04-04 11:30:00')
127+
(-1, 1, 1.0, '\'', NULL, '2011-03-06', '2011-03-06 06:20:00'),
128+
(-2, 2, 2.0, '"', '', '2012-05-31', '2012-05-31 11:20:00'),
129+
(-3, 3, 3.0, '\\', 'NULL', '2016-04-04', '2016-04-04 11:30:00')
132130
"""
133131
)
134132
rows = context.conn.query_iter("SELECT * FROM test")
135-
ret = []
136-
for row in rows:
137-
ret.append(row.values())
133+
ret = [row.values() for row in rows]
138134
expected = [
139-
(-1, 1, 1.0, "1", "1", date(2011, 3, 6), datetime(2011, 3, 6, 6, 20)),
140-
(-2, 2, 2.0, "2", "2", date(2012, 5, 31), datetime(2012, 5, 31, 11, 20)),
141-
(-3, 3, 3.0, "3", "2", date(2016, 4, 4), datetime(2016, 4, 4, 11, 30)),
135+
(-1, 1, 1.0, "'", None, date(2011, 3, 6), datetime(2011, 3, 6, 6, 20)),
136+
(-2, 2, 2.0, '"', "", date(2012, 5, 31), datetime(2012, 5, 31, 11, 20)),
137+
(-3, 3, 3.0, "\\", "NULL", date(2016, 4, 4), datetime(2016, 4, 4, 11, 30)),
142138
]
143139
assert ret == expected, f"ret: {ret}"
144140

145141

146142
@then("Stream load and Select should be equal")
147143
def _(context):
148144
values = [
149-
["-1", "1", "1.0", "1", "1", "2011-03-06", "2011-03-06T06:20:00Z"],
150-
["-2", "2", "2.0", "2", "2", "2012-05-31", "2012-05-31T11:20:00Z"],
151-
["-3", "3", "3.0", "3", "2", "2016-04-04", "2016-04-04T11:30:00Z"],
145+
["-1", "1", "1.0", "'", "\\N", "2011-03-06", "2011-03-06T06:20:00Z"],
146+
["-2", "2", "2.0", '"', "", "2012-05-31", "2012-05-31T11:20:00Z"],
147+
["-3", "3", "3.0", "\\", "NULL", "2016-04-04", "2016-04-04T11:30:00Z"],
152148
]
153149
progress = context.conn.stream_load("INSERT INTO test VALUES", values)
154150
assert progress.write_rows == 3, f"progress.write_rows: {progress.write_rows}"
155-
assert progress.write_bytes == 193, f"progress.write_bytes: {progress.write_bytes}"
151+
assert progress.write_bytes == 194, f"progress.write_bytes: {progress.write_bytes}"
156152

157153
rows = context.conn.query_iter("SELECT * FROM test")
158-
ret = []
159-
for row in rows:
160-
ret.append(row.values())
154+
ret = [row.values() for row in rows]
161155
expected = [
162-
(-1, 1, 1.0, "1", "1", date(2011, 3, 6), datetime(2011, 3, 6, 6, 20)),
163-
(-2, 2, 2.0, "2", "2", date(2012, 5, 31), datetime(2012, 5, 31, 11, 20)),
164-
(-3, 3, 3.0, "3", "2", date(2016, 4, 4), datetime(2016, 4, 4, 11, 30)),
156+
(-1, 1, 1.0, "'", None, date(2011, 3, 6), datetime(2011, 3, 6, 6, 20)),
157+
(-2, 2, 2.0, '"', None, date(2012, 5, 31), datetime(2012, 5, 31, 11, 20)),
158+
(-3, 3, 3.0, "\\", "NULL", date(2016, 4, 4), datetime(2016, 4, 4, 11, 30)),
165159
]
166160
assert ret == expected, f"ret: {ret}"
167161

168162

169163
@then("Load file and Select should be equal")
170164
def _(context):
171165
progress = context.conn.load_file(
172-
"INSERT INTO test VALUES", "tests/data/test.csv", {"type": "CSV"}
166+
"INSERT INTO test VALUES",
167+
"tests/data/test.csv",
168+
{"type": "CSV"},
173169
)
174170
assert progress.write_rows == 3, f"progress.write_rows: {progress.write_rows}"
175-
assert progress.write_bytes == 193, f"progress.write_bytes: {progress.write_bytes}"
171+
assert progress.write_bytes == 194, f"progress.write_bytes: {progress.write_bytes}"
176172

177173
rows = context.conn.query_iter("SELECT * FROM test")
178-
ret = []
179-
for row in rows:
180-
ret.append(row.values())
174+
ret = [row.values() for row in rows]
181175
expected = [
182-
(-1, 1, 1.0, "1", "1", date(2011, 3, 6), datetime(2011, 3, 6, 6, 20)),
183-
(-2, 2, 2.0, "2", "2", date(2012, 5, 31), datetime(2012, 5, 31, 11, 20)),
184-
(-3, 3, 3.0, "3", "2", date(2016, 4, 4), datetime(2016, 4, 4, 11, 30)),
176+
(-1, 1, 1.0, "'", None, date(2011, 3, 6), datetime(2011, 3, 6, 6, 20)),
177+
(-2, 2, 2.0, '"', None, date(2012, 5, 31), datetime(2012, 5, 31, 11, 20)),
178+
(-3, 3, 3.0, "\\", "NULL", date(2016, 4, 4), datetime(2016, 4, 4, 11, 30)),
185179
]
186180
assert ret == expected, f"ret: {ret}"
187181

@@ -191,9 +185,7 @@ async def _(context):
191185
context.conn.exec("create or replace temp table temp_1(a int)")
192186
context.conn.exec("INSERT INTO temp_1 VALUES (1),(2)")
193187
rows = context.conn.query_iter("SELECT * FROM temp_1")
194-
ret = []
195-
for row in rows:
196-
ret.append(row.values())
188+
ret = [row.values() for row in rows]
197189
expected = [(1), (2)]
198190
assert ret == expected, f"ret: {ret}"
199191
context.conn.exec("DROP TABLE temp_1")

0 commit comments

Comments
 (0)