@@ -11,6 +11,7 @@ import (
1111
1212const rsIdentifier = `([_a-zA-Z0-9]+)`
1313const sExpr = `\$` + rsIdentifier + `\(([^\)]*)\)`
14+ const missingColumnMessage = "missing time column argument for macro %v"
1415
1516func ReplaceAllStringSubmatchFunc (re * regexp.Regexp , str string , repl func ([]string ) string ) string {
1617 result := ""
@@ -78,20 +79,21 @@ func SetupFillmode(configStruct *queryConfigStruct, fillmode string) error {
7879// evaluateMacro convert macro expression to sql expression
7980func evaluateMacro (name string , args []string , configStruct * queryConfigStruct ) (string , error ) {
8081 timeRange := configStruct .TimeRange
82+
8183 switch name {
8284 case "__time" :
8385 if len (args ) == 0 || args [0 ] == "" {
84- return "" , fmt .Errorf ("missing time column argument for macro %v" , name )
86+ return "" , fmt .Errorf (missingColumnMessage , name )
8587 }
8688 return fmt .Sprintf ("TRY_TO_TIMESTAMP_NTZ(%s) AS time" , args [0 ]), nil
8789 case "__timeEpoch" :
8890 if len (args ) == 0 || args [0 ] == "" {
89- return "" , fmt .Errorf ("missing time column argument for macro %v" , name )
91+ return "" , fmt .Errorf (missingColumnMessage , name )
9092 }
9193 return fmt .Sprintf ("extract(epoch from %s) as time" , args [0 ]), nil
9294 case "__timeFilter" :
9395 if len (args ) == 0 || args [0 ] == "" {
94- return "" , fmt .Errorf ("missing time column argument for macro %v" , name )
96+ return "" , fmt .Errorf (missingColumnMessage , name )
9597 }
9698 column := args [0 ]
9799 timezone := "'UTC'"
@@ -101,7 +103,7 @@ func evaluateMacro(name string, args []string, configStruct *queryConfigStruct)
101103 return fmt .Sprintf ("%s > CONVERT_TIMEZONE('UTC', %s, '%s'::timestamp_ntz) AND %s < CONVERT_TIMEZONE('UTC', %s, '%s'::timestamp_ntz)" , column , timezone , timeRange .From .UTC ().Format (time .RFC3339Nano ), column , timezone , timeRange .To .UTC ().Format (time .RFC3339Nano )), nil
102104 case "__timeTzFilter" :
103105 if len (args ) == 0 || args [0 ] == "" {
104- return "" , fmt .Errorf ("missing time column argument for macro %v" , name )
106+ return "" , fmt .Errorf (missingColumnMessage , name )
105107 }
106108 column := args [0 ]
107109 return fmt .Sprintf ("%s > '%s'::timestamp_tz AND %s < '%s'::timestamp_tz" , column , timeRange .From .UTC ().Format (time .RFC3339Nano ), column , timeRange .To .UTC ().Format (time .RFC3339Nano )), nil
@@ -164,12 +166,12 @@ func evaluateMacro(name string, args []string, configStruct *queryConfigStruct)
164166 return "" , err
165167 case "__unixEpochFilter" :
166168 if len (args ) == 0 || args [0 ] == "" {
167- return "" , fmt .Errorf ("missing time column argument for macro %v" , name )
169+ return "" , fmt .Errorf (missingColumnMessage , name )
168170 }
169171 return fmt .Sprintf ("%s >= %d AND %s <= %d" , args [0 ], timeRange .From .UTC ().Unix (), args [0 ], timeRange .To .UTC ().Unix ()), nil
170172 case "__unixEpochNanoFilter" :
171173 if len (args ) == 0 || args [0 ] == "" {
172- return "" , fmt .Errorf ("missing time column argument for macro %v" , name )
174+ return "" , fmt .Errorf (missingColumnMessage , name )
173175 }
174176 return fmt .Sprintf ("%s >= %d AND %s <= %d" , args [0 ], timeRange .From .UTC ().UnixNano (), args [0 ], timeRange .To .UTC ().UnixNano ()), nil
175177 case "__unixEpochNanoFrom" :
0 commit comments