示例#1
0
        public override Value ExecNonDistributed(ExecContext context, Row input)
        {
            Debug.Assert(type_ != null);
            Value expr = expr_().Exec(context, input);

            // for distributed execution, we don't copy logic plan which means this expression
            // is also not copied thus multiple threads may racing updating cacheVal_. Lock the
            // code section to prevent it. This also redu
            if (isCacheable_ && cachedValSet_)
            {
                var hset = cachedVal_ as HashSet <Value>;
                hasNull_ = hset.Contains(null);
                var in_cache_flag = !(expr is null) && hset.Contains(expr); // null in (1,null)  false
                // not in [.. null ..] = false
                return(hasNot_ ? (!hasNull_ && !in_cache_flag) : in_cache_flag);
            }

            var set = new HashSet <Value>();

            query_.physicPlan_.Exec(l =>
            {
                // it may have hidden columns but that's after [0]
                set.Add(l[0]);
            });

            hasNull_      = set.Contains(null);
            cachedVal_    = set;
            cachedValSet_ = true;
            bool in_flag = set.Contains(expr);

            return(hasNot_ ? (!hasNull_ && !in_flag) : in_flag);
        }
示例#2
0
        public override Value ExecNonDistributed(ExecContext context, Row input)
        {
            Debug.Assert(type_ != null);
            Value expr = expr_().Exec(context, input);

            // for distributed execution, we don't copy logic plan which means this expression
            // is also not copied thus multiple threads may racing updating cacheVal_. Lock the
            // code section to prevent it. This also redu
            if (isCacheable_ && cachedValSet_)
            {
                return((cachedVal_ as HashSet <Value>).Contains(expr));
            }

            var set = new HashSet <Value>();

            query_.physicPlan_.Exec(l =>
            {
                // it may have hidden columns but that's after [0]
                set.Add(l[0]);
            });

            cachedVal_    = set;
            cachedValSet_ = true;
            return(set.Contains(expr));
        }
示例#3
0
        public override object Visit(ExecContext ctx, Dictionary <string, object> table)
        {
            int   intRes;
            float floatRes;

            if (var.StartsWith("\"") && var.EndsWith("\""))
            {
                return(var.Substring(1, var.Length - 2));
            }

            if (int.TryParse(var, out intRes))
            {
                return(intRes);
            }

            if (float.TryParse(var, out floatRes))
            {
                return(floatRes);
            }

            if (table.ContainsKey(var))
            {
                return(table[var]);
            }

            return(null);
        }
示例#4
0
        public override Value Exec(ExecContext context, Row input)
        {
            string str   = (string)args_()[0].Exec(context, input);
            int    times = (int)args_()[1].Exec(context, input);

            return(string.Join("", Enumerable.Repeat(str, times)));
        }
示例#5
0
 public override Value Init(ExecContext context, Row input)
 {
     pair_        = new AvgPair();
     pair_.sum_   = arg_().Exec(context, input);
     pair_.count_ = pair_.sum_ is null ? 0 : 1;
     return(pair_);
 }
示例#6
0
 public override Value Init(ExecContext context, Row input)
 {
     values_ = new AggStddevValues();
     values_.vals_.Add(arg_().Exec(context, input));
     type_ = new DoubleType();
     return(values_);
 }
示例#7
0
        public override object Visit(ExecContext ctx, Dictionary <string, object> table)
        {
            switch (s)
            {
            case "=":
                op = Assign();
                break;

            case "*":
                op = Binary("op_Multiply");
                break;

            case "/":
                op = Binary("op_Division");
                break;

            case "%":
                op = Binary("op_Modulus");
                break;

            case "+":
                op = Binary("op_Addition");
                break;

            case "-":
                op = Binary("op_Subtraction");
                break;

            case "?":
                op = Nullable();
                break;
            }

            return(op(lhs, rhs, table));
        }
