Skip to content

Commit 5e72b8a

Browse files
kyleconroyclaude
andcommitted
Add short interval unit notations h, m, s, d, w (#119)
ClickHouse supports short notations for interval units like "INTERVAL 4 h" for hours. Added support for: - h -> hour - m -> minute - s -> second - d -> day - w -> week - ms -> millisecond - us -> microsecond - ns -> nanosecond Updated both the parser's intervalUnits map and the explain code's normalizeIntervalUnit functions to handle these short forms. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 4576008 commit 5e72b8a

File tree

3 files changed

+47
-35
lines changed

3 files changed

+47
-35
lines changed

internal/explain/functions.go

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,26 @@ func normalizeIntervalUnit(unit string) string {
2222
u = u[8:] // Remove "sql_tsi_" prefix
2323
}
2424

25-
// Handle SQL standard abbreviations
25+
// Handle SQL standard abbreviations and ClickHouse short notations
2626
abbrevs := map[string]string{
27-
"yy": "year",
28-
"qq": "quarter",
29-
"mm": "month",
30-
"wk": "week",
31-
"ww": "week",
32-
"dd": "day",
33-
"hh": "hour",
34-
"mi": "minute",
35-
"ss": "second",
36-
"ms": "millisecond",
37-
"us": "microsecond",
38-
"ns": "nanosecond",
27+
"yy": "year",
28+
"qq": "quarter",
29+
"mm": "month",
30+
"wk": "week",
31+
"ww": "week",
32+
"dd": "day",
33+
"hh": "hour",
34+
"mi": "minute",
35+
"ss": "second",
36+
// ClickHouse short notations
37+
"w": "week",
38+
"d": "day",
39+
"h": "hour",
40+
"m": "minute",
41+
"s": "second",
42+
"ms": "millisecond",
43+
"us": "microsecond",
44+
"ns": "nanosecond",
3945
}
4046
if expanded, ok := abbrevs[u]; ok {
4147
u = expanded
@@ -62,20 +68,26 @@ func normalizeIntervalUnitToLiteral(unit string) string {
6268
u = u[8:] // Remove "sql_tsi_" prefix
6369
}
6470

65-
// Handle SQL standard abbreviations
71+
// Handle SQL standard abbreviations and ClickHouse short notations
6672
abbrevs := map[string]string{
67-
"yy": "year",
68-
"qq": "quarter",
69-
"mm": "month",
70-
"wk": "week",
71-
"ww": "week",
72-
"dd": "day",
73-
"hh": "hour",
74-
"mi": "minute",
75-
"ss": "second",
76-
"ms": "millisecond",
77-
"us": "microsecond",
78-
"ns": "nanosecond",
73+
"yy": "year",
74+
"qq": "quarter",
75+
"mm": "month",
76+
"wk": "week",
77+
"ww": "week",
78+
"dd": "day",
79+
"hh": "hour",
80+
"mi": "minute",
81+
"ss": "second",
82+
// ClickHouse short notations
83+
"w": "week",
84+
"d": "day",
85+
"h": "hour",
86+
"m": "minute",
87+
"s": "second",
88+
"ms": "millisecond",
89+
"us": "microsecond",
90+
"ns": "nanosecond",
7991
}
8092
if expanded, ok := abbrevs[u]; ok {
8193
return expanded

parser/parser.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ var intervalUnits = map[string]bool{
1818
"YEAR": true, "YEARS": true,
1919
"QUARTER": true, "QUARTERS": true,
2020
"MONTH": true, "MONTHS": true,
21-
"WEEK": true, "WEEKS": true,
22-
"DAY": true, "DAYS": true,
23-
"HOUR": true, "HOURS": true,
24-
"MINUTE": true, "MINUTES": true,
25-
"SECOND": true, "SECONDS": true,
26-
"MILLISECOND": true, "MILLISECONDS": true,
27-
"MICROSECOND": true, "MICROSECONDS": true,
28-
"NANOSECOND": true, "NANOSECONDS": true,
21+
"WEEK": true, "WEEKS": true, "W": true,
22+
"DAY": true, "DAYS": true, "D": true,
23+
"HOUR": true, "HOURS": true, "H": true,
24+
"MINUTE": true, "MINUTES": true, "M": true,
25+
"SECOND": true, "SECONDS": true, "S": true,
26+
"MILLISECOND": true, "MILLISECONDS": true, "MS": true,
27+
"MICROSECOND": true, "MICROSECONDS": true, "US": true,
28+
"NANOSECOND": true, "NANOSECONDS": true, "NS": true,
2929
}
3030

3131
// isIntervalUnit checks if the given string is a valid interval unit name
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"explain_todo":{"stmt2":true}}
1+
{}

0 commit comments

Comments
 (0)