Repository navigation
Description
Found via ClickGap automated review. Please close or comment if this is incorrect or needs adjustment.
Retrospective finding from a historical scan of PR #83784 (merged 2025-07-22). Confirmed on current codebase — close with a note if already fixed.
Describe what's wrong
JSONExtract('{"t": 45045}', 't', 'Time') returns 00:00:00 instead of 12:30:45. Numeric time values in JSON are silently dropped, returning default zero time.
Root cause: JSONExtractTree.cpp:760: TimeNode checks element.isUInt64() which is false for simdjson-parsed positive integers. Time64Node at line 978-988 correctly uses a switch on element.type() handling DOUBLE, UINT64, and INT64.
Why we believe this is a bug: TimeNode::insertResultToColumn (JSONExtractTree.cpp:760) checks element.isUInt64() for numeric path, but simdjson parses positive integers like 45045 as Int64 (not UInt64). The check fails, falls through to error case returning false, and JSONExtract inserts default value 00:00:00.
Affected locations:
src/Formats/JSONExtractTree.cpp:760— TimeNode::insertResultToColumn - isUInt64 check for numeric time values
Impact: Numeric time values in JSON (e.g., seconds since midnight) silently return 00:00:00 when using Time type with JSONExtract or JSON column type. Time64 works correctly with the same numeric values.
Does it reproduce on most recent release?
Yes — confirmed on current master (commit 6c21ce93c4df).
How to reproduce
-- Test: TimeNode in JSONExtractTree only handles UInt64 but JSON parser returns Int64 for positive ints
-- Covers: src/Formats/JSONExtractTree.cpp:760 - isUInt64 check misses Int64 path
SET enable_time_time64_type = 1;
-- Time from numeric value (45045 = 12:30:45 in seconds)
-- simdjson parses 45045 as Int64 (not UInt64), so TimeNode fails to handle it
SELECT 'time_numeric_int64';
SELECT JSONExtract('{"t": 45045}', 't', 'Time');
-- Time64 from numeric value - this works because Time64Node handles Int64
SELECT 'time64_numeric_int64';
SELECT JSONExtract('{"t": 45045123}', 't', 'Time64(3)');
-- Time from string - this works fine (existing test coverage)
SELECT 'time_string';
SELECT JSONExtract('{"t": "12:30:45"}', 't', 'Time');
-- Time64 from string - works fine
SELECT 'time64_string';
SELECT JSONExtract('{"t": "12:30:45.123"}', 't', 'Time64(3)');Expected behavior
time_numeric_int64
12:30:45
time64_numeric_int64
12:30:45.123
time_string
12:30:45
time64_string
12:30:45.123
Error message and/or stacktrace
time_numeric_int64
00:00:00
time64_numeric_int64
12:30:45.123
time_string
12:30:45
time64_string
12:30:45.123
Additional context
Open risks:
- DateTimeNode (line 695) has the same pre-existing bug - only checks isUInt64() for numeric DateTime values
Suggested fix: Replace the isUInt64() check with a switch statement matching Time64Node's pattern: handle ElementType::UINT64, ElementType::INT64, and optionally ElementType::DOUBLE.
Analysis details: Confidence HIGH | Severity P1 | Testability: STATELESS_SQL
Found during automated review of PR #83784.
ClickGapAI · Confidence: HIGH · Severity: P1 · Finding: h_pr83784_001
Version info
- Resolved by: Fix inserting into Time data type during JSON parsing #102690
- Merged into:
26.5.1.683
Activity