Exemplo n.º 1
0
        // Arthmentic Simplification:

        /*
         * +/- zero to a column, or multiply/divide a column by 1
         */
        internal bool IsArithIdentity(ConstExpr lce, ConstExpr rce)
        {
            ConstExpr ve = lce != null ? lce : rce;
            ColExpr   ce = (children_[0] is ColExpr) ? (ColExpr)children_[0] : (children_[1] is ColExpr ? (ColExpr)children_[1] : null);

            if (ce == null)
            {
                return(false);
            }

            if (!(TypeBase.IsNumberType(ve.type_) && TypeBase.IsNumberType(ce.type_)))
            {
                return(false);
            }

            if ((op_ == "+" || op_ == "-") && ve.IsZero())
            {
                return(true);
            }

            if ((op_ == "*" || op_ == "/") && ve.IsOne())
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 2
0
            public static ColExpr Load(XmlElement xml)
            {
                ColExpr res = new ColExpr();

                res.Expression = xml.GetAttribute("expr");
                res.Name       = xml.GetAttribute("name");
                switch (xml.GetAttribute("type"))
                {
                case "column":
                    res.Type = new ColumnColExprType();
                    break;

                case "python":
                    res.Type = new PythonColExprType();
                    break;

                case "null":
                    res.Type = new NullColExprType();
                    break;

                case "const":
                    res.Type = new ConstColExprType();
                    break;

                case "rownum":
                    res.Type = new RowNumberColExprType();
                    break;

                default:
                    throw new InternalError("DAE-00024 Unknown col expr type:" + xml.GetAttribute("type"));
                }
                return(res);
            }
Exemplo n.º 3
0
        public override void LoadFromXml(XmlElement xml, ITableStructure source, ITableStructure target)
        {
            m_source = source;
            m_target = target;

            if (xml.SelectSingleNode("Script") != null)
            {
                m_script = xml.SelectSingleNode("Script").InnerText;
            }

            TableStructure t = new TableStructure();

            foreach (XmlElement e in xml.SelectNodes("Column"))
            {
                ColExpr ce = ColExpr.Load(e);
                m_dstcols.Add(ce);
                t.AddColumn(new ColumnStructure
                {
                    ColumnName = ce.Name,
                    DataType   = ce.GetColType(source)
                }, true);
            }
            m_target = t;
            UpdateFlags();
        }
Exemplo n.º 4
0
        public static double EstSelectivity(this Expr filter)
        {
            var    andorlist   = filter.FilterToAndOrList();
            double selectivity = filter is LogicAndExpr ? 1.0 : 0.0;

            if (andorlist.Count == 1)
            {
                return(EstSingleSelectivity(filter));
            }
            else
            {
                // combine simple expressions of the same column
                Dictionary <ColExpr, List <double> > colselcombine = new Dictionary <ColExpr, List <double> >();
                foreach (var v in andorlist)
                {
                    ColExpr col = ExtractColumn(v);
                    if (!(col is null))
                    {
                        if (colselcombine.ContainsKey(col))
                        {
                            colselcombine[col].Add(EstSelectivity(v));
                        }
                        else
                        {
                            colselcombine.Add(col, new List <double> {
                                EstSelectivity(v)
                            });
                        }
                    }
Exemplo n.º 5
0
        internal Expr SimplifyArithmetic(ConstExpr lve, ConstExpr rve)
        {
            // we know we have a BinExpr with numeric children
            ConstExpr ve = lve != null ? lve : rve;
            ColExpr   ce = (children_[0] is ColExpr) ? (ColExpr)children_[0] : (children_[1] is ColExpr ? (ColExpr)children_[1] : null);

            if (ce is null || ve is null)
            {
                return(this);
            }

            // Col + 0, or Col - 0 => return col
            if ((op_ == "+" || op_ == "-") && ve.IsZero())
            {
                return(ce);
            }

            if ((op_ == "*" || op_ == "/") && ve.IsOne())
            {
                return(ce);
            }

            return(this);
        }