Skip to content

Commit

Permalink
fix clip, add tests
Browse files Browse the repository at this point in the history
Signed-off-by: qGYdXbY2 <[email protected]>
  • Loading branch information
qGYdXbY2 committed Nov 15, 2024
1 parent 2d310ce commit 77fd1dd
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public List<Load> getNeededResources() {
bRemoteCopy, rList.size(),
sourceSpace.getStorage().getId(),
targetSpace.getStorage().getId() );

return rList;
}
catch (WebClientException e) {
Expand Down Expand Up @@ -425,32 +425,17 @@ private SQLQuery buildCopyContentQuery(Space space) throws SQLException {
}

try {
return ((ExportSpace)getQueryRunner(event))
return ((ExportSpace) getQueryRunner(event))
//TODO: Why not selecting the feature id / geo here?
//FIXME: Do not select operation / author as part of the "property-selection"-fragment
.withSelectionOverride(new SQLQuery("jsondata, operation, author"))
.withGeoOverride(buildGeoFragment())
.withSelectionOverride(new SQLQuery("jsondata, author"))
.buildQuery(event);
}
catch (Exception e) {
throw new SQLException(e);
}
}

private SQLQuery buildGeoFragment() {
if (geometry != null && clipOnFilterGeometry) {
if( radius != -1 )
return new SQLQuery("ST_Intersection(ST_MakeValid(geo), ST_Buffer(ST_GeomFromText(#{wktGeometry})::geography, #{radius})::geometry) as geo")
.withNamedParameter("wktGeometry", WKTHelper.geometryToWKB(geometry))
.withNamedParameter("radius", radius);
else
return new SQLQuery("ST_Intersection(ST_MakeValid(geo), st_setsrid( ST_GeomFromText( #{wktGeometry} ),4326 )) as geo")
.withNamedParameter("wktGeometry", WKTHelper.geometryToWKB(geometry));
}
else
return new SQLQuery("geo");
}

private SearchForFeatures getQueryRunner(GetFeaturesByGeometryEvent event) throws SQLException,
ErrorResponseException, TooManyResourcesClaimed, WebClientException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ public static FeatureCollection generateRandomFeatureCollection(int featureCnt)
return fc;
}

public static FeatureCollection generateRandomFeatureCollection(int featureCnt,float xmin, float ymin, float xmax, float ymax) {
FeatureCollection fc = new FeatureCollection();
Random random = new Random();

try {
for (int i = 0; i < featureCnt; i++)
fc.getFeatures().add(new Feature().withProperties(new Properties().with("test", i).with("all","common"))
.withGeometry(new Point().withCoordinates(new PointCoordinates( (xmin + random.nextFloat() * (xmax - xmin)),
(ymin + random.nextFloat() * (ymax - ymin))))));
}catch (JsonProcessingException e){}

return fc;
}


