From b9bba49be6123765fdbf6cc4cc9ed66fd9ddddb0 Mon Sep 17 00:00:00 2001 From: Erni Durdevic Date: Fri, 11 Nov 2022 10:27:32 +0100 Subject: [PATCH 1/2] Fixed duplicated indexes --- .../databricks/labs/mosaic/core/Mosaic.scala | 2 +- .../labs/mosaic/core/TestMosaic.scala | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/test/scala/com/databricks/labs/mosaic/core/TestMosaic.scala diff --git a/src/main/scala/com/databricks/labs/mosaic/core/Mosaic.scala b/src/main/scala/com/databricks/labs/mosaic/core/Mosaic.scala index 3425a8f73..8195ed9f0 100644 --- a/src/main/scala/com/databricks/labs/mosaic/core/Mosaic.scala +++ b/src/main/scala/com/databricks/labs/mosaic/core/Mosaic.scala @@ -37,7 +37,7 @@ object Mosaic { } val coreIndices = indexSystem.polyfill(carvedGeometry, resolution, Some(geometryAPI)) - val borderIndices = indexSystem.polyfill(borderGeometry, resolution, Some(geometryAPI)) + val borderIndices = indexSystem.polyfill(borderGeometry, resolution, Some(geometryAPI)).diff(coreIndices) val coreChips = indexSystem.getCoreChips(coreIndices, keepCoreGeom, geometryAPI) val borderChips = indexSystem.getBorderChips(geometry, borderIndices, keepCoreGeom, geometryAPI) diff --git a/src/test/scala/com/databricks/labs/mosaic/core/TestMosaic.scala b/src/test/scala/com/databricks/labs/mosaic/core/TestMosaic.scala new file mode 100644 index 000000000..b59d62502 --- /dev/null +++ b/src/test/scala/com/databricks/labs/mosaic/core/TestMosaic.scala @@ -0,0 +1,18 @@ +package com.databricks.labs.mosaic.core + +import com.databricks.labs.mosaic.core.geometry.api.GeometryAPI.ESRI +import com.databricks.labs.mosaic.core.index.H3IndexSystem +import com.databricks.labs.mosaic.expressions.constructors.ConstructorsBehaviors +import org.scalatest.flatspec.AnyFlatSpec + +class TestMosaic extends AnyFlatSpec with ConstructorsBehaviors { + + "mosaicFill" should "not return duplicates with H3" in { + // This tests the fix for issue #243 https://github.com/databrickslabs/mosaic/issues/243 + val geom = ESRI.geometry("POLYGON ((4.42 51.78, 4.38 51.78, 4.39 51.83, 4.40 51.83, 4.41 51.8303, 4.417 51.8295, 4.42 51.83, 4.44 51.81, 4.42 51.78))", "WKT") + val result = Mosaic.mosaicFill(geom, 7, true, H3IndexSystem, ESRI) + + assert(result.length == 10) + assert(result.map(x => x.index).distinct.length == 10) + } +} From 3620d8b6fd860db18521b69b422db416bfa42da5 Mon Sep 17 00:00:00 2001 From: Erni Durdevic Date: Fri, 11 Nov 2022 22:15:12 +0100 Subject: [PATCH 2/2] Refactored test suite --- .../scala/com/databricks/labs/mosaic/core/TestMosaic.scala | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/test/scala/com/databricks/labs/mosaic/core/TestMosaic.scala b/src/test/scala/com/databricks/labs/mosaic/core/TestMosaic.scala index b59d62502..01699f34c 100644 --- a/src/test/scala/com/databricks/labs/mosaic/core/TestMosaic.scala +++ b/src/test/scala/com/databricks/labs/mosaic/core/TestMosaic.scala @@ -2,12 +2,11 @@ package com.databricks.labs.mosaic.core import com.databricks.labs.mosaic.core.geometry.api.GeometryAPI.ESRI import com.databricks.labs.mosaic.core.index.H3IndexSystem -import com.databricks.labs.mosaic.expressions.constructors.ConstructorsBehaviors -import org.scalatest.flatspec.AnyFlatSpec +import org.scalatest.funsuite.AnyFunSuite -class TestMosaic extends AnyFlatSpec with ConstructorsBehaviors { +class TestMosaic extends AnyFunSuite { - "mosaicFill" should "not return duplicates with H3" in { + test("mosaicFill should not return duplicates with H3") { // This tests the fix for issue #243 https://github.com/databrickslabs/mosaic/issues/243 val geom = ESRI.geometry("POLYGON ((4.42 51.78, 4.38 51.78, 4.39 51.83, 4.40 51.83, 4.41 51.8303, 4.417 51.8295, 4.42 51.83, 4.44 51.81, 4.42 51.78))", "WKT") val result = Mosaic.mosaicFill(geom, 7, true, H3IndexSystem, ESRI)