t.Run("interpolate macros with function calls as params successfully",func(t*testing.T){
filterInterpolated:=fmt.Sprintf("BETWEEN '%s' AND '%s'",from.Format(time.RFC3339),to.Format(time.RFC3339))
unixEpochFilter:=fmt.Sprintf("select try_convert(timestamp, time) >= %d AND try_convert(timestamp, time) <= %d",from.Unix(),to.Unix())
unixEphocNanoFilter:=fmt.Sprintf("select try_convert(timestamp, time) >= %d AND try_convert(timestamp, time) <= %d",from.UnixNano(),to.UnixNano())
//queries with macros and fct calls as params. fct calls are tested with various params and spaces
sqls:=[]struct{
querystring
expectedstring
}{
{
query:"select $__timeGroup(try_convert(timestamp, time), 5m) from test where $__timeFilter(time)",
expected:"select FLOOR(DATEDIFF(second, '1970-01-01', try_convert(timestamp, time))/300)*300 from test where time "+filterInterpolated,
},
{
query:"select $__timeGroup(try_convert(timestamp, time), 5m) from test where $__timeFilter(func(time))",
expected:"select FLOOR(DATEDIFF(second, '1970-01-01', try_convert(timestamp, time))/300)*300 from test where func(time) "+filterInterpolated,
},
{
query:"select $__timeGroup(try_convert(timestamp, time), 5m) from test where $__timeFilter(func(time));",
expected:"select FLOOR(DATEDIFF(second, '1970-01-01', try_convert(timestamp, time))/300)*300 from test where func(time) "+filterInterpolated+";",
},
{
query:"select $__timeGroup(try_convert(timestamp, time), 5m) from test where $__timeFilter(func(time, var2));",
expected:"select FLOOR(DATEDIFF(second, '1970-01-01', try_convert(timestamp, time))/300)*300 from test where func(time, var2) "+filterInterpolated+";",
},
{
query:"select $__timeGroup(try_convert(timestamp, time), 5m), $__timeGroup(func2( var1 , var2, var3 ), 15m) from test where $__timeFilter(func(time, var2));",
expected:"select FLOOR(DATEDIFF(second, '1970-01-01', try_convert(timestamp, time))/300)*300, FLOOR(DATEDIFF(second, '1970-01-01', func2( var1 , var2, var3 ))/900)*900 from test where func(time, var2) "+filterInterpolated+";",