示例#8
0
        public override Value Accum(ExecContext context, Value old, Row input)
        {
            var  arg = arg_().Exec(context, input);
            Type ltype, rtype; ltype = typeof(int); rtype = typeof(int);

            Debug.Assert(old != null);
            AvgPair oldpair = old as AvgPair;

            if (oldpair.sum_ is null)
            {
                pair_.sum_ = arg;
                Debug.Assert(oldpair.count_ == 0);
                if (arg != null)
                {
                    pair_.count_ = 1;
                }
            }
            else
            {
                dynamic lv = oldpair.sum_;
                if (!(arg is null))
                {
                    dynamic rv = arg;
                    pair_.sum_   = lv + rv;
                    pair_.count_ = oldpair.count_ + 1;
                }
            }

            return(pair_);
        }
示例#9
0
        public override Value Exec(ExecContext context, Row input)
        {
            dynamic val     = arg_();
            int     hashval = val.GetHashCode();

            return(hashval);
        }
示例#10
0
        public List <Row> show()
        {
            bind(null);

            // TBD: route to optimizer here
            QueryOption queryOpt = new QueryOption();

            physicPlan_ = logicPlan_.DirectToPhysical(queryOpt);
            logicPlan_.ResolveColumnOrdinal(outputs_);

            // actual execution
            var finalplan = new PhysicCollect(physicPlan_);

            physicPlan_ = finalplan;
            var context = new ExecContext(queryOpt);

            Console.WriteLine(physicPlan_.Explain());

            finalplan.ValidateThis();
            var code = finalplan.Open(context);

            code += finalplan.Exec(null);
            code += finalplan.Close();

            return(finalplan.rows_);
        }
示例#11
0
 // for distributed execution, we don't copy logic plan which means this expression
 // is also not copied thus multiple threads may racing updating cacheVal_. A simple
 // way is to Lock the code section to prevent it.
 //
 Value ExecDistributed(ExecContext context, Row input)
 {
     lock (this)
     {
         return(ExecNonDistributed(context, input));
     }
 }
示例#12
0
        public override object Exec(ExecContext context, Row input)
        {
            var desc = ExternalFunctions.set_[funcName_];

            Debug.Assert(argcnt_ == desc.argcnt_);
            dynamic        fncode = desc.fn_;
            List <dynamic> args   = new List <dynamic>();

            for (int i = 0; i < argcnt_; i++)
            {
                args.Add(args_()[i].Exec(context, input));
            }
            switch (argcnt_)
            {
            case 0: return(fncode());

            case 1: return(fncode(args[0]));

            case 2: return(fncode(args[0], args[1]));

            case 3: return(fncode(args[0], args[1], args[2]));

            default:
                throw new NotImplementedException();
            }
        }
示例#13
0
 public override Value Exec(ExecContext context, Row input)
 {
     if (eval_() != null)
     {
         var eval = eval_().Exec(context, input);
         for (int i = 0; i < when_().Count; i++)
         {
             if (eval.Equals(when_()[i].Exec(context, input)))
             {
                 return(then_()[i].Exec(context, input));
             }
         }
     }
     else
     {
         for (int i = 0; i < when_().Count; i++)
         {
             if (when_()[i].Exec(context, input) is true)
             {
                 return(then_()[i].Exec(context, input));
             }
         }
     }
     if (else_() != null)
     {
         return(else_().Exec(context, input));
     }
     return(null);
 }
示例#14
0
        public override Value Exec(ExecContext context, Row input)
        {
            Value   to   = null;
            dynamic from = child_().Exec(context, input);

            switch (from)
            {
            case string vs:
                switch (type_)
                {
                case DateTimeType td:
                    to = DateTime.Parse(from);
                    break;

                default:
                    break;
                }
                break;

            default:
                to = from;
                break;
            }
            return(to);
        }
