Skip to content

Commit 3417f5f

Browse files
authored
fix: date_bin (#5)
1 parent 04701fc commit 3417f5f

File tree

2 files changed

+65
-65
lines changed

2 files changed

+65
-65
lines changed

pkg/arrow_flightsql/macro.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func createMacroDateBin(suffix string) sqlutil.MacroFunc {
2929
}
3030
column := args[0]
3131
alias := generateAlias(column, suffix)
32-
return fmt.Sprintf("date_bin(interval '%d second', %s, timestamp '1970-01-01T00:00:00Z')%s", int64(query.Interval.Seconds()), column, alias), nil
32+
return fmt.Sprintf("date_bin('%d second', %s, timestamp '1970-01-01T00:00:00Z')%s", int64(query.Interval.Seconds()), column, alias), nil
3333
}
3434
}
3535

@@ -53,7 +53,7 @@ func macroTimeGroupAlias(query *sqlutil.Query, args []string) (string, error) {
5353

5454
// macroInterval generates the SQL for interval.
5555
func macroInterval(query *sqlutil.Query, _ []string) (string, error) {
56-
return fmt.Sprintf("interval '%d second'", int64(query.Interval.Seconds())), nil
56+
return fmt.Sprintf("'%d second'", int64(query.Interval.Seconds())), nil
5757
}
5858

5959
// macroFrom generates the SQL for the 'from' time range.

src/components/QueryHelp.tsx

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React from 'react'
2-
import {Card} from '@grafana/ui'
2+
import { Card } from '@grafana/ui'
33

44
export const QueryHelp = () => (
5-
<div style={{padding: '10px 0'}}>
5+
<div style={{ padding: '10px 0' }}>
66
<div>
77
<h3>Format Options:</h3>
88
<h4>Table(default):</h4>
@@ -16,128 +16,128 @@ export const QueryHelp = () => (
1616
<Card>
1717
<Card.Heading>$__interval</Card.Heading>
1818
<Card.Description>
19-
Get the appropriate time interval from Grafana panel then parse it like `1 seconds` <br />
20-
And the possible units are: milliseconds/seconds/minutes/hours/days <br />
21-
Example: <br />
22-
SELECT speed FROM test WHERE time &gt;= NOW() - INTERVAL &apos;$__interval&apos;<br />
23-
Be parsed as: <br />
24-
SELECT speed FROM test WHERE time &gt;= NOW() - INTERVAL &apos;1 seconds&apos;
19+
Get the appropriate time interval from Grafana panel then parse it like `1 seconds` <br />
20+
And the possible units are: milliseconds/seconds/minutes/hours/days <br />
21+
Example: <br />
22+
SELECT speed FROM test WHERE time &gt;= NOW() - INTERVAL &apos;$__interval&apos;<br />
23+
Be parsed as: <br />
24+
SELECT speed FROM test WHERE time &gt;= NOW() - INTERVAL &apos;1 seconds&apos;
2525
</Card.Description>
2626
</Card>
2727

2828
<Card>
2929
<Card.Heading>$__dateBin</Card.Heading>
3030
<Card.Description>
31-
Group the data according to the appropriate time interval<br />
32-
Example: <br />
33-
SELECT $__dateBin(time) as timepoint FROM demo.test GROUP BY timepoint <br />
34-
Be parsed as: <br />
35-
SELECT date_bin(interval &apos;5 second&apos;, time, timestamp &apos;1970-01-01T00:00:00Z&apos;) as timepoint FROM demo.test GROUP BY timepoint
31+
Group the data according to the appropriate time interval<br />
32+
Example: <br />
33+
SELECT $__dateBin(time) as timepoint FROM demo.test GROUP BY timepoint <br />
34+
Be parsed as: <br />
35+
SELECT date_bin(&apos;5 second&apos;, time, timestamp &apos;1970-01-01T00:00:00Z&apos;) as timepoint FROM demo.test GROUP BY timepoint
3636
</Card.Description>
3737
</Card>
3838

3939
<Card>
4040
<Card.Heading>$__dateBinAlias</Card.Heading>
4141
<Card.Description>
42-
Group the data according to the appropriate time interval, use `_binned` suffix<br />
43-
Example: <br />
44-
SELECT $__dateBinAlias(time) FROM demo.test GROUP BY time_binned <br />
45-
Be parsed as: <br />
46-
SELECT date_bin(interval &apos;5 second&apos;, time, timestamp &apos;1970-01-01T00:00:00Z&apos;) as time_binned FROM demo.test GROUP BY ts_binned
42+
Group the data according to the appropriate time interval, use `_binned` suffix<br />
43+
Example: <br />
44+
SELECT $__dateBinAlias(time) FROM demo.test GROUP BY time_binned <br />
45+
Be parsed as: <br />
46+
SELECT date_bin(&apos;5 second&apos;, time, timestamp &apos;1970-01-01T00:00:00Z&apos;) as time_binned FROM demo.test GROUP BY ts_binned
4747
</Card.Description>
4848
</Card>
4949

5050
<Card>
5151
<Card.Heading>$__timeFrom</Card.Heading>
5252
<Card.Description>
53-
Represent the start time selected for the Grafana panel<br />
54-
Example: <br />
55-
SELECT * FROM demo.test WHERE time &gt;= $__timeFrom<br />
56-
Be parsed as: <br />
57-
SELECT * FROM demo.test WHERE time &gt;= cast(&apos;2024-07-30T06:40:39Z&apos; as timestamp)
53+
Represent the start time selected for the Grafana panel<br />
54+
Example: <br />
55+
SELECT * FROM demo.test WHERE time &gt;= $__timeFrom<br />
56+
Be parsed as: <br />
57+
SELECT * FROM demo.test WHERE time &gt;= cast(&apos;2024-07-30T06:40:39Z&apos; as timestamp)
5858
</Card.Description>
5959
</Card>
6060

6161
<Card>
6262
<Card.Heading>$__timeTo</Card.Heading>
6363
<Card.Description>
64-
Represent the end time selected for the Grafana panel<br />
65-
Example: <br />
66-
SELECT * FROM demo.test WHERE time &gt;= $__timeTo<br />
67-
Be parsed as: <br />
68-
SELECT * FROM demo.test WHERE time &gt;= cast(&apos;2024-07-30T06:40:39Z&apos; as timestamp)
64+
Represent the end time selected for the Grafana panel<br />
65+
Example: <br />
66+
SELECT * FROM demo.test WHERE time &gt;= $__timeTo<br />
67+
Be parsed as: <br />
68+
SELECT * FROM demo.test WHERE time &gt;= cast(&apos;2024-07-30T06:40:39Z&apos; as timestamp)
6969
</Card.Description>
7070
</Card>
7171

7272
<Card>
7373
<Card.Heading>$__timeFilter(time)</Card.Heading>
7474
<Card.Description>
75-
Represent the range time selected for the Grafana panel<br />
76-
Example: <br />
77-
SELECT * from demo.test WHERE $__timeFilter(time) <br />
78-
Be parsed as: <br />
79-
SELECT * from demo.test WHERE time &gt;= &apos;2024-07-30T07:36:07Z&apos; AND time &lt;= &apos;2024-07-30T10:36:07Z&apos; <br />
80-
Equal to: <br />
81-
SELECT * from demo.test WHERE time &gt;= $timeFrom AND time &lt;= $__timeTo
75+
Represent the range time selected for the Grafana panel<br />
76+
Example: <br />
77+
SELECT * from demo.test WHERE $__timeFilter(time) <br />
78+
Be parsed as: <br />
79+
SELECT * from demo.test WHERE time &gt;= &apos;2024-07-30T07:36:07Z&apos; AND time &lt;= &apos;2024-07-30T10:36:07Z&apos; <br />
80+
Equal to: <br />
81+
SELECT * from demo.test WHERE time &gt;= $timeFrom AND time &lt;= $__timeTo
8282
</Card.Description>
8383
</Card>
8484

8585
<Card>
8686
<Card.Heading>$__timeGroup(time, year)</Card.Heading>
8787
<Card.Description>
88-
Group the extracted partial time of the time field, the time field values: year/month/day/hour/minute<br />
89-
Example: <br />
90-
SELECT $__timeGroup(time, year) FROM demo.test<br />
91-
Be parsed as: <br />
92-
SELECT datepart(&apos;year&apos;, time),datepart(&apos;month&apos;, time),datepart(&apos;day&apos;, time),datepart(&apos;hour&apos;, time),datepart(&apos;minute&apos;, time) FROM demo.test
88+
Group the extracted partial time of the time field, the time field values: year/month/day/hour/minute<br />
89+
Example: <br />
90+
SELECT $__timeGroup(time, year) FROM demo.test<br />
91+
Be parsed as: <br />
92+
SELECT datepart(&apos;year&apos;, time),datepart(&apos;month&apos;, time),datepart(&apos;day&apos;, time),datepart(&apos;hour&apos;, time),datepart(&apos;minute&apos;, time) FROM demo.test
9393
</Card.Description>
9494
</Card>
9595

9696
<Card>
9797
<Card.Heading>$__timeGroupAlias(time, year)</Card.Heading>
9898
<Card.Description>
99-
Group the extracted partial time of the time field, use alias prefix `time_`, the time field values: year/month/day/hour/minute<br />
100-
Example: <br />
101-
SELECT $__timeGroupAlias(time, year) FROM demo.test<br />
102-
Be parsed as: <br />
103-
SELECT datepart(&apos;year&apos;, time) as time_year,datepart(&apos;month&apos;, time) as time_month,datepart(&apos;day&apos;, time) as time_day,datepart(&apos;hour&apos;, time) as time_hour,datepart(&apos;minute&apos;, time) as time_minute FROM demo.test
99+
Group the extracted partial time of the time field, use alias prefix `time_`, the time field values: year/month/day/hour/minute<br />
100+
Example: <br />
101+
SELECT $__timeGroupAlias(time, year) FROM demo.test<br />
102+
Be parsed as: <br />
103+
SELECT datepart(&apos;year&apos;, time) as time_year,datepart(&apos;month&apos;, time) as time_month,datepart(&apos;day&apos;, time) as time_day,datepart(&apos;hour&apos;, time) as time_hour,datepart(&apos;minute&apos;, time) as time_minute FROM demo.test
104104
</Card.Description>
105105
</Card>
106106

107107
<Card>
108108
<Card.Heading>$__timeRangeFrom(time)</Card.Heading>
109109
<Card.Description>
110-
Represent the start time selected for the Grafana panel<br />
111-
Example: <br />
112-
SELECT * FROM demo.test where $__timeRangeFrom(time)<br />
113-
Be parsed as: <br />
114-
SELECT * FROM demo.test where time &gt;= &apos;2024-07-30T07:29:46Z&apos;
110+
Represent the start time selected for the Grafana panel<br />
111+
Example: <br />
112+
SELECT * FROM demo.test where $__timeRangeFrom(time)<br />
113+
Be parsed as: <br />
114+
SELECT * FROM demo.test where time &gt;= &apos;2024-07-30T07:29:46Z&apos;
115115
</Card.Description>
116116
</Card>
117117

118118
<Card>
119119
<Card.Heading>$__timeRangeTo(time)</Card.Heading>
120120
<Card.Description>
121-
Represent the end time selected for the Grafana panel<br />
122-
Example: <br />
123-
SELECT * FROM demo.test where $__timeRangeTo(time)<br />
124-
Be parsed as: <br />
125-
SELECT * FROM demo.test where time &lt;= &apos;2024-07-30T07:29:46Z&apos;
121+
Represent the end time selected for the Grafana panel<br />
122+
Example: <br />
123+
SELECT * FROM demo.test where $__timeRangeTo(time)<br />
124+
Be parsed as: <br />
125+
SELECT * FROM demo.test where time &lt;= &apos;2024-07-30T07:29:46Z&apos;
126126
</Card.Description>
127127
</Card>
128128

129-
129+
130130

131131
<Card>
132132
<Card.Heading>$__timeRange(time)</Card.Heading>
133133
<Card.Description>
134-
Represent the range time selected for the Grafana panel <br />
135-
Example: <br />
136-
SELECT * FROM demo.test where $__timeRange(time)<br />
137-
Be parsed as: <br />
138-
SELECT * FROM demo.test where time &gt;= &apos;2024-07-30T07:37:41Z&apos; AND time &lt;= &apos;2024-07-30T10:37:41Z&apos; <br />
139-
Equal to: <br />
140-
SELECT * FROM demo.test where $__timeRangeFrom(time) AND $__timeRangeTo(time)
134+
Represent the range time selected for the Grafana panel <br />
135+
Example: <br />
136+
SELECT * FROM demo.test where $__timeRange(time)<br />
137+
Be parsed as: <br />
138+
SELECT * FROM demo.test where time &gt;= &apos;2024-07-30T07:37:41Z&apos; AND time &lt;= &apos;2024-07-30T10:37:41Z&apos; <br />
139+
Equal to: <br />
140+
SELECT * FROM demo.test where $__timeRangeFrom(time) AND $__timeRangeTo(time)
141141
</Card.Description>
142142
</Card>
143143
</div>

0 commit comments

Comments
 (0)