Skip to content

Commit 625757b

Browse files
committed
DS-2171: Remove deprecated ImportFromFile implementation and CSV support.
Signed-off-by: mchrza <maximilian.chrzan@here.com>
1 parent a17c719 commit 625757b

16 files changed

Lines changed: 161 additions & 1818 deletions

File tree

xyz-hub-test/src/test/java/com/here/xyz/hub/rest/LimitsTestIT.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import static io.restassured.RestAssured.given;
2727
import static org.hamcrest.Matchers.equalTo;
2828

29-
import com.here.xyz.jobs.steps.impl.transport.ImportFilesToSpace;
3029
import io.restassured.response.ValidatableResponse;
3130
import org.apache.commons.lang3.RandomStringUtils;
3231
import org.junit.After;

xyz-jobs/xyz-job-service/src/main/java/com/here/xyz/jobs/JobPlayground.java

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
import com.here.xyz.jobs.steps.impl.maintenance.MarkForMaintenance;
5252
import com.here.xyz.jobs.steps.impl.transport.CopySpace;
5353
import com.here.xyz.jobs.steps.impl.transport.ExportSpaceToFiles;
54-
import com.here.xyz.jobs.steps.impl.transport.ImportFilesToSpace;
54+
import com.here.xyz.jobs.steps.impl.transport.TaskedImportFilesToSpace;
5555
import com.here.xyz.jobs.steps.inputs.Input;
5656
import com.here.xyz.jobs.steps.outputs.Output;
5757
import com.here.xyz.models.geojson.coordinates.PointCoordinates;
@@ -117,7 +117,6 @@ public class JobPlayground {
117117
private static Space targetSpace;
118118
private static boolean simulateExecution = true;
119119
private static boolean executeWholeJob = false;
120-
private static ImportFilesToSpace.Format importFormat = ImportFilesToSpace.Format.GEOJSON;
121120
private static int uploadFileCount = 2;
122121
private static String jobServiceBaseUrl = "http://localhost:7070";
123122

@@ -235,7 +234,7 @@ private static void startLambdaExecutions() throws IOException, WebClientExcepti
235234

236235
runDropIndexStep(sampleSpace.getId());
237236

238-
runImportFilesToSpaceStep(sampleSpace.getId(), importFormat);
237+
runImportFilesToSpaceStep(sampleSpace.getId());
239238

240239
for (SystemIndex index : SystemIndex.values())
241240
runCreateIndexStep(sampleSpace.getId(), index);
@@ -253,15 +252,15 @@ else if (playgroundUsecase == EXPORT)
253252
private static void uploadFiles() throws IOException {
254253
//Generate N Files with M features
255254
for (int i = 0; i < uploadFileCount; i++)
256-
uploadInputFile(generateContent(importFormat, 10));
255+
uploadInputFile(generateContent( 10));
257256
}
258257

259258
private static void uploadFilesToRealJob(String jobId) throws IOException, InterruptedException {
260259
//Generate N Files with M features
261260
for (int i = 0; i < uploadFileCount; i++) {
262261
HttpResponse<byte[]> inputResponse = post("/jobs/" + jobId + "/inputs", Map.of("type", "UploadUrl"));
263262
String uploadUrl = (String) XyzSerializable.deserialize(inputResponse.body(), Map.class).get("url");
264-
uploadInputFile(generateContent(importFormat, 10), new URL(uploadUrl));
263+
uploadInputFile(generateContent( 10), new URL(uploadUrl));
265264
}
266265

267266
}
@@ -291,16 +290,16 @@ private static void pollRealJobStatus(String jobId) throws InterruptedException
291290
}
292291
}
293292

