From b8972ae2c2420ada0f0d5ac4c95ae7b58f8951d4 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Wed, 4 Apr 2018 22:58:14 +0100 Subject: [PATCH] =?UTF-8?q?Mathmatical=20sql=20functions=20must=20be=20pre?= =?UTF-8?q?fixed=20with=20=E2=80=98math=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit All mathmatical functions must now be used by specifying the full function name. For example `avg` is now `math.avg`. --- sql/funcs.go | 54 ------------------------------------------------ sql/sql_test.go | 2 +- util/fncs/fnc.go | 48 +++++++++++++++++++++--------------------- 3 files changed, 25 insertions(+), 79 deletions(-) diff --git a/sql/funcs.go b/sql/funcs.go index 9b173e1f..5af8f608 100644 --- a/sql/funcs.go +++ b/sql/funcs.go @@ -26,15 +26,6 @@ var rolls = map[string]bool{ // Math implementation - "geometricmean": true, - "mean": true, - "percentile": true, - "stddev": true, - "sum": true, - "variance": true, - - // Math implementation - "math.geometricmean": true, "math.mean": true, "math.percentile": true, @@ -55,27 +46,6 @@ var aggrs = map[string]bool{ // Math implementation - "bottom": true, - "geometricmean": true, - "harmonicmean": true, - "interquartile": true, - "max": true, - "mean": true, - "median": true, - "midhinge": true, - "min": true, - "mode": true, - "percentile": true, - "sample": true, - "spread": true, - "stddev": true, - "sum": true, - "top": true, - "trimean": true, - "variance": true, - - // Math implementation - "math.bottom": true, "math.geometricmean": true, "math.harmonicmean": true, @@ -148,30 +118,6 @@ var funcs = map[string]map[int]interface{}{ "http.async.delete": {1: nil, 2: nil}, // Math implementation - "abs": {1: nil}, - "bottom": {2: nil}, - "ceil": {1: nil}, - "correlation": {2: nil}, - "covariance": {2: nil}, - "floor": {1: nil}, - "geometricmean": {1: nil}, - "harmonicmean": {1: nil}, - "interquartile": {1: nil}, - "max": {1: nil}, - "mean": {1: nil}, - "median": {1: nil}, - "midhinge": {1: nil}, - "min": {1: nil}, - "mode": {1: nil}, - "percentile": {2: nil}, - "round": {2: nil}, - "sample": {2: nil}, - "spread": {1: nil}, - "stddev": {1: nil}, - "sum": {1: nil}, - "top": {2: nil}, - "trimean": {1: nil}, - "variance": {1: nil}, "math.abs": {1: nil}, "math.bottom": {2: nil}, "math.ceil": {1: nil}, diff --git a/sql/sql_test.go b/sql/sql_test.go index 8249bdf4..62152472 100644 --- a/sql/sql_test.go +++ b/sql/sql_test.go @@ -2521,7 +2521,7 @@ func Test_Parse_Queries_Define(t *testing.T) { }}}, }, { - sql: `DEFINE TABLE person AS SELECT nationality, midhinge(age) AS mid FROM users GROUP BY nationality`, + sql: `DEFINE TABLE person AS SELECT nationality, math.midhinge(age) AS mid FROM users GROUP BY nationality`, err: "Found 'mid' but field is not an aggregate function, and is not present in GROUP expression", }, { diff --git a/util/fncs/fnc.go b/util/fncs/fnc.go index c9cbb141..7c52dddb 100644 --- a/util/fncs/fnc.go +++ b/util/fncs/fnc.go @@ -106,53 +106,53 @@ func Run(ctx context.Context, name string, args ...interface{}) (interface{}, er return httpAsyncDelete(ctx, args...) // Math implementation - case "math.abs", "abs": + case "math.abs": return mathAbs(ctx, args...) - case "math.bottom", "bottom": + case "math.bottom": return mathBottom(ctx, args...) - case "math.ceil", "ceil": + case "math.ceil": return mathCeil(ctx, args...) - case "math.correlation", "correlation": + case "math.correlation": return mathCorrelation(ctx, args...) - case "math.covariance", "covariance": + case "math.covariance": return mathCovariance(ctx, args...) - case "math.floor", "floor": + case "math.floor": return mathFloor(ctx, args...) - case "math.geometricmean", "geometricmean": + case "math.geometricmean": return mathGeometricmean(ctx, args...) - case "math.harmonicmean", "harmonicmean": + case "math.harmonicmean": return mathHarmonicmean(ctx, args...) - case "math.interquartile", "interquartile": + case "math.interquartile": return mathInterquartile(ctx, args...) - case "math.max", "max": + case "math.max": return mathMax(ctx, args...) - case "math.mean", "mean": + case "math.mean": return mathMean(ctx, args...) - case "math.median", "median": + case "math.median": return mathMedian(ctx, args...) - case "math.midhinge", "midhinge": + case "math.midhinge": return mathMidhinge(ctx, args...) - case "math.min", "min": + case "math.min": return mathMin(ctx, args...) - case "math.mode", "mode": + case "math.mode": return mathMode(ctx, args...) - case "math.percentile", "percentile": + case "math.percentile": return mathPercentile(ctx, args...) - case "math.round", "round": + case "math.round": return mathRound(ctx, args...) - case "math.sample", "sample": + case "math.sample": return mathSample(ctx, args...) - case "math.spread", "spread": + case "math.spread": return mathSpread(ctx, args...) - case "math.stddev", "stddev": + case "math.stddev": return mathStddev(ctx, args...) - case "math.sum", "sum": + case "math.sum": return mathSum(ctx, args...) - case "math.top", "top": + case "math.top": return mathTop(ctx, args...) - case "math.trimean", "trimean": + case "math.trimean": return mathTrimean(ctx, args...) - case "math.variance", "variance": + case "math.variance": return mathVariance(ctx, args...) // String implementation