Exemple #1
0
        public override Expr SplitAgg()
        {
            var child = child_();

            // child of tsum/tcount will be replace to bypass aggfunc child during aggfunc intialization
            var tsum = new AggSum(new List <Expr> {
                child
            }); tsum.dummyBind();
            var sumchild = new AggSum(new List <Expr> {
                child.Clone()
            }); sumchild.dummyBind();
            var sumchildref = new AggrRef(sumchild, -1);

            tsum.children_[0] = sumchildref;

            var tcount = new AggSum(new List <Expr> {
                child
            }); tcount.dummyBind();
            var countchild = new AggCount(new List <Expr> {
                child.Clone()
            }); countchild.dummyBind();
            var countchildref = new AggrRef(countchild, -1);

            tcount.children_[0] = countchildref;

            var processed = new BinExpr(tsum, tcount, "/");

            processed.dummyBind();
            return(processed);
        }
Exemple #2
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 #3
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);
        }