示例#15
0
        public override string ExecCode(ExecContext context, string input)
        {
            string lv = "(dynamic)" + l_().ExecCode(context, input);
            string rv = "(dynamic)" + r_().ExecCode(context, input);

            string code = null;

            switch (op_)
            {
            case "+": code = $"({lv} + {rv})"; break;

            case "-": code = $"({lv} - {rv})"; break;

            case "*": code = $"({lv} * {rv})"; break;

            case "/": code = $"({lv} / {rv})"; break;

            case ">": code = $"({lv} > {rv})"; break;

            case ">=": code = $"({lv} >= {rv})"; break;

            case "<": code = $"({lv} < {rv})"; break;

            case "<=": code = $"({lv} <= {rv})"; break;

            case "=": code = $"({lv} == {rv})"; break;

            case " and ": code = $"((bool){lv} && (bool){rv})"; break;

            default:
                throw new NotImplementedException();
            }
            return(code);
        }
示例#16
0
        public override Value ExecNonDistributed(ExecContext context, Row input)
        {
            Debug.Assert(type_ != null);
            if (isCacheable_ && cachedValSet_)
            {
                return(cachedVal_);
            }

            context.option_.PushCodeGenDisable();
            Row r = null;

            query_.physicPlan_.Exec(l =>
            {
                // exists check can immediately return after receiving a row
                var prevr = r; r = l;
                if (prevr != null)
                {
                    throw new SemanticExecutionException("subquery more than one row returned");
                }
            });
            context.option_.PopCodeGen();

            cachedVal_    = (r != null) ? r[0] : null;
            cachedValSet_ = true;
            return(cachedVal_);
        }
示例#17
0
 public override Value Exec(ExecContext context, Row input)
 {
     if (context is DistributedContext)
     {
         return(ExecDistributed(context, input));
     }
     return(ExecNonDistributed(context, input));
 }
示例#18
0
        public override Value Accum(ExecContext context, Value old, Row input)
        {
            var             arg     = arg_().Exec(context, input);
            AggStddevValues oldlist = old as AggStddevValues;

            oldlist.vals_.Add(arg);
            values_ = oldlist;
            return(values_);
        }
示例#19
0
        internal static void Run(Assembly assembly, SQLStatement stmt, ExecContext context)
        {
            // now we can execute it
            var type     = assembly.GetType("QueryCode");
            var instance = assembly.CreateInstance("QueryCode");
            var meth     = type.GetMember("Run").First() as MethodInfo;

            meth.Invoke(instance, new object[] { stmt, context });
        }
示例#20
0
        public override Value Exec(ExecContext context, Row input)
        {
            var val = args_()[0].Exec(context, input);

            if (val is null)
            {
                return(args_()[1].Exec(context, input));
            }
            return(val);
        }
示例#21
0
        public override Value Accum(ExecContext context, Value old, Row input)
        {
            var arg = arg_().Exec(context, input);

            if (arg != null)
            {
                count_ = old is null ? 1 : (long)old + 1;
            }
            return(count_);
        }
示例#22
0
        public override Value Exec(ExecContext context, Row input)
        {
            dynamic number   = args_()[0].Exec(context, input);
            int     decimals = (int)args_()[1].Exec(context, input);

            if (number is null)
            {
                return(null);
            }
            return(Math.Round(number, decimals));
        }
示例#23
0
        internal static void Run(CompilerResults cr, SQLStatement stmt, ExecContext context)
        {
            // now we can execute it
            var assembly  = cr.CompiledAssembly;
            var queryCode = assembly.GetType("QueryCode");
            var runmethod = queryCode.GetMethod("Run");

            runmethod.Invoke(null, new object[2] {
                stmt, context
            });
        }
示例#24
0
 internal void OpenSubQueries(ExecContext context)
 {
     foreach (var v in Subqueries(true))
     {
         v.query_.physicPlan_.Open(context);
     }
     foreach (var v in Subqueries(false))
     {
         v.query_.OpenSubQueries(context);
     }
 }
示例#25
0
        public override string ExecCode(ExecContext context, string input)
        {
            var str = str_.Replace("'", "\"");

            if (type_ is DateTimeType)
            {
                var date = (DateTime)val_;
                return($"(new DateTime({date.Ticks}))");
            }
            return(str);
        }
示例#26
0
        public override Value Exec(ExecContext context, Row input)
        {
            string str   = (string)args_()[0].Exec(context, input);
            int    start = (int)args_()[1].Exec(context, input) - 1;
            int    end   = (int)args_()[2].Exec(context, input) - 1;

            if (str is null)
            {
                return(null);
            }
            return(str.Substring(start, end - start + 1));
        }
        static void Main(string[] args)
        {
            // Dynamic proxy generation...

            // Create a new proxy generation request
            ProxyGenRequest req = new ProxyGenRequest();

            // Set the location of the assembly to be generated
            // leave empty ("") for current directory
            req.ProxyPath = "";
            // Set the name of the assembly (dll) that will be generated
            req.ServiceName = "WeatherSvc";
            // Set the url of the web service's WSDL file
            req.WsdlUrl = "http://www.xmethods.net/sd/2001/TemperatureService.wsdl";

            // Create a WSE mutator, generated proxies will expose the RequestContext
            // and ResponseContext properties
            ProxyPolicyMutator mutator = new ProxyPolicyMutator();

            // Set the name of the proxy class generated
            mutator.ProxyName = req.ServiceName;

            // Create the proxy generator
            ProxyGen pxyGen = new ProxyGen();

            // Set the proxy generator's mutator
            pxyGen.Mutator = mutator;
            // Generate the proxy
            string strAssembly = pxyGen.GenerateAssembly(req);

            // Dynamic invocation...

            // Set the parameter...note it MUST be in xml form
            string strZipcode = "<string>10025</string>";

            // Create an execution context
            ExecContext ctx = new ExecContext();

            // Set the fully qualified name of the web service proxy
            // (FullQname = <Namespace>.<classname>"
            ctx.ServiceName = req.Namespace + "." + req.ServiceName;
            // Set the name of the assembly where the proxy class "lives"
            ctx.Assembly = strAssembly;
            // Set the name of the method to dynamically invoke
            ctx.MethodName = "getTemp";
            // Add any parameters
            ctx.AddParameter(strZipcode);

            // Create an Executor
            Executor exec = new Executor();
            // Execute using the context
            object objRes = exec.Execute(ctx);
        }
示例#28
0
 public override string ExecCode(ExecContext context, string input)
 {
     Debug.Assert(type_ != null);
     if (isParameter_)
     {
         return(base.ExecCode(context, input));
     }
     else
     {
         return($"{input}[{ordinal_}]");
     }
 }
示例#29
0
 public override Value Exec(ExecContext context, Row input)
 {
     Debug.Assert(type_ != null);
     if (isParameter_)
     {
         return(context.GetParam(tabRef_, ordinal_));
     }
     else
     {
         return(input[ordinal_]);
     }
 }
示例#30
0
        public override Value Exec(ExecContext context, Row input)
        {
            dynamic lv = l_().Exec(context, input);
            dynamic rv = r_().Exec(context, input);

            if (op_ != "is" && (lv is null || rv is null))
            {
                return(null);
            }

            switch (op_)
            {
            case "+": return(lv + rv);

            case "-": return(lv - rv);

            case "*": return(lv * rv);

            case "/": return(lv / rv);

            case "||": return(string.Concat(lv, rv));

            case ">": return(lv > rv);

            case ">=": return(lv >= rv);

            case "<": return(lv < rv);

            case "<=": return(lv <= rv);

            case "=": return(lv == rv);

            case "<>":
            case "!=": return(lv != rv);

            case "like": return(Utils.StringLike(lv, rv));

            case "not like": return(!Utils.StringLike(lv, rv));

            case " and ": return(lv && rv);

            case " or ":     // null handling is different - handled by itself
            case "is":
                return(lv is null && rv is null);

            case "is not":
                return(!(lv is null) && rv is null);

            default:
                throw new NotImplementedException();
            }
        }