Exemple #1
0
        static public FuncExpr BuildFuncExpr(string funcName, List <Expr> args)
        {
            FuncExpr r    = null;
            var      func = funcName.Trim().ToLower();

            switch (func)
            {
            case "sum": r = new AggSum(args[0]); break;

            case "min": r = new AggMin(args[0]); break;

            case "max": r = new AggMax(args[0]); break;

            case "avg": r = new AggAvg(args[0]); break;

            case "stddev_samp": r = new AggStddevSamp(args[0]); break;

            case "count":
                if (args.Count == 0)
                {
                    r = new AggCountStar(null);
                }
                else
                {
                    r = new AggCount(args[0]);
                }
                break;

            case "substr":
            case "substring": r = new SubstringFunc(args); break;

            case "upper": r = new UpperFunc(args); break;

            case "year": r = new YearFunc(args); break;

            case "repeat": r = new RepeatFunc(args); break;

            case "round": r = new RoundFunc(args); break;

            case "coalesce": r = new CoalesceFunc(args); break;

            case "hash": r = new HashFunc(args); break;

            default:
                if (ExternalFunctions.set_.ContainsKey(funcName))
                {
                    r = new ExternalFunc(func, args);
                }
                else
                {
                    r = new FuncExpr(funcName, args);
                }
                break;
            }

            // verify arguments count
            Utils.Checks(args.Count == r.argcnt_, $"{r.argcnt_} argument is expected");
            return(r);
        }
Exemple #2
0
        static public FuncExpr BuildFuncExpr(string funcName, List <Expr> args)
        {
            var func = funcName.Trim().ToLower();

            FuncExpr r;

            switch (func)
            {
            case "sum": r = new AggSum(args); break;

            case "min": r = new AggMin(args); break;

            case "max": r = new AggMax(args); break;

            case "avg": r = new AggAvg(args); break;

            case "stddev_samp": r = new AggStddevSamp(args); break;

            case "count":
                if (args.Count == 0)
                {
                    r = new AggCountStar(null);
                }
                else
                {
                    r = new AggCount(args);
                }
                break;

            case "substr":
            case "substring": r = new SubstringFunc(args); break;

            case "upper": r = new UpperFunc(args); break;

            case "year": r = new YearFunc(args); break;

            case "date": r = new DateFunc(args); break;

            case "repeat": r = new RepeatFunc(args); break;

            case "abs": r = new AbsFunc(args); break;

            case "round": r = new RoundFunc(args); break;

            case "coalesce": r = new CoalesceFunc(args); break;

            case "hash": r = new HashFunc(args); break;

            case "tumble": r = new TumbleWindow(args); break;

            case "tumble_start": r = new TumbleStart(args); break;

            case "tumble_end": r = new TumbleEnd(args); break;

            case "hop": r = new HopWindow(args); break;

            case "session": r = new SessionWindow(args); break;

            default:
                if (ExternalFunctions.set_.ContainsKey(funcName))
                {
                    r = new ExternalFunc(func, args);
                }
                else
                {
                    r = new FuncExpr(funcName, args);
                }
                break;
            }

            // verify arguments count
            if (args.Count != r.argcnt_)
            {
                throw new SemanticAnalyzeException($"{r.argcnt_} argument is expected");
            }
            return(r);
        }