public override Task <bool> Open(Int64 auditKey, SelectQuery query, CancellationToken cancellationToken)
        {
            AuditKey = auditKey;

            if (query == null)
            {
                query = new SelectQuery();
            }

            var requiredSorts = RequiredSortFields();

            if (query.Sorts != null && query.Sorts.Count > 0)
            {
                for (var i = 0; i < requiredSorts.Count; i++)
                {
                    if (query.Sorts[i].Column == requiredSorts[i].Column)
                    {
                        requiredSorts[i].Direction = query.Sorts[i].Direction;
                    }
                    else
                    {
                        break;
                    }
                }
            }

            query.Sorts = requiredSorts;

            var returnValue = PrimaryTransform.Open(auditKey, query, cancellationToken);

            return(returnValue);
        }
        public override async Task <bool> Open(Int64 auditKey, SelectQuery query, CancellationToken cancellationToken)
        {
            AuditKey = auditKey;

            if (query == null)
            {
                query = new SelectQuery();
            }

            query.Sorts = RequiredSortFields();

            var returnValue = await PrimaryTransform.Open(auditKey, query, cancellationToken);

            //check if the transform has already sorted the data, using sql or a presort.
            _alreadySorted = SortFieldsMatch(_sortFields, PrimaryTransform.SortFields);

            return(returnValue);
        }
Exemple #3
0
        // public override List<Sort> SortFields => new List<Sort>();

        public override async Task <bool> Open(long auditKey, SelectQuery query, CancellationToken cancellationToken)
        {
            AuditKey = auditKey;

            var primarySorts   = new List <Sort>();
            var referenceSorts = new List <Sort>();

            //we need to translate filters and sorts to source column names before passing them through.
            if (query?.Sorts != null)
            {
                foreach (var sort in query.Sorts)
                {
                    if (sort.Column != null)
                    {
                        var column = PrimaryTransform.CacheTable[sort.Column.Name];
                        if (column != null)
                        {
                            primarySorts.Add(new Sort(column, sort.Direction));
                        }

                        column = ReferenceTransform.CacheTable[sort.Column.Name];
                        if (column != null)
                        {
                            referenceSorts.Add(new Sort(column, sort.Direction));
                        }
                    }
                }
            }

            var primaryQuery = new SelectQuery()
            {
                Sorts = primarySorts
            };
            var referenceQuery = new SelectQuery()
            {
                Sorts = referenceSorts
            };

            var returnValue = await PrimaryTransform.Open(auditKey, primaryQuery, cancellationToken);

            if (!returnValue)
            {
                return(false);
            }

            returnValue = await ReferenceTransform.Open(auditKey, referenceQuery, cancellationToken);

            //if the primary & reference transforms are sorted, we will merge sort the items.
            if (PrimaryTransform.SortFields != null && ReferenceTransform.SortFields != null)
            {
                var newSortFields = new List <Sort>();
                _primarySortOrdinals   = new List <int>();
                _referenceSortOrdinals = new List <int>();

                var index = 0;
                var referenceSortFields = ReferenceTransform.SortFields;

                foreach (var sortField in PrimaryTransform.SortFields)
                {
                    if (referenceSortFields.Count <= index)
                    {
                        break;
                    }

                    var referenceSortField = referenceSortFields[index];
                    if (sortField.Column.Name == referenceSortField.Column.Name &&
                        sortField.Direction == referenceSortField.Direction)
                    {
                        newSortFields.Add(sortField);

                        _primarySortOrdinals.Add(PrimaryTransform.CacheTable.GetOrdinal(sortField.Column.Name));
                        _referenceSortOrdinals.Add(ReferenceTransform.CacheTable.GetOrdinal(sortField.Column.Name));
                    }
                    else
                    {
                        break;
                    }

                    index++;
                }

                if (newSortFields.Count > 0)
                {
                    _sortedMerge = true;
                    CacheTable.OutputSortFields = newSortFields;
                }
            }

            return(returnValue);
        }
Exemple #4
0
        public override async Task <bool> Open(Int64 auditKey, SelectQuery query, CancellationToken cancellationToken)
        {
            AuditKey = auditKey;
            if (query == null)
            {
                query = new SelectQuery();
            }

            //only apply a sort if there is not already a sort applied.
            // if(query.Sorts == null || query.Sorts.Count == 0)
            query.Sorts = RequiredSortFields();

            var returnValue = await PrimaryTransform.Open(auditKey, query, cancellationToken);

            if (!returnValue)
            {
                return(false);
            }

            var referenceQuery = new SelectQuery()
            {
                Sorts = RequiredReferenceSortFields()
            };

            returnValue = await ReferenceTransform.Open(auditKey, referenceQuery, cancellationToken);

            if (!returnValue)
            {
                return(false);
            }

            //check if the primary and reference transform are sorted in the join
            if (SortFieldsMatch(RequiredSortFields(), PrimaryTransform.SortFields) && SortFieldsMatch(RequiredReferenceSortFields(), ReferenceTransform.SortFields))
            {
                JoinAlgorithm = EJoinAlgorithm.Sorted;
            }
            else
            {
                JoinAlgorithm = EJoinAlgorithm.Hash;
            }

            //store the ordinals for the joins to improve performance.
            if (_joinColumns == null)
            {
                _joinKeyOrdinals   = new int[0];
                _sourceKeyOrdinals = new int[0];
            }
            else
            {
                _joinKeyOrdinals   = new int[_joinColumns.Length];
                _sourceKeyOrdinals = new int[_joinColumns.Length];

                for (var i = 0; i < _joinColumns.Length; i++)
                {
                    _joinKeyOrdinals[i]   = ReferenceTransform.GetOrdinal(_joinColumns[i].JoinColumn.Name);
                    _sourceKeyOrdinals[i] = _joinColumns[i].SourceColumn == null ? -1 : PrimaryTransform.GetOrdinal(_joinColumns[i].SourceColumn.Name);
                }
            }


            return(true);
        }