コード例 #1
0
ファイル: QueryPlanner.cs プロジェクト: prepare/deveeldb
        private static int MakeupFunctions(PreparedQuerySelectColumns columnSet, IList<SqlExpression> aggregateFunctions, out SqlExpression[] defFunList, out string[] defFunNames)
        {
            // Make up the functions list,
            var functionsList = columnSet.FunctionColumns.ToList();
            int fsz = functionsList.Count;
            var completeFunList = new List<object>();
            for (int i = 0; i < fsz; ++i) {
                var scol = functionsList[i];
                completeFunList.Add(scol.Expression);
                completeFunList.Add(scol.InternalName.Name);
            }

            for (int i = 0; i < aggregateFunctions.Count; ++i) {
                completeFunList.Add(aggregateFunctions[i]);
                completeFunList.Add("HAVINGAGG_" + (i + 1));
            }

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

            return fsz;
        }
コード例 #2
0
ファイル: QueryPlanner.cs プロジェクト: meikeric/deveeldb
        private static int MakeupFunctions(PreparedQuerySelectColumns columnSet, IList <SqlExpression> aggregateFunctions, out SqlExpression[] defFunList, out string[] defFunNames)
        {
            // Make up the functions list,
            var functionsList   = columnSet.FunctionColumns.ToList();
            int fsz             = functionsList.Count;
            var completeFunList = new List <object>();

            for (int i = 0; i < fsz; ++i)
            {
                var scol = functionsList[i];
                completeFunList.Add(scol.Expression);
                completeFunList.Add(scol.InternalName.Name);
            }

            for (int i = 0; i < aggregateFunctions.Count; ++i)
            {
                completeFunList.Add(aggregateFunctions[i]);
                completeFunList.Add("HAVINGAGG_" + (i + 1));
            }

            int fsz2 = completeFunList.Count / 2;

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

            return(fsz);
        }
コード例 #3
0
ファイル: QueryPlanner.cs プロジェクト: meikeric/deveeldb
        private IQueryPlanNode EvaluateToSingle(PreparedQuerySelectColumns columns)
        {
            if (columns.AggregateCount > 0)
            {
                throw new InvalidOperationException("Invalid use of aggregate function in select with no FROM clause");
            }

            // Make up the lists
            var selectedColumns = columns.SelectedColumns.ToList();
            int colCount        = selectedColumns.Count;
            var colNames        = new string[colCount];
            var expList         = new SqlExpression[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;
                aliases1[i]   = scol.ResolvedName;
            }

            return(new SubsetNode(new CreateFunctionsNode(new SingleRowTableNode(), expList, colNames), subsetVars, aliases1));
        }
コード例 #4
0
ファイル: QueryPlanner.cs プロジェクト: meikeric/deveeldb
        private static IList <SortColumn> ResolveOrderByRefs(PreparedQuerySelectColumns columnSet,
                                                             IEnumerable <SortColumn> orderBy)
        {
            // Resolve any numerical references in the ORDER BY list (eg.
            // '1' will be a reference to column 1.
            if (orderBy == null)
            {
                return(null);
            }

            var columnCount = columnSet.SelectedColumns.Count();

            var resolvedColumns = new List <SortColumn>();

            foreach (var column in orderBy)
            {
                var resolved = column;

                var expression = column.Expression;
                if (expression.ExpressionType == SqlExpressionType.Constant)
                {
                    var value = ((SqlConstantExpression)expression).Value;
                    if (value.Type is NumericType &&
                        !value.IsNull)
                    {
                        var colRef = ((SqlNumber)value.Value).ToInt32() - 1;
                        if (colRef >= 0 && colRef < columnCount)
                        {
                            var funArray = columnSet.FunctionColumns.ToArray();
                            var refExp   = funArray[colRef];

                            resolved = new SortColumn(refExp.Expression, column.Ascending);
                        }
                    }
                }

                resolvedColumns.Add(resolved);
            }

            return(resolvedColumns.ToArray());
        }
コード例 #5
0
ファイル: QueryPlanner.cs プロジェクト: prepare/deveeldb
        private IQueryPlanNode EvaluateToSingle(PreparedQuerySelectColumns columns)
        {
            if (columns.AggregateCount > 0)
                throw new InvalidOperationException("Invalid use of aggregate function in select with no FROM clause");

            // Make up the lists
            var selectedColumns = columns.SelectedColumns.ToList();
            int colCount = selectedColumns.Count;
            var colNames = new string[colCount];
            var expList = new SqlExpression[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;
                aliases1[i] = scol.ResolvedName;
            }

            return new SubsetNode(new CreateFunctionsNode(new SingleRowTableNode(), expList, colNames), subsetVars, aliases1);
        }
コード例 #6
0
ファイル: QueryPlanner.cs プロジェクト: prepare/deveeldb
        private static IList<SortColumn> ResolveOrderByRefs(PreparedQuerySelectColumns columnSet,
			IEnumerable<SortColumn> orderBy)
        {
            // Resolve any numerical references in the ORDER BY list (eg.
            // '1' will be a reference to column 1.
            if (orderBy == null)
                return null;

            var columnCount = columnSet.SelectedColumns.Count();

            var resolvedColumns = new List<SortColumn>();
            foreach (var column in orderBy) {
                var resolved = column;

                var expression = column.Expression;
                if (expression.ExpressionType == SqlExpressionType.Constant) {
                    var value = ((SqlConstantExpression) expression).Value;
                    if (value.Type is NumericType &&
                        !value.IsNull) {
                        var colRef = ((SqlNumber) value.Value).ToInt32() - 1;
                        if (colRef >= 0 && colRef < columnCount) {
                            var funArray = columnSet.FunctionColumns.ToArray();
                            var refExp = funArray[colRef];

                            resolved = new SortColumn(refExp.Expression, column.Ascending);
                        }
                    }
                }

                resolvedColumns.Add(resolved);
            }

            return resolvedColumns.ToArray();
        }