You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 61a63a7
Browse filesBrowse the repository at this point in the historyBrowse files
fix(bigquery)!: keep raw and adjacent pieces of bytes, typed literals and grantees
BigQuery gave one tree for literals written different ways: b'ab',
b'a' b'b' and rb'ab'; DATE, DATETIME, TIME and TIMESTAMP of a plain, a
raw or an adjacent string; JSON, NUMERIC and the other self-typed casts
of a raw or adjacent string; and a GRANT grantee as a plain, raw or
adjacent string.
The shared tree gains two literal kinds, raw bytes and adjacent bytes,
each keeping what was written. A typed literal of a raw or adjacent
string is a self-typed cast of that literal, and a grantee written raw
or in pieces records the written literal beside its name.
The GROUP BY match that already treats r'ab' as 'ab' now also reads raw
and adjacent bytes as one bytes literal and a raw or adjacent date or
time typed literal as the plain one, so these spellings give no new
E230. Bytes of the new kinds type as BYTES.
BREAKING CHANGE: sqlquack-syntax adds Literal::RawByteString and
Literal::JoinedBytes, and GrantPrincipal gains a written field, so an
exhaustive match on Literal or a GrantPrincipal struct literal no longer
compiles.
sql:"SELECT COALESCE(status, 'ab') AS x FROM orders GROUP BY COALESCE(status, r'ab')",
344
344
expected_findings:&[],
345
345
},
346
+
QueryFindingsTestCase{
347
+
description:"raw bytes in the select, plain ones in GROUP BY",
348
+
sql:"SELECT COALESCE(CAST(status AS BYTES), rb'ab') AS x FROM orders GROUP BY COALESCE(CAST(status AS BYTES), b'ab')",
349
+
expected_findings:&[],
350
+
},
351
+
QueryFindingsTestCase{
352
+
description:"adjacent bytes in the select, one piece in GROUP BY",
353
+
sql:"SELECT COALESCE(CAST(status AS BYTES), b'a' b'b') AS x FROM orders GROUP BY COALESCE(CAST(status AS BYTES), b'ab')",
354
+
expected_findings:&[],
355
+
},
356
+
QueryFindingsTestCase{
357
+
description:"a raw DATE in the select, a plain one in GROUP BY",
358
+
sql:"SELECT COALESCE(CAST(status AS DATE), DATE r'2020-01-01') AS x FROM orders GROUP BY COALESCE(CAST(status AS DATE), DATE '2020-01-01')",
359
+
expected_findings:&[],
360
+
},
361
+
QueryFindingsTestCase{
362
+
description:"an adjacent DATETIME in the select, a plain one in GROUP BY",
363
+
sql:"SELECT COALESCE(CAST(status AS DATETIME), DATETIME '2020-01-01' ' 00:00:00') AS x FROM orders GROUP BY COALESCE(CAST(status AS DATETIME), DATETIME '2020-01-01 00:00:00')",
364
+
expected_findings:&[],
365
+
},
366
+
QueryFindingsTestCase{
367
+
description:"a raw TIMESTAMP in the select, a plain one in GROUP BY",
368
+
sql:"SELECT COALESCE(CAST(status AS TIMESTAMP), TIMESTAMP r'2020-01-01 00:00:00') AS x FROM orders GROUP BY COALESCE(CAST(status AS TIMESTAMP), TIMESTAMP '2020-01-01 00:00:00')",
369
+
expected_findings:&[],
370
+
},
371
+
QueryFindingsTestCase{
372
+
description:"a raw NUMERIC in the select, a plain one in GROUP BY",
373
+
sql:"SELECT COALESCE(CAST(status AS NUMERIC), NUMERIC r'1') AS x FROM orders GROUP BY COALESCE(CAST(status AS NUMERIC), NUMERIC '1')",
374
+
expected_findings:&[],
375
+
},
376
+
QueryFindingsTestCase{
377
+
description:"a raw bytes character in the select, its UTF-8 bytes escaped in GROUP BY",
378
+
sql:"SELECT COALESCE(CAST(status AS BYTES), rb'\u{ff}') AS x FROM orders GROUP BY COALESCE(CAST(status AS BYTES), b'\\xc3\\xbf')",
379
+
expected_findings:&[],
380
+
},
381
+
QueryFindingsTestCase{
382
+
description:"raw bytes of another value are still a different expression",
383
+
sql:"SELECT COALESCE(CAST(status AS BYTES), rb'ac') AS x FROM orders GROUP BY COALESCE(CAST(status AS BYTES), b'ab')",
384
+
expected_findings:&[(
385
+
"E230",
386
+
"Column must be grouped or used in an aggregate function",
387
+
21,
388
+
)],
389
+
},
346
390
QueryFindingsTestCase{
347
391
description:"adjacent strings of another value are still a different expression",
348
392
sql:"SELECT COALESCE(status, 'a' 'c') AS x FROM orders GROUP BY COALESCE(status, 'ab')",
0 commit comments