core icon indicating copy to clipboard operation
core copied to clipboard

Complete Stream leads to data loss

Open j-bbr opened this issue 4 years ago • 3 comments

I am reading from an OSM-PBF File with a filter. CallingToComplete() leaves only nodes. All ways and relations that are present in the non-materialized stream are removed. Maybe related to #123 . I can provide a repro project in case you're interested.

j-bbr avatar May 08 '21 22:05 j-bbr

Can you reproduce this still? For example in a unittest?

xivk avatar May 10 '21 12:05 xivk

Here is a Test (all playgrounds in Berlin) that fails:

Test Output ----Normal---- OsmSharp.Node 1021 OsmSharp.Way 3031 OsmSharp.Relation 25 ----Complete---- OsmSharp.Node 1021

So it seems no completed ways or relations are returned at all

public class OsmSharpTest
    {
        public async Task<string> DownloadedFile()
        {
            var httpClient = new HttpClient();
            var downloadStream = await httpClient.GetStreamAsync("https://download.geofabrik.de/europe/germany/berlin-latest.osm.pbf");
            var filePath = Path.GetTempFileName();
            await using var fileStream = File.OpenWrite(filePath);
            await downloadStream.CopyToAsync(fileStream);
            return filePath;
        }

        private IEnumerable<object> GetItemsFromFile(string path, bool complete)
        {
            using var source = new PBFOsmStreamSource(new FileInfo(path).OpenRead());
            
            var includeTags = new []{new Tag ("leisure", "playground")}.ToImmutableHashSet();
            var filteredItems = source
                .Where(item => item.Tags.Any(tag => includeTags.Contains(tag)));
            return complete ? filteredItems.ToComplete().ToArray() : filteredItems.ToArray();
            
        }

        private async Task LogTypeCounts(IEnumerable<object> objects)
        {
            foreach (var type in objects.GroupBy(o => o.GetType())) 
                await TestContext.Progress.WriteLineAsync($"{type.Key} {type.Count()}");
        }
        
        [Test]
        public async Task Complete_Read_Test()
        {
            var downloadedPath = await DownloadedFile();
            var normalObjects = GetItemsFromFile( downloadedPath,false);
            var completeObjects = GetItemsFromFile(downloadedPath,true);
            File.Delete(downloadedPath);
            await TestContext.Progress.WriteLineAsync("----Normal----");
            await LogTypeCounts(normalObjects);
            await TestContext.Progress.WriteLineAsync("----Complete----");
            await LogTypeCounts(completeObjects);
            Assert.AreEqual(normalObjects.Count(), completeObjects.Count());
            
        }
    }

j-bbr avatar May 11 '21 19:05 j-bbr

Any idea on what could be the issue here?

j-bbr avatar May 25 '21 15:05 j-bbr