@@ -25,7 +25,6 @@ import (
25
25
"os"
26
26
"pb/pkg/config"
27
27
"pb/pkg/iterator"
28
- "regexp"
29
28
"strings"
30
29
"sync"
31
30
"time"
@@ -167,33 +166,31 @@ func createIteratorFromModel(m *QueryModel) *iterator.QueryIterator[QueryData, F
167
166
startTime = startTime .Truncate (time .Minute )
168
167
endTime = endTime .Truncate (time .Minute ).Add (time .Minute )
169
168
170
- regex := regexp .MustCompile (`^select\s+(?:\*|\w+(?:,\s*\w+)*)\s+from\s+(\w+)(?:\s+;)?$` )
171
- matches := regex .FindStringSubmatch (m .query .Value ())
172
- if matches == nil {
173
- return nil
169
+ table := streamNameFromQuery (m .query .Value ())
170
+ if table != "" {
171
+ iter := iterator .NewQueryIterator (
172
+ startTime , endTime ,
173
+ false ,
174
+ func (t1 , t2 time.Time ) (QueryData , FetchResult ) {
175
+ client := & http.Client {
176
+ Timeout : time .Second * 50 ,
177
+ }
178
+ return fetchData (client , & m .profile , m .query .Value (), t1 .UTC ().Format (time .RFC3339 ), t2 .UTC ().Format (time .RFC3339 ))
179
+ },
180
+ func (t1 , t2 time.Time ) bool {
181
+ client := & http.Client {
182
+ Timeout : time .Second * 50 ,
183
+ }
184
+ res , err := fetchData (client , & m .profile , "select count(*) as count from " + table , m .timeRange .StartValueUtc (), m .timeRange .EndValueUtc ())
185
+ if err == fetchErr {
186
+ return false
187
+ }
188
+ count := res .Records [0 ]["count" ].(float64 )
189
+ return count > 0
190
+ })
191
+ return & iter
174
192
}
175
- table := matches [1 ]
176
- iter := iterator .NewQueryIterator (
177
- startTime , endTime ,
178
- false ,
179
- func (t1 , t2 time.Time ) (QueryData , FetchResult ) {
180
- client := & http.Client {
181
- Timeout : time .Second * 50 ,
182
- }
183
- return fetchData (client , & m .profile , m .query .Value (), t1 .UTC ().Format (time .RFC3339 ), t2 .UTC ().Format (time .RFC3339 ))
184
- },
185
- func (t1 , t2 time.Time ) bool {
186
- client := & http.Client {
187
- Timeout : time .Second * 50 ,
188
- }
189
- res , err := fetchData (client , & m .profile , "select count(*) as count from " + table , m .timeRange .StartValueUtc (), m .timeRange .EndValueUtc ())
190
- if err == fetchErr {
191
- return false
192
- }
193
- count := res .Records [0 ]["count" ].(float64 )
194
- return count > 0
195
- })
196
- return & iter
193
+ return nil
197
194
}
198
195
199
196
func NewQueryModel (profile config.Profile , queryStr string , startTime , endTime time.Time ) QueryModel {
@@ -653,3 +650,15 @@ func countDigits(num int) int {
653
650
numDigits := int (math .Log10 (math .Abs (float64 (num )))) + 1
654
651
return numDigits
655
652
}
653
+
654
+ func streamNameFromQuery (query string ) string {
655
+ stream := ""
656
+ tokens := strings .Split (query , " " )
657
+ for i , token := range tokens {
658
+ if token == "from" {
659
+ stream = tokens [i + 1 ]
660
+ break
661
+ }
662
+ }
663
+ return stream
664
+ }
0 commit comments