public virtual async Task <List <TransformWriterResult> > GetTransformWriterResults(long?hubKey, long connectionKey, long[] referenceKeys, string auditType, long?auditKey, TransformWriterResult.ERunStatus?runStatus, bool previousResult, bool previousSuccessResult, bool currentResult, DateTime?startTime, int rows, long?parentAuditKey, bool childItems, CancellationToken cancellationToken)
        {
            Transform reader = null;
            var       watch  = new Stopwatch();

            watch.Start();

            var picoTable = new PocoTable <TransformWriterResult>();

            reader = GetTransformReader(picoTable.Table);

            var filters = new List <Filter>();

            if (hubKey != null)
            {
                filters.Add(new Filter(new TableColumn("HubKey", ETypeCode.Int64), Filter.ECompare.IsEqual, hubKey));
            }
            if (referenceKeys != null && referenceKeys.Length > 0)
            {
                filters.Add(new Filter(new TableColumn("ReferenceKey", ETypeCode.Int64), Filter.ECompare.IsIn, referenceKeys));
            }
            if (auditType != null)
            {
                filters.Add(new Filter(new TableColumn("AuditType", ETypeCode.String), Filter.ECompare.IsEqual, auditType));
            }
            if (auditKey != null)
            {
                filters.Add(new Filter(new TableColumn("AuditKey", ETypeCode.Int64), Filter.ECompare.IsEqual, auditKey));
            }
            if (runStatus != null)
            {
                filters.Add(new Filter(new TableColumn("RunStatus", ETypeCode.String), Filter.ECompare.IsEqual, runStatus.ToString()));
            }
            if (startTime != null)
            {
                filters.Add(new Filter(new TableColumn("StartTime", ETypeCode.DateTime), Filter.ECompare.GreaterThanEqual, startTime));
            }
            if (currentResult)
            {
                filters.Add(new Filter(new TableColumn("IsCurrent", ETypeCode.Boolean), Filter.ECompare.IsEqual, true));
            }
            if (previousResult)
            {
                filters.Add(new Filter(new TableColumn("IsPrevious", ETypeCode.Boolean), Filter.ECompare.IsEqual, true));
            }
            if (previousSuccessResult)
            {
                filters.Add(new Filter(new TableColumn("IsPreviousSuccess", ETypeCode.Boolean), Filter.ECompare.IsEqual, true));
            }
            if (parentAuditKey != null)
            {
                filters.Add(new Filter(new TableColumn("ParentAuditKey", ETypeCode.Int64), Filter.ECompare.IsEqual, parentAuditKey));
            }

            var sorts = new List <Sort>()
            {
                new Sort(new TableColumn("AuditKey", ETypeCode.Int64), Sort.EDirection.Descending)
            };
            var query = new SelectQuery()
            {
                Filters = filters, Sorts = sorts, Rows = rows
            };

            //add a sort transform to ensure sort order.
            reader = new TransformSort(reader, sorts);

            var returnValue = await reader.Open(0, query, cancellationToken);

            if (!returnValue)
            {
                throw new ConnectionException($"Failed to get the transform writer results on table {picoTable.Table} at {Name}.");
            }

            var pocoReader    = new PocoLoader <TransformWriterResult>();
            var writerResults = await pocoReader.ToListAsync(reader, rows, cancellationToken);

            foreach (var result in writerResults)
            {
                result.AuditConnectionKey = connectionKey;

                if (childItems)
                {
                    result.ChildResults = await GetTransformWriterResults(hubKey, connectionKey, null, null, null, null, previousResult, previousSuccessResult, currentResult, null, 0, result.AuditKey, false, cancellationToken);
                }

                if (cancellationToken.IsCancellationRequested)
                {
                    break;
                }
            }

            watch.Stop();
            reader.Dispose();

            return(writerResults);
        }
示例#2
0
        public override bool InitializeOutputFields()
        {
            if (ReferenceTransform == null)
            {
                throw new Exception("There must a join table specified.");
            }

            CacheTable = new Table("Join");

            var pos = 0;

            foreach (var column in PrimaryTransform.CacheTable.Columns)
            {
                CacheTable.Columns.Add(column.Copy());
                pos++;
            }
            foreach (var column in ReferenceTransform.CacheTable.Columns)
            {
                var newColumn = column.Copy();
                newColumn.ReferenceTable      = ReferenceTableAlias;
                newColumn.IsIncrementalUpdate = false;

                // if (CacheTable.GetOrdinal(column.SchemaColumnName()) >= 0)
                // {
                //     throw new Exception("The join could not be initialized as the column " + column.SchemaColumnName() + " could not be found in the join table.");
                // }
                CacheTable.Columns.Add(newColumn);
                pos++;
            }

            var preFilters = new List <TransformFunction>();

            _referenceTableName = string.IsNullOrEmpty(ReferenceTransform.ReferenceTableAlias) ? ReferenceTransform.CacheTable.Name : ReferenceTransform.ReferenceTableAlias;

            List <FilterPair> filterJoins = null;

            if (JoinPairs != null)
            {
                _joinColumns = JoinPairs.Where(c => c.SourceColumn != null).ToArray();
                filterJoins  = JoinPairs
                               .Where(c => c.SourceColumn == null)
                               .Select(c => new FilterPair
                {
                    Column1     = c.JoinColumn,
                    Column2     = null,
                    FilterValue = c.JoinValue,
                    Compare     = Filter.ECompare.IsEqual
                }).ToList();
            }

            //seperate out the filers that only use the reference table and add them to prefilters from the ones required for joining.
            if (Functions != null)
            {
                foreach (var function in Functions)
                {
                    var isPrefilter = true;
                    foreach (var input in function.Inputs)
                    {
                        if (input.IsColumn)
                        {
                            if (input.Column.ReferenceTable != _referenceTableName)
                            {
                                isPrefilter = false;
                                break;
                            }
                        }
                    }
                    if (isPrefilter)
                    {
                        preFilters.Add(function);
                    }
                    else
                    {
                        _joinFilters.Add(function);
                    }
                }
            }

            if (preFilters.Count > 0 || filterJoins != null)
            {
                var preFilterTransform = new TransformFilter(ReferenceTransform, preFilters, filterJoins);
                ReferenceTransform = preFilterTransform;
            }


            //if the joinSortField has been, we need to enssure the reference dataset is sorted for duplication resolution.
            if (JoinSortField != null)
            {
                if (!SortFieldsMatch(RequiredReferenceSortFields(), ReferenceTransform.SortFields))
                {
                    var sortTransform = new TransformSort(ReferenceTransform, RequiredReferenceSortFields());
                    ReferenceTransform = sortTransform;
                }
            }

            _firstRead = true;

            _primaryFieldCount   = PrimaryTransform.FieldCount;
            _referenceFieldCount = ReferenceTransform.FieldCount;
            _joinKeyComparer     = new JoinKeyComparer();

            CacheTable.OutputSortFields = PrimaryTransform.CacheTable.OutputSortFields;

            return(true);
        }