private IAsyncEnumerable <KeyValuePair <string, string> > GetFileMappingForColumn(KeyValuePair <string, IAsyncEnumerable <string> > column)
        {
            var(key, value) = column;
            var mapping = value.Select(async val =>
                                       new KeyValuePair <string, string>(val,
                                                                         await _rootIndexAccess.GetFileNameForColumnAndValue(key, val)))
                          .Select(t => t.Result);

            return(mapping);
        }
Ejemplo n.º 2
0
        private async Task <IEnumerable <QueryResult> > GetFilesMatchingCondition(NeedleInHaystackColumnCondition condition)
        {
            var defaultResult = Enumerable.Empty <QueryResult>();
            var indexFileName = await _rootIndexAccess.GetFileNameForColumnAndValue(condition.ColumnName, condition.Value);

            if (indexFileName == CommonKeys.END_OF_INDEX_FLAG)
            {
                return(defaultResult);
            }

            var downloadedFileName = await this.DownloadIndexFile(indexFileName);//await _amazonAdapter.DownloadObjectAsync(_bucketName, indexFileName);

            if (string.IsNullOrEmpty(downloadedFileName))
            {
                return(Enumerable.Empty <QueryResult>());
            }
            using var indexFile = File.OpenRead(downloadedFileName);
            indexFile.Seek(-(2 * sizeof(long)), SeekOrigin.End);
            var metadataOffset = indexFile.ReadBinaryLongFromStream();
            var bloomOffset    = indexFile.ReadBinaryLongFromStream();

            if (!await VerifyConditionWithBloomFilter(condition, indexFile, bloomOffset))
            {
                return(defaultResult);
            }

            var(relevantSection, endOffset) = await GetRelevantSectionInIndex(indexFile, condition, metadataOffset, bloomOffset);

            if (relevantSection == default(IndexMetadataSectionModel))
            {
                return(defaultResult);
            }
            var indexRow = await GetIndexRowForCondition(condition, indexFile, relevantSection, endOffset);

            return(indexRow == default(IndexValueModel)
                ? defaultResult
                : indexRow.Files.Select(file =>
                                        new QueryResult {
                ["FileName"] = file, ["HitValues"] = new[] { condition.Value }
            }));
        }