示例#1
0
        /// <summary>
        /// Check if this batchinfo has some data (in memory or not)
        /// </summary>
        public bool HasData(string tableName, string schemaName)
        {
            if (this.SanitizedSchema == null)
            {
                throw new NullReferenceException("Batch info schema should not be null");
            }

            if (InMemory && InMemoryData != null && InMemoryData.HasTables)
            {
                var table = InMemoryData.Tables[tableName, schemaName];
                if (table == null)
                {
                    return(false);
                }

                return(table.HasRows);
            }

            if (!InMemory && BatchPartsInfo != null && BatchPartsInfo.Count > 0)
            {
                var tableInfo = new BatchPartTableInfo(tableName, schemaName);

                var bptis = BatchPartsInfo.SelectMany(bpi => bpi.Tables.Where(t => t.EqualsByName(tableInfo)));

                if (bptis == null)
                {
                    return(false);
                }


                return(bptis.Sum(bpti => bpti.RowsCount) > 0);
            }

            return(false);
        }
示例#2
0
        public async IAsyncEnumerable <SyncTable> GetTableAsync(string tableName, string schemaName, ISerializerFactory serializerFactory = default, BaseOrchestrator orchestrator = null)
        {
            if (this.SanitizedSchema == null)
            {
                throw new NullReferenceException("Batch info schema should not be null");
            }

            var tableInfo = new BatchPartTableInfo(tableName, schemaName);

            if (InMemory)
            {
                this.SerializerFactoryKey = null;

                if (this.InMemoryData != null && this.InMemoryData.HasTables)
                {
                    yield return(this.InMemoryData.Tables[tableName, schemaName]);
                }
            }
            else
            {
                this.SerializerFactoryKey = serializerFactory.Key;

                var bpiTables = BatchPartsInfo.Where(bpi => bpi.RowsCount > 0 && bpi.Tables.Any(t => t.EqualsByName(tableInfo))).OrderBy(t => t.Index);

                if (bpiTables != null)
                {
                    foreach (var batchPartinInfo in bpiTables)
                    {
                        // load only if not already loaded in memory
                        if (batchPartinInfo.Data == null)
                        {
                            await batchPartinInfo.LoadBatchAsync(this.SanitizedSchema, GetDirectoryFullPath(), serializerFactory, orchestrator).ConfigureAwait(false);
                        }

                        // Get the table from the batchPartInfo
                        // generate a tmp SyncTable for
                        var batchTable = batchPartinInfo.Data.Tables.FirstOrDefault(bt => bt.EqualsByName(new SyncTable(tableName, schemaName)));

                        if (batchTable != null)
                        {
                            yield return(batchTable);

                            // We may need this same BatchPartInfo for another table,
                            // but we dispose it anyway, because memory can be quickly a bottleneck
                            // if batchpartinfos are resident in memory
                            batchPartinInfo.Data.Dispose();
                            batchPartinInfo.Data = null;
                        }
                    }
                }
            }
        }
示例#3
0
        /// <summary>
        /// Check if this batchinfo has some data
        /// </summary>
        public bool HasData()
        {
            if (this.SanitizedSchema == null)
            {
                throw new NullReferenceException("Batch info schema should not be null");
            }

            if (BatchPartsInfo != null && BatchPartsInfo.Count > 0)
            {
                var rowsCount = BatchPartsInfo.Sum(bpi => bpi.RowsCount);

                return(rowsCount > 0);
            }

            return(false);
        }
示例#4
0
        public async IAsyncEnumerable <SyncTable> GetTableAsync(string tableName, string schemaName, BaseOrchestrator orchestrator = null)
        {
            if (this.SanitizedSchema == null)
            {
                throw new NullReferenceException("Batch info schema should not be null");
            }

            var tableInfo = new BatchPartTableInfo(tableName, schemaName);

            if (InMemory)
            {
                if (this.InMemoryData != null && this.InMemoryData.HasTables)
                {
                    yield return(this.InMemoryData.Tables[tableName, schemaName]);
                }
            }
            else
            {
                var bpiTables = BatchPartsInfo.Where(bpi => bpi.RowsCount > 0 && bpi.Tables.Any(t => t.EqualsByName(tableInfo))).OrderBy(t => t.Index);

                if (bpiTables != null)
                {
                    foreach (var batchPartinInfo in bpiTables)
                    {
                        // load only if not already loaded in memory
                        if (batchPartinInfo.Data == null)
                        {
                            await batchPartinInfo.LoadBatchAsync(this.SanitizedSchema, GetDirectoryFullPath(), orchestrator).ConfigureAwait(false);
                        }

                        // Get the table from the batchPartInfo
                        // generate a tmp SyncTable for
                        var batchTable = batchPartinInfo.Data.Tables.FirstOrDefault(bt => bt.EqualsByName(new SyncTable(tableName, schemaName)));

                        if (batchTable != null)
                        {
                            yield return(batchTable);

                            // once loaded and yield, can dispose
                            batchPartinInfo.Data.Dispose();
                            batchPartinInfo.Data = null;
                        }
                    }
                }
            }
        }