Esempio n. 1
0
        private static IQueryPlanNode EvaluateSingle(QuerySelectColumnSet columnSet)
        {
            if (columnSet.AggregateCount > 0)
            {
                throw new ApplicationException("Invalid use of aggregate function in select with no FROM clause");
            }

            // Make up the lists
            List <SelectColumn> selectedColumns = columnSet.SelectedColumns;
            int colCount   = selectedColumns.Count;
            var colNames   = new string[colCount];
            var expList    = new Expression[colCount];
            var subsetVars = new ObjectName[colCount];
            var aliases1   = new ObjectName[colCount];

            for (int i = 0; i < colCount; ++i)
            {
                SelectColumn scol = selectedColumns[i];
                expList[i]    = scol.Expression;
                colNames[i]   = scol.InternalName.Name;
                subsetVars[i] = scol.InternalName.Clone();
                aliases1[i]   = scol.Alias.Clone();
            }

            return(new SubsetNode(new CreateFunctionsNode(new SingleRowTableNode(), expList, colNames), subsetVars, aliases1));
        }
Esempio n. 2
0
        private static int MakeupFunctions(QuerySelectColumnSet columnSet, IList <Expression> extraAggregateFunctions, out Expression[] defFunList, out string[] defFunNames)
        {
            // Make up the functions list,
            List <SelectColumn> functionsList = columnSet.FunctionColumns;
            int       fsz             = functionsList.Count;
            ArrayList completeFunList = new ArrayList();

            for (int i = 0; i < fsz; ++i)
            {
                SelectColumn scol = functionsList[i];
                completeFunList.Add(scol.Expression);
                completeFunList.Add(scol.InternalName.Name);
            }
            for (int i = 0; i < extraAggregateFunctions.Count; ++i)
            {
                completeFunList.Add(extraAggregateFunctions[i]);
                completeFunList.Add("HAVINGAG_" + (i + 1));
            }

            int fsz2 = completeFunList.Count / 2;

            defFunList  = new Expression[fsz2];
            defFunNames = new string[fsz2];
            for (int i = 0; i < fsz2; ++i)
            {
                defFunList[i]  = (Expression)completeFunList[i * 2];
                defFunNames[i] = (string)completeFunList[(i * 2) + 1];
            }

            return(fsz);
        }
Esempio n. 3
0
        private static IEnumerable <ByColumn> ResolveOrderByRefs(QuerySelectColumnSet columnSet, IEnumerable <ByColumn> orderBy)
        {
            // Resolve any numerical references in the ORDER BY list (eg.
            // '1' will be a reference to column 1.

            var result = new List <ByColumn>();

            if (orderBy != null)
            {
                List <SelectColumn> preparedColSet = columnSet.SelectedColumns;
                foreach (ByColumn col in orderBy)
                {
                    var byColumn = col;

                    Expression exp = col.Expression;
                    if (exp is ConstantExpression)
                    {
                        Number bnum = ((ConstantExpression)exp).Value.ToNumber();
                        if (bnum.Scale == 0)
                        {
                            int colRef = bnum.ToInt32() - 1;
                            if (colRef >= 0 && colRef < preparedColSet.Count)
                            {
                                SelectColumn scol = preparedColSet[colRef];
                                byColumn = new ByColumn(scol.Expression, byColumn.Ascending);
                            }
                        }
                    }

                    result.Add(byColumn);
                }
            }

            return(result.AsReadOnly());
        }
Esempio n. 4
0
        private static IQueryPlanNode PlanGroup(IQueryPlanNode node,
                                                QuerySelectColumnSet columnSet,
                                                ObjectName groupmaxColumn,
                                                int gsz,
                                                ObjectName[] groupByList,
                                                IList <Expression> groupByFunctions,
                                                int fsz,
                                                string[] defFunNames,
                                                Expression[] defFunList)
        {
            // If there is more than 1 aggregate function or there is a group by
            // clause, then we must add a grouping plan.
            if (columnSet.AggregateCount > 0 || gsz > 0)
            {
                // If there is no GROUP BY clause then assume the entire result is the
                // group.
                if (gsz == 0)
                {
                    node = new GroupNode(node, groupmaxColumn, defFunList, defFunNames);
                }
                else
                {
                    // Do we have any group by functions that need to be planned first?
                    int gfsz = groupByFunctions.Count;
                    if (gfsz > 0)
                    {
                        var groupFunList = new Expression[gfsz];
                        var groupFunName = new String[gfsz];
                        for (int i = 0; i < gfsz; ++i)
                        {
                            groupFunList[i] = groupByFunctions[i];
                            groupFunName[i] = "#GROUPBY-" + i;
                        }
                        node = new CreateFunctionsNode(node, groupFunList, groupFunName);
                    }

                    // Otherwise we provide the 'group_by_list' argument
                    node = new GroupNode(node, groupByList, groupmaxColumn, defFunList, defFunNames);
                }
            }
            else
            {
                // Otherwise no grouping is occuring.  We simply need create a function
                // node with any functions defined in the SELECT.
                // Plan a FunctionsNode with the functions defined in the SELECT.
                if (fsz > 0)
                {
                    node = new CreateFunctionsNode(node, defFunList, defFunNames);
                }
            }

            return(node);
        }
Esempio n. 5
0
        private static QuerySelectColumnSet BuildColumnSet(TableSelectExpression expression, TableExpressionFromSet fromSet)
        {
            // What we are selecting
            var columnSet = new QuerySelectColumnSet(fromSet);

            // The list of columns being selected.
            ICollection <SelectColumn> columns = expression.Columns;

            // For each column being selected
            foreach (SelectColumn col in columns)
            {
                // Is this a glob?  (eg. Part.* )
                if (col.IsGlob)
                {
                    // Find the columns globbed and add to the 'selectedColumns' result.
                    if (col.IsAll)
                    {
                        columnSet.SelectAllColumnsFromAllSources();
                    }
                    else
                    {
                        // Otherwise the glob must be of the form '[table name].*'
                        string     tname = col.GlobPrefix;
                        ObjectName tn    = ObjectName.Parse(tname);
                        columnSet.SelectAllColumnsFromSource(tn);
                    }
                }
                else
                {
                    // Otherwise must be a standard column reference.
                    columnSet.SelectSingleColumn(col);
                }
            }              // for each column selected

            return(columnSet);
        }
Esempio n. 6
0
        private static IEnumerable<ByColumn> ResolveOrderByRefs(QuerySelectColumnSet columnSet, IEnumerable<ByColumn> orderBy)
        {
            // Resolve any numerical references in the ORDER BY list (eg.
            // '1' will be a reference to column 1.

            var result = new List<ByColumn>();

            if (orderBy != null) {
                List<SelectColumn> preparedColSet = columnSet.SelectedColumns;
                foreach (ByColumn col in orderBy) {
                    var byColumn = col;

                    Expression exp = col.Expression;
                    if (exp is ConstantExpression) {
                        Number bnum = ((ConstantExpression)exp).Value.ToNumber();
                        if (bnum.Scale == 0) {
                            int colRef = bnum.ToInt32() - 1;
                            if (colRef >= 0 && colRef < preparedColSet.Count) {
                                SelectColumn scol = preparedColSet[colRef];
                                byColumn = new ByColumn(scol.Expression, byColumn.Ascending);
                            }
                        }
                    }

                    result.Add(byColumn);
                }
            }

            return result.AsReadOnly();
        }
Esempio n. 7
0
        private static IQueryPlanNode PlanGroup(IQueryPlanNode node,
			QuerySelectColumnSet columnSet,
			ObjectName groupmaxColumn,
			int gsz,
			ObjectName[] groupByList,
			IList<Expression> groupByFunctions,
			int fsz,
			string[] defFunNames,
			Expression[] defFunList)
        {
            // If there is more than 1 aggregate function or there is a group by
            // clause, then we must add a grouping plan.
            if (columnSet.AggregateCount > 0 || gsz > 0) {
                // If there is no GROUP BY clause then assume the entire result is the
                // group.
                if (gsz == 0) {
                    node = new GroupNode(node, groupmaxColumn, defFunList, defFunNames);
                } else {
                    // Do we have any group by functions that need to be planned first?
                    int gfsz = groupByFunctions.Count;
                    if (gfsz > 0) {
                        var groupFunList = new Expression[gfsz];
                        var groupFunName = new String[gfsz];
                        for (int i = 0; i < gfsz; ++i) {
                            groupFunList[i] = groupByFunctions[i];
                            groupFunName[i] = "#GROUPBY-" + i;
                        }
                        node = new CreateFunctionsNode(node, groupFunList, groupFunName);
                    }

                    // Otherwise we provide the 'group_by_list' argument
                    node = new GroupNode(node, groupByList, groupmaxColumn, defFunList, defFunNames);
                }
            } else {
                // Otherwise no grouping is occuring.  We simply need create a function
                // node with any functions defined in the SELECT.
                // Plan a FunctionsNode with the functions defined in the SELECT.
                if (fsz > 0)
                    node = new CreateFunctionsNode(node, defFunList, defFunNames);
            }

            return node;
        }
Esempio n. 8
0
        private static int MakeupFunctions(QuerySelectColumnSet columnSet, IList<Expression> extraAggregateFunctions, out Expression[] defFunList, out string[] defFunNames)
        {
            // Make up the functions list,
            List<SelectColumn> functionsList = columnSet.FunctionColumns;
            int fsz = functionsList.Count;
            ArrayList completeFunList = new ArrayList();
            for (int i = 0; i < fsz; ++i) {
                SelectColumn scol = functionsList[i];
                completeFunList.Add(scol.Expression);
                completeFunList.Add(scol.InternalName.Name);
            }
            for (int i = 0; i < extraAggregateFunctions.Count; ++i) {
                completeFunList.Add(extraAggregateFunctions[i]);
                completeFunList.Add("HAVINGAG_" + (i + 1));
            }

            int fsz2 = completeFunList.Count / 2;
            defFunList = new Expression[fsz2];
            defFunNames = new string[fsz2];
            for (int i = 0; i < fsz2; ++i) {
                defFunList[i] = (Expression)completeFunList[i * 2];
                defFunNames[i] = (string)completeFunList[(i * 2) + 1];
            }

            return fsz;
        }
Esempio n. 9
0
        private static IQueryPlanNode EvaluateSingle(QuerySelectColumnSet columnSet)
        {
            if (columnSet.AggregateCount > 0)
                throw new ApplicationException("Invalid use of aggregate function in select with no FROM clause");

            // Make up the lists
            List<SelectColumn> selectedColumns = columnSet.SelectedColumns;
            int colCount = selectedColumns.Count;
            var colNames = new string[colCount];
            var expList = new Expression[colCount];
            var subsetVars = new ObjectName[colCount];
            var aliases1 = new ObjectName[colCount];
            for (int i = 0; i < colCount; ++i) {
                SelectColumn scol = selectedColumns[i];
                expList[i] = scol.Expression;
                colNames[i] = scol.InternalName.Name;
                subsetVars[i] = scol.InternalName.Clone();
                aliases1[i] = scol.Alias.Clone();
            }

            return new SubsetNode(new CreateFunctionsNode(new SingleRowTableNode(), expList, colNames), subsetVars, aliases1);
        }
Esempio n. 10
0
        private static QuerySelectColumnSet BuildColumnSet(TableSelectExpression expression, TableExpressionFromSet fromSet)
        {
            // What we are selecting
            var columnSet = new QuerySelectColumnSet(fromSet);

            // The list of columns being selected.
            ICollection<SelectColumn> columns = expression.Columns;

            // For each column being selected
            foreach (SelectColumn col in columns) {
                // Is this a glob?  (eg. Part.* )
                if (col.IsGlob) {
                    // Find the columns globbed and add to the 'selectedColumns' result.
                    if (col.IsAll) {
                        columnSet.SelectAllColumnsFromAllSources();
                    } else {
                        // Otherwise the glob must be of the form '[table name].*'
                        string tname = col.GlobPrefix;
                        ObjectName tn = ObjectName.Parse(tname);
                        columnSet.SelectAllColumnsFromSource(tn);
                    }
                } else {
                    // Otherwise must be a standard column reference.
                    columnSet.SelectSingleColumn(col);
                }
            }  // for each column selected

            return columnSet;
        }