Skip to content

Commit 3e80cfe

Browse files
committed
better timeGroup macro handling for sub-second intervals
1 parent 5d94894 commit 3e80cfe

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

pkg/bigquery/macros.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func macroTimeGroup(query *sqlds.Query, args []string) (string, error) {
4646

4747
}
4848

49-
return fmt.Sprintf("TIMESTAMP_SECONDS(DIV(UNIX_SECONDS(%s), %v) * %v)", timeVar, interval.Seconds(), interval.Seconds()), nil
49+
return fmt.Sprintf("TIMESTAMP_MILLIS(DIV(UNIX_MILLIS(%s), %v) * %v)", timeVar, interval.Milliseconds(), interval.Milliseconds()), nil
5050
}
5151

5252
var macros = map[string]sqlds.MacroFunc{

pkg/bigquery/macros_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ func Test_macros(t *testing.T) {
2121
"timeGroup",
2222
&sqlds.Query{},
2323
[]string{"created_at", "1w"},
24-
"TIMESTAMP_SECONDS(DIV(UNIX_SECONDS(created_at), 604800) * 604800)",
24+
"TIMESTAMP_MILLIS(DIV(UNIX_MILLIS(created_at), 604800000) * 604800000)",
2525
nil,
2626
},
2727
{
2828
"time groups 1d",
2929
"timeGroup",
3030
&sqlds.Query{},
3131
[]string{"created_at", "1d"},
32-
"TIMESTAMP_SECONDS(DIV(UNIX_SECONDS(created_at), 86400) * 86400)",
32+
"TIMESTAMP_MILLIS(DIV(UNIX_MILLIS(created_at), 86400000) * 86400000)",
3333
nil,
3434
},
3535
{

0 commit comments

Comments
 (0)