public static Feature getFeatureFromCSVLine(String csvLine) throws JsonProcessingException {
return XyzSerializable.deserialize( csvLine.substring(1, csvLine.lastIndexOf(",") -1 ).replaceAll("'\"","\""), Feature.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,15 @@ protected void putRandomFeatureCollectionToSpace(String spaceId, int featureCoun
}
}

protected void putRandomFeatureCollectionToSpace(String spaceId, int featureCount ,float xmin, float ymin, float xmax, float ymax)
{
try {
hubWebClient.putFeaturesWithoutResponse(spaceId, ContentCreator.generateRandomFeatureCollection(featureCount,xmin,ymin,xmax,ymax));
} catch (XyzWebClient.WebClientException e) {
System.out.println("Hub Error: " + e.getMessage());
}
}

protected List<String> listExistingIndexes(String spaceId) throws SQLException {
return new SQLQuery("SELECT * FROM xyz_index_list_all_available(#{schema}, #{table});")
.withNamedParameter("schema", SCHEMA)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@

import com.here.xyz.jobs.steps.execution.LambdaBasedStep;
import com.here.xyz.jobs.steps.impl.transport.CopySpace;
import com.here.xyz.models.geojson.coordinates.LinearRingCoordinates;
import com.here.xyz.models.geojson.coordinates.PointCoordinates;
import com.here.xyz.models.geojson.coordinates.PolygonCoordinates;
import com.here.xyz.models.geojson.coordinates.Position;
import com.here.xyz.models.geojson.implementation.Geometry;
import com.here.xyz.models.geojson.implementation.Point;
import com.here.xyz.models.geojson.implementation.Polygon;
import com.here.xyz.models.hub.Ref;
import com.here.xyz.models.hub.Space;
import com.here.xyz.models.hub.Space.ConnectorRef;
Expand All @@ -30,20 +37,39 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;

import static java.lang.Thread.sleep;
import static org.junit.Assert.assertEquals;

import java.sql.SQLException;
import java.util.stream.Stream;

public class CopySpaceStepsTest extends StepTest {

private String SrcSpc = "testCopy-Source-07",
TrgSpc = "testCopy-Target-07",
OtherCntr = "psql_db2_hashed",
TrgRmtSpc = "testCopy-Target-07-remote";

static private String SrcSpc = "testCopy-Source-07",
TrgSpc = "testCopy-Target-07",
OtherCntr = "psql_db2_hashed",
TrgRmtSpc = "testCopy-Target-07-remote",
propertyFilter = "p.all=common";

static private Polygon spatialSearchGeom;
static private float xmin = 7.0f, ymin = 50.0f, xmax = 7.1f, ymax = 50.1f;
static {

LinearRingCoordinates lrc = new LinearRingCoordinates();
lrc.add(new Position(xmin, ymin));
lrc.add(new Position(xmax, ymin));
lrc.add(new Position(xmax, ymax));
lrc.add(new Position(xmin, ymax));
lrc.add(new Position(xmin, ymin));
PolygonCoordinates pc = new PolygonCoordinates();
pc.add(lrc);
spatialSearchGeom = new Polygon().withCoordinates( pc );

}

@BeforeEach
public void setup() throws SQLException {
Expand All @@ -53,12 +79,12 @@ public void setup() throws SQLException {
createSpace(new Space().withId(TrgRmtSpc).withVersionsToKeep(100).withStorage(new ConnectorRef().withId(OtherCntr)),false);

//write features source
putRandomFeatureCollectionToSpace(SrcSpc, 20);
putRandomFeatureCollectionToSpace(SrcSpc, 20);
putRandomFeatureCollectionToSpace(SrcSpc, 20,xmin,ymin,xmax,ymax);
putRandomFeatureCollectionToSpace(SrcSpc, 20,xmin,ymin,xmax,ymax);
//write features target - non-empty-space
putRandomFeatureCollectionToSpace(TrgSpc, 2);
putRandomFeatureCollectionToSpace(TrgSpc, 2,xmin,ymin,xmax,ymax);

putRandomFeatureCollectionToSpace(TrgRmtSpc, 2);
putRandomFeatureCollectionToSpace(TrgRmtSpc, 2,xmin,ymin,xmax,ymax);

}

Expand All @@ -69,11 +95,26 @@ public void cleanup() throws SQLException {
deleteSpace(TrgRmtSpc);
}


private static Stream<Arguments> provideParameters() {
return Stream.of(
Arguments.of(false,null,false,null),
Arguments.of(false,null,false,propertyFilter),
Arguments.of(true,null,false,null),
Arguments.of(true,null,false,propertyFilter),
Arguments.of(false, spatialSearchGeom,false,null),
Arguments.of(false, spatialSearchGeom,false,propertyFilter),
Arguments.of(false, spatialSearchGeom,true,null),
Arguments.of(false, spatialSearchGeom,true,propertyFilter),
Arguments.of(true, spatialSearchGeom,false,null),
Arguments.of(true, spatialSearchGeom,false,propertyFilter),
Arguments.of(true, spatialSearchGeom,true,null),
Arguments.of(true, spatialSearchGeom,true,propertyFilter)
);
}

@ParameterizedTest
@ValueSource(booleans = {false, true})
public void testCopySpaceToSpaceStep( boolean testRemoteDb) throws Exception {
@ParameterizedTest //(name = "{index}")
@MethodSource("provideParameters")
public void testCopySpaceToSpaceStep( boolean testRemoteDb, Geometry geo, boolean clip, String propertyFilter) throws Exception {

String targetSpace = !testRemoteDb ? TrgSpc : TrgRmtSpc;

Expand All @@ -83,12 +124,14 @@ public void testCopySpaceToSpaceStep( boolean testRemoteDb) throws Exception {

LambdaBasedStep step = new CopySpace()
.withSpaceId(SrcSpc).withSourceVersionRef(new Ref("HEAD"))
.withGeometry( geo ).withClipOnFilterGeometry(clip)
.withPropertyFilter(propertyFilter)
.withTargetSpaceId( targetSpace );

sendLambdaStepRequestBlock(step, true);

StatisticsResponse statsAfter = getStatistics(targetSpace);
assertEquals(42L, (Object) statsAfter.getCount().getValue());
}
}

}

0 comments on commit 77fd1dd

Please sign in to comment.