294-
private static byte[] generateContent(ImportFilesToSpace.Format format, int featureCnt) {
293+
private static byte[] generateContent(int featureCnt) {
295294
String output = "";
296295

297296
for (int i = 1; i <= featureCnt; i++) {
298-
output += generateContentLine(format, i);
297+
output += generateContentLine(i);
299298
}
300299
return output.getBytes();
301300
}
302301

303-
private static void generateContentToFile(ImportFilesToSpace.Format format, int featureCnt, boolean beZipped) throws IOException {
302+
private static void generateContentToFile(int featureCnt, boolean beZipped) throws IOException {
304303
String outputFile = "/tmp/output.file" + (beZipped ? ".gz" : "");
305304

306305
BufferedWriter writer = null;
@@ -315,24 +314,18 @@ private static void generateContentToFile(ImportFilesToSpace.Format format, int
315314
new OutputStreamWriter(zip, "UTF-8"));
316315
}
317316
for (int i = 1; i <= featureCnt; i++) {
318-
writer.write(generateContentLine(format, i));
317+
writer.write(generateContentLine(i));
319318
}
320319
}finally {
321320
if (writer != null)
322321
writer.close();
323322
}
324323
}
325324

326-
private static String generateContentLine(ImportFilesToSpace.Format format, int i){
325+
private static String generateContentLine(int i){
327326
Random rd = new Random();
328327
String lineSeparator = "\n";
329-
330-
if(format.equals(ImportFilesToSpace.Format.CSV_JSON_WKB))
331-
return "\"{'\"properties'\": {'\"test'\": "+i+"}}\",01010000A0E61000007DAD4B8DD0AF07C0BD19355F25B74A400000000000000000"+lineSeparator;
332-
else if(format.equals(ImportFilesToSpace.Format.CSV_GEOJSON))
333-
return "\"{'\"type'\":'\"Feature'\",'\"geometry'\":{'\"type'\":'\"Point'\",'\"coordinates'\":["+(rd.nextInt(179))+"."+(rd.nextInt(100))+","+(rd.nextInt(79))+"."+(rd.nextInt(100))+"]},'\"properties'\":{'\"test'\":"+i+"}}\""+lineSeparator;
334-
else
335-
return "{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":["+(rd.nextInt(179))+"."+(rd.nextInt(100))+","+(rd.nextInt(79))+"."+(rd.nextInt(100))+"]},\"properties\":{\"te\\\"st\":"+i+"}}"+lineSeparator;
328+
return "{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":["+(rd.nextInt(179))+"."+(rd.nextInt(100))+","+(rd.nextInt(79))+"."+(rd.nextInt(100))+"]},\"properties\":{\"te\\\"st\":"+i+"}}"+lineSeparator;
336329
}
337330

338331
private static void startMockJob() {
@@ -479,8 +472,8 @@ public static void runDropIndexStep(String spaceId) throws IOException {
479472
runStep(new DropIndexes().withSpaceId(spaceId));
480473
}
481474

482-
public static void runImportFilesToSpaceStep(String spaceId, ImportFilesToSpace.Format format) throws IOException {
483-
runStep(new ImportFilesToSpace().withSpaceId(spaceId).withFormat(format).withUpdateStrategy(UpdateStrategy.DEFAULT_UPDATE_STRATEGY));
475+
public static void runImportFilesToSpaceStep(String spaceId) throws IOException {
476+
runStep(new TaskedImportFilesToSpace().withSpaceId(spaceId).withUpdateStrategy(UpdateStrategy.DEFAULT_UPDATE_STRATEGY));
484477
}
485478

486479
public static void runCreateIndexStep(String spaceId, SystemIndex index) throws IOException {

xyz-jobs/xyz-job-service/src/main/java/com/here/xyz/jobs/steps/compiler/ImportFromFiles.java

Lines changed: 26 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2017-2025 HERE Europe B.V.
2+
* Copyright (C) 2017-2026 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,14 +19,6 @@
1919

2020
package com.here.xyz.jobs.steps.compiler;
2121

22-
import static com.here.xyz.jobs.steps.Step.InputSet.USER_INPUTS;
23-
import static com.here.xyz.jobs.steps.impl.transport.ImportFilesToSpace.Format.CSV_GEOJSON;
24-
import static com.here.xyz.jobs.steps.impl.transport.ImportFilesToSpace.Format.CSV_JSON_WKB;
25-
import static com.here.xyz.jobs.steps.impl.transport.ImportFilesToSpace.Format.GEOJSON;
26-
import static com.here.xyz.util.db.pg.IndexHelper.SystemIndex.NEXT_VERSION;
27-
import static com.here.xyz.util.db.pg.IndexHelper.SystemIndex.OPERATION;
28-
import static com.here.xyz.util.db.pg.IndexHelper.SystemIndex.VERSION_ID;
29-
3022
import com.google.common.collect.Lists;
3123
import com.here.xyz.jobs.Job;
3224
import com.here.xyz.jobs.datasets.DatasetDescription.Space;
@@ -42,35 +34,28 @@
4234
import com.here.xyz.jobs.steps.impl.AnalyzeSpaceTable;
4335
import com.here.xyz.jobs.steps.impl.CreateIndex;
4436
import com.here.xyz.jobs.steps.impl.DropIndexes;
45-
import com.here.xyz.jobs.steps.impl.transport.ImportFilesToSpace;
46-
import com.here.xyz.jobs.steps.impl.transport.ImportFilesToSpace.EntityPerLine;
47-
import com.here.xyz.jobs.steps.impl.transport.ImportFilesToSpace.Format;
4837
import com.here.xyz.jobs.steps.impl.transport.TaskedImportFilesToSpace;
4938
import com.here.xyz.models.hub.Ref;
5039
import com.here.xyz.util.db.pg.IndexHelper.Index;
5140
import com.here.xyz.util.db.pg.IndexHelper.SystemIndex;
5241
import com.here.xyz.util.web.HubWebClient;
5342
import com.here.xyz.util.web.XyzWebClient.ErrorResponseException;
5443
import com.here.xyz.util.web.XyzWebClient.WebClientException;
44+
5545
import java.util.HashSet;
5646
import java.util.List;
5747
import java.util.Set;
5848
import java.util.stream.Collectors;
5949
import java.util.stream.Stream;
6050

61-
public class ImportFromFiles implements JobCompilationInterceptor {
62-
public boolean useNewTaskedImportStep = true;
51+
import static com.here.xyz.jobs.steps.Step.InputSet.USER_INPUTS;
52+
import static com.here.xyz.util.db.pg.IndexHelper.SystemIndex.NEXT_VERSION;
53+
import static com.here.xyz.util.db.pg.IndexHelper.SystemIndex.OPERATION;
54+
import static com.here.xyz.util.db.pg.IndexHelper.SystemIndex.VERSION_ID;
6355

56+
public class ImportFromFiles implements JobCompilationInterceptor {
6457
public static Set<Class<? extends Space>> allowedTargetTypes = new HashSet<>(Set.of(Space.class));
6558

66-
public void setUseNewTaskedImportStep(boolean useNewTaskedImportStep) {
67-
this.useNewTaskedImportStep = useNewTaskedImportStep;
68-
}
69-
public ImportFromFiles withUseNewTaskedImportStep(boolean useNewTaskedImportStep) {
70-
setUseNewTaskedImportStep(useNewTaskedImportStep);
71-
return this;
72-
}
73-
7459
@Override
7560
public boolean chooseMe(Job job) {
7661
return job.getProcess() == null && job.getSource() instanceof Files files && isSupportedFormat(files)
@@ -87,52 +72,31 @@ public CompilationStepGraph compile(Job job) {
8772
String spaceId = target.getId();
8873

8974
final FileFormat sourceFormat = ((Files) job.getSource()).getInputSettings().getFormat();
90-
Format importStepFormat;
91-
if (sourceFormat instanceof GeoJson)
92-
importStepFormat = GEOJSON;
93-
else if (sourceFormat instanceof Csv csvFormat)
94-
importStepFormat = csvFormat.isGeometryAsExtraWkbColumn() ? CSV_JSON_WKB : CSV_GEOJSON;
95-
else
96-
throw new CompilationError("Unsupported import file format: " + sourceFormat.getClass().getSimpleName());
9775

98-
EntityPerLine entityPerLine = getEntityPerLine(sourceFormat);
76+
if (!(sourceFormat instanceof GeoJson))
77+
throw new CompilationError("Unsupported import file format: " + sourceFormat.getClass().getSimpleName());
9978

10079
//This validation check is necessary to deliver a constructive error to the user - otherwise keepIndices will throw a runtime error.
10180
checkIfSpaceIsAccessible(spaceId);
10281

103-
if(useNewTaskedImportStep) {
104-
if(!entityPerLine.equals(EntityPerLine.Feature))
105-
throw new CompilationError("TaskedImportStep - Unsupported entityPerLine configuration: " + entityPerLine.name());
106-
if(!(sourceFormat instanceof GeoJson))
107-
throw new CompilationError("TaskedImportStep - Unsupported format configuration: " + sourceFormat.getClass().getSimpleName());
108-
109-
TaskedImportFilesToSpace importFilesStep = new TaskedImportFilesToSpace() //Perform import
110-
.withSpaceId(spaceId)
111-
.withVersionRef(new Ref(Ref.HEAD))
112-
.withJobId(job.getId())
113-
.withInputSets(List.of(USER_INPUTS.get()));
114-
if (importFilesStep.keepIndices())
115-
//Perform only the import Step
116-
return (CompilationStepGraph) new CompilationStepGraph()
117-
.addExecution(importFilesStep);
82+
TaskedImportFilesToSpace importFilesStep = new TaskedImportFilesToSpace() //Perform import
83+
.withEntityPerLine(getEntityPerLine(sourceFormat))
84+
.withSpaceId(spaceId)
85+
.withVersionRef(new Ref(Ref.HEAD))
86+
.withJobId(job.getId())
87+
.withInputSets(List.of(USER_INPUTS.get()));
11888

119-
//perform full Import with all 11 Steps (IDX deletion/creation..)
120-
return compileTaskedImportSteps(importFilesStep);
121-
}else{
122-
ImportFilesToSpace importFilesStep = new ImportFilesToSpace() //Perform import
123-
.withSpaceId(spaceId)
124-
.withFormat(importStepFormat)
125-
.withEntityPerLine(entityPerLine)
126-
.withJobId(job.getId())
127-
.withInputSets(List.of(USER_INPUTS.get()));
128-
if (importFilesStep.keepIndices())
89+
try {
90+
if (importFilesStep.useFeatureWriter())
12991
//Perform only the import Step
13092
return (CompilationStepGraph) new CompilationStepGraph()
13193
.addExecution(importFilesStep);
132-
133-
//perform full Import with all 11 Steps (IDX deletion/creation..)
134-
return compileImportSteps(importFilesStep);
94+
} catch (WebClientException e) {
95+
throw new CompilationError("Error retrieving statistics for target resource during compilation!", e);
13596
}
97+
98+
//perform full Import with all 11 Steps (IDX deletion/creation..)
99+
return compileTaskedImportSteps(importFilesStep);
136100
}
137101

138102
public static CompilationStepGraph compileWrapWithDropRecreateIndices(String spaceId, StepExecution stepExecution) {
@@ -179,20 +143,10 @@ public static CompilationStepGraph compileTaskedImportSteps(TaskedImportFilesToS
179143
}
180144
}
181145

182-
public static CompilationStepGraph compileImportSteps(ImportFilesToSpace importFilesStep) {
183-
try {
184-
//Keep these indices if FeatureWriter is used
185-
List<Index> whiteListIndex = importFilesStep.useFeatureWriter() ? List.of(VERSION_ID, NEXT_VERSION, OPERATION) : null;
186-
return compileWrapWithDropRecreateIndices(importFilesStep.getSpaceId(), importFilesStep, whiteListIndex);
187-
} catch (WebClientException e) {
188-
throw new CompilationError("Unexpected error occurred during compilation", e);
189-
}
190-
}
191-
192-
private EntityPerLine getEntityPerLine(FileFormat format) {
193-
return EntityPerLine.valueOf((format instanceof GeoJson geoJson
194-
? geoJson.getEntityPerLine()
195-
: ((Csv) format).getEntityPerLine()).toString());
146+
private TaskedImportFilesToSpace.EntityPerLine getEntityPerLine(FileFormat format) {
147+
return TaskedImportFilesToSpace.EntityPerLine.valueOf((format instanceof GeoJson geoJson
148+
? geoJson.getEntityPerLine()
149+
: ((Csv) format).getEntityPerLine()).toString());
196150
}
197151

198152
private static List<StepExecution> toSequentialSteps(String spaceId, List<SystemIndex> indices) {

xyz-jobs/xyz-job-service/src/test/java/com/here/xyz/jobs/ImportJobTestIT.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import com.here.xyz.jobs.datasets.files.GeoJson;
2626
import com.here.xyz.jobs.steps.JobCompiler;
2727
import com.here.xyz.jobs.steps.compiler.ImportFromFiles;
28-
import com.here.xyz.jobs.steps.impl.transport.ImportFilesToSpace;
2928
import com.here.xyz.jobs.util.test.ContentCreator;
3029
import com.here.xyz.models.hub.Space;
3130
import org.junit.jupiter.api.Assertions;
@@ -46,12 +45,13 @@
4645
public class ImportJobTestIT extends JobTest {
4746
@BeforeEach
4847
public void setUp() {
49-
createSpace(new Space().withId(SPACE_ID).withSearchableProperties(Map.of(
48+
createSpace(new Space().withId(SPACE_ID).withVersionsToKeep(10000).withSearchableProperties(Map.of(
5049
"foo1", true,
5150
"foo2.nested", true,
5251
"foo3.nested.array::array", true
5352
)
5453
), false);
54+
putRandomFeatureCollectionToSpace(SPACE_ID, 10);
5555
}
5656

5757
@Test
@@ -60,7 +60,7 @@ public void testSimpleImport() throws Exception {
6060
new FileInputSettings()
6161
.withFormat(new GeoJson().withEntityPerLine(Feature)))
6262
);
63-
createAndStartJob(importJob, ContentCreator.generateImportFileContent(ImportFilesToSpace.Format.GEOJSON, 50));
63+
createAndStartJob(importJob, ContentCreator.generateImportFileContent(50));
6464
}
6565

6666
@Test
@@ -71,7 +71,6 @@ public void testInvalidEntity() throws Exception {
7171
);
7272
Assertions.assertThrows(JobCompiler.CompilationError.class, () ->
7373
new ImportFromFiles()
74-
.withUseNewTaskedImportStep(true)
7574
.compile(importJob));
7675
}
7776

@@ -82,7 +81,6 @@ public void testInvalidFormat() throws Exception {
8281
.withFormat(new Csv().withEntityPerLine(Feature))));
8382
Assertions.assertThrows(JobCompiler.CompilationError.class, () ->
8483
new ImportFromFiles()
85-
.withUseNewTaskedImportStep(true)
8684
.compile(importJob));
8785
}
8886

xyz-jobs/xyz-job-service/src/test/java/com/here/xyz/jobs/steps/execution/JobExecutorTests.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import static com.here.xyz.jobs.steps.Step.Visibility.SYSTEM;
2323
import static com.here.xyz.jobs.steps.impl.transport.ExportSpaceToFiles.EXPORTED_DATA;
24-
import static com.here.xyz.jobs.steps.impl.transport.ImportFilesToSpace.Format.GEOJSON;
2524
import static org.junit.jupiter.api.Assertions.assertEquals;
2625
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
2726
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -34,7 +33,6 @@
3433
import com.here.xyz.jobs.steps.StepExecution;
3534
import com.here.xyz.jobs.steps.StepGraph;
3635
import com.here.xyz.jobs.steps.impl.transport.ExportSpaceToFiles;
37-
import com.here.xyz.jobs.steps.impl.transport.ImportFilesToSpace;
3836
import java.net.URI;
3937
import java.net.URISyntaxException;
4038
import java.util.ArrayList;
@@ -43,6 +41,8 @@
4341
import java.util.Objects;
4442
import java.util.Set;
4543
import java.util.stream.Collectors;
44+
45+
import com.here.xyz.jobs.steps.impl.transport.TaskedImportFilesToSpace;
4646
import org.junit.jupiter.api.Assertions;
4747
import org.junit.jupiter.api.Disabled;
4848
import org.junit.jupiter.api.Test;
@@ -119,7 +119,7 @@ public void testReuseSequentialGraphWithInputIds() {
119119
StepGraph graph1 = new CompilationStepGraph()
120120
.withExecutions(List.of(
121121
exportStep1,
122-
stepGenerator(ImportFilesToSpace.class, JOB_ID1, SOURCE_ID2, Set.of(exportStep1.getId()))
122+
stepGenerator(TaskedImportFilesToSpace.class, JOB_ID1, SOURCE_ID2, Set.of(exportStep1.getId()))
123123
))
124124
.withParallel(false);
125125
((CompilationStepGraph) graph1).enrich(JOB_ID1);
@@ -129,7 +129,7 @@ public void testReuseSequentialGraphWithInputIds() {
129129
StepGraph graph2 = new CompilationStepGraph()
130130
.withExecutions(List.of(
131131
exportStep2,
132-
stepGenerator(ImportFilesToSpace.class, JOB_ID2, SOURCE_ID2, Set.of(exportStep2.getId())) //not reusable
132+
stepGenerator(TaskedImportFilesToSpace.class, JOB_ID2, SOURCE_ID2, Set.of(exportStep2.getId())) //not reusable
133133
))
134134
.withParallel(false);
135135
((CompilationStepGraph) graph2).enrich(JOB_ID1);
@@ -147,7 +147,7 @@ public void testReuseSequentialGraphWithInputIds() {
147147
Step execution2 = (Step) graph.getExecutions().get(1);
148148

149149
assertInstanceOf(DelegateStep.class, execution1);
150-
assertInstanceOf(ImportFilesToSpace.class, execution2);
150+
assertInstanceOf(TaskedImportFilesToSpace.class, execution2);
151151

152152
//Check if previousStepIds are set correct
153153
assertEquals(Set.of(execution1.getId()), execution2.getPreviousStepIds());
@@ -417,9 +417,8 @@ public StepExecution stepGenerator(Class stepType, String jobId, String sourceId
417417
.withJobId(jobId)
418418
.withOutputSetVisibility(EXPORTED_DATA, SYSTEM);
419419

420-
case "ImportFilesToSpace" -> {
421-
ImportFilesToSpace importFilesToSpace = new ImportFilesToSpace()
422-
.withFormat(GEOJSON)
420+
case "TaskedImportFilesToSpace" -> {
421+
TaskedImportFilesToSpace importFilesToSpace = new TaskedImportFilesToSpace()
423422
.withSpaceId(sourceId)
424423
.withJobId(jobId);
425424
if (inputStepIds != null)

xyz-jobs/xyz-job-steps/src/main/java/com/here/xyz/jobs/steps/impl/SpaceBasedStep.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import com.here.xyz.jobs.steps.impl.transport.ExportChangedTiles;
4545
import com.here.xyz.jobs.steps.impl.transport.ExportSpaceToFiles;
4646
import com.here.xyz.jobs.steps.impl.transport.GetNextSpaceVersion;
47-
import com.here.xyz.jobs.steps.impl.transport.ImportFilesToSpace;
4847
import com.here.xyz.jobs.steps.impl.transport.TaskedImportFilesToSpace;
4948
import com.here.xyz.models.hub.Branch;
5049
import com.here.xyz.models.hub.Connector;
@@ -67,7 +66,6 @@
6766
@JsonSubTypes.Type(value = CreateIndex.class),
6867
@JsonSubTypes.Type(value = ExportSpaceToFiles.class),
6968
@JsonSubTypes.Type(value = ExportChangedTiles.class),
70-
@JsonSubTypes.Type(value = ImportFilesToSpace.class),
7169
@JsonSubTypes.Type(value = TaskedImportFilesToSpace.class),
7270
@JsonSubTypes.Type(value = DropIndexes.class),
7371
@JsonSubTypes.Type(value = AnalyzeSpaceTable.class),

0 commit comments

Comments
 (0)