Mathmatical sql functions must be prefixed with ‘math’

All mathmatical functions must now be used by specifying the full function name. For example `avg` is now `math.avg`.
This commit is contained in:
Tobie Morgan Hitchcock 2018-04-04 22:58:14 +01:00
parent 6c3ae600f8
commit b8972ae2c2
3 changed files with 25 additions and 79 deletions

View file

@ -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},

View file

@ -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",
},
{

View file

@ -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