示例#1
0
 public override Value Init(ExecContext context, Row input)
 {
     values_ = new AggStddevValues();
     values_.vals_.Add(arg_().Exec(context, input));
     type_ = new DoubleType();
     return(values_);
 }
示例#2
0
        static ColumnType externalType2ColumnType(Type type)
        {
            ColumnType ctype;

            if (type == typeof(double))
            {
                ctype = new DoubleType();
            }
            else if (type == typeof(int))
            {
                ctype = new IntType();
            }
            else if (type == typeof(string))
            {
                ctype = new VarCharType(64 * 1024);
            }
            else
            {
                throw new NotImplementedException();
            }

            return(ctype);
        }
示例#3
0
文件: DataType.cs 项目: bigwa/qpmodel
        // 5/2.0 => 2.5
        public static ColumnType CoerseType(string op, Expr el, Expr er)
        {
            ColumnType result = null;
            ColumnType l      = el.type_;
            ColumnType r      = er.type_;

            if (l.Equals(r))
            {
                return(l);
            }
            else
            {
                if (l is DoubleType && r is NumericType rnum)
                {
                    result   = new NumericType(rnum.len_, rnum.scale_);
                    el.type_ = result;
                    if (el is LiteralExpr ell)
                    {
                        ell.val_ = Convert.ToDecimal(ell.val_);
                    }
                }
                else if (r is DoubleType && l is NumericType lnum)
                {
                    result   = new NumericType(lnum.len_, lnum.scale_);
                    er.type_ = result;
                    if (er is LiteralExpr erl)
                    {
                        erl.val_ = Convert.ToDecimal(erl.val_);
                    }
                }
                else if (l is DoubleType || r is DoubleType)
                {
                    result = new DoubleType();
                }
                else if (l is AnyType || r is AnyType)
                {
                    result = new AnyType();
                }
                else
                {
                    if (l is NumericType || r is NumericType)
                    {
                        // FIXME: this is a rough calculation
                        int prec = 0, scale = 0;
                        if (l is NumericType ln)
                        {
                            prec = ln.len_; scale = ln.scale_;
                        }
                        if (r is NumericType rn)
                        {
                            prec  = Math.Max(rn.len_, prec);
                            scale = Math.Max(rn.scale_, scale);
                        }
                        result = new NumericType(prec, scale);
                    }
                    else
                    {
                        throw new NotImplementedException("types coersion not implmeneted");
                    }
                }
            }

            Debug.Assert(result != null);
            return(result);
        }