Example #1
0
        private static int Compare(OrderByColumn c, RowHolder x, RowHolder y)
        {
            IComparable left  = QueryProcessingAccessors.MetadataColumnRowsetHolderFetcher(c.column, x);
            IComparable right = QueryProcessingAccessors.MetadataColumnRowsetHolderFetcher(c.column, y);

            return((c.direction == OrderByColumn.Direction.Asc) ? left.CompareTo(right) : right.CompareTo(left));
        }
Example #2
0
        private static IComparable ValToIComp(Sql.value op, ref MetadataColumn[] metadataColumns, ref RowHolder rowHolder)
        {
            if (op.IsId)
            {
                Sql.value.Id   idVal = (Sql.value.Id)op;
                MetadataColumn mc    = QueryProcessingAccessors.GetMetadataColumn(idVal.Item, metadataColumns);
                return(QueryProcessingAccessors.MetadataColumnRowsetHolderFetcher(mc, rowHolder));
            }
            else if (op.IsFloat)
            {
                return(((Sql.value.Float)op).Item);
            }
            else if (op.IsInt)
            {
                return(((Sql.value.Int)op).Item);
            }
            else if (op.IsString)
            {
                return(((Sql.value.String)op).Item);
            }
            else
            {
                Debug.Fail("Invalid type");
            }

            throw new InvalidProgramException("Invalid state.");
        }
Example #3
0
        public async Task <IPhysicalOperator <RowHolder> > BuildStatement(Sql.sqlStatement statement, ITransaction tran, IPhysicalOperator <RowHolder> source, InputStringNormalizer stringNormalizer)
        {
            if (statement.Joins.Any())
            {
                IPhysicalOperator <RowHolder> currJoinSource = source;
                for (int i = 0; i < statement.Joins.Length; i++)
                {
                    if (!statement.Joins[i].Item2.IsInner)
                    {
                        throw new NotSupportedException("Only inner join is supported at this point.");
                    }

                    MetadataTable joinRightTable = await this.metadataManager.GetTableManager().GetByName(statement.Joins[i].Item1, tran).ConfigureAwait(false);

                    PhyOpScan scanOpRight = new PhyOpScan(joinRightTable.Collection, tran, joinRightTable.Columns, joinRightTable.TableName);

                    Func <RowHolder, bool> filter = (_) => true;
                    if (FSharpOption <Sql.where> .get_IsSome(statement.Joins[i].Item3))
                    {
                        filter = FilterStatementBuilder.EvalWhere(
                            statement.Joins[i].Item3.Value,
                            QueryProcessingAccessors.MergeColumns(currJoinSource.GetOutputColumns(), scanOpRight.GetOutputColumns()),
                            stringNormalizer);
                    }

                    currJoinSource = new PhyOpLoopInnerJoin(currJoinSource, scanOpRight, filter);
                }

                return(currJoinSource);
            }
            else
            {
                return(source);
            }
        }
Example #4
0
        public PhyOpLoopInnerJoin(IPhysicalOperator <RowHolder> sourceLeft, IPhysicalOperator <RowHolder> sourceRight, Func <RowHolder, bool> filterFunc)
        {
            this.filterFunc  = filterFunc;
            this.sourceLeft  = sourceLeft;
            this.sourceRight = sourceRight;

            this.returnMdColumns = QueryProcessingAccessors.MergeColumns(sourceLeft.GetOutputColumns(), sourceRight.GetOutputColumns());
        }
        public static GroupByFunctors EvalGroupBy(string[] groupByColumns, Sql.columnSelect[] selectColumns, MetadataColumn[] metadataColumns)
        {
            // Just prototyping for now. This needs a lot of refactoring.

            foreach (string groupByColumn in groupByColumns)
            {
                // Just checking whether all columns have correct name.
                var _ = QueryProcessingAccessors.GetMetadataColumn(groupByColumn, metadataColumns);
            }

            // metadata column, is extended.
            (MetadataColumn, bool)[] projectColumns = selectColumns
Example #6
0
        private OrderByColumn[] GetOrderByColumns(MetadataColumn[] columns, FSharpList <Tuple <string, Sql.dir> > orderBy)
        {
            OrderByColumn[] orderByColumns = new OrderByColumn[orderBy.Length];
            for (int i = 0; i < orderBy.Length; ++i)
            {
                MetadataColumn          column    = QueryProcessingAccessors.GetMetadataColumn(orderBy[i].Item1, columns);
                OrderByColumn.Direction direction = orderBy[i].Item2 == Sql.dir.Asc ? OrderByColumn.Direction.Asc : OrderByColumn.Direction.Desc;

                orderByColumns[i] = new OrderByColumn(column, direction);
            }

            return(orderByColumns);
        }
Example #7
0
        public Task <IPhysicalOperator <RowHolder> > BuildStatement(Sql.sqlStatement statement, ITransaction tran, IPhysicalOperator <RowHolder> source, InputStringNormalizer inputStringNormalizer)
        {
            Sql.columnSelect[] columns = new Sql.columnSelect[0];
            bool isStar = false;

            string[] projections = new string[0];

            if (statement.GroupBy.Any())
            {
                // no job for me, this is group by.
                return(Task.FromResult(source));
            }

            if (!statement.Columns.IsStar)
            {
                columns = (((Sql.selectType.ColumnList)statement.Columns).Item).ToArray();

                if (columns.Any(c => c.IsAggregate == true))
                {
                    // No job for me, this is aggregation.
                    return(Task.FromResult(source));
                }

                projections = columns
                              .Where(c => c.IsProjection == true)
                              .Select(c => ((Sql.columnSelect.Projection)c).Item).ToArray();
            }
            else
            {
                isStar = true;
            }

            int?topRows = null;

            if (FSharpOption <int> .get_IsSome(statement.Top))
            {
                topRows = statement.Top.Value;

                if (topRows < 1)
                {
                    throw new InvalidTopCountException();
                }
            }

            if (isStar)
            {
                // no need for project, just return everything.
                IPhysicalOperator <RowHolder> projectOp = new PhyOpProject(source, topRows);
                return(Task.FromResult(projectOp));
            }
            else
            {
                // Project Op.
                List <MetadataColumn> columnMapping = new List <MetadataColumn>();
                foreach (string columnName in projections)
                {
                    MetadataColumn mc = QueryProcessingAccessors.GetMetadataColumn(columnName, source.GetOutputColumns());
                    columnMapping.Add(mc);
                }

                IPhysicalOperator <RowHolder> projectOp = new PhyOpProject(source, columnMapping.Select(mc => mc.ColumnId).ToArray(), topRows);
                return(Task.FromResult(projectOp));
            }
        }