Skip to content

Commit be39ce2

Browse files
committed
DS-1723,DS-1841:
* Introduce new Connector "PSQLXyzNLConnector". * Add new TableLayout "OLD_LAYOUT_WITH_SEARCHABLE". * Start implementing support for index creation on searchable columns. Signed-off-by: mchrza <[email protected]>
1 parent 3d46e2f commit be39ce2

File tree

9 files changed

+192
-189
lines changed

9 files changed

+192
-189
lines changed

xyz-hub-service/src/main/resources/connectors.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
"type": "Embedded",
7676
"id": "xyz-psql-local",
7777
"warmUp": 1,
78-
"className": "com.here.xyz.psql.PSQLXyzConnector",
78+
"className": "com.here.xyz.psql.PSQLXyzNLConnector",
7979
"env": {
8080
"ECPS_PHRASE": "local"
8181
},

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.here.xyz.jobs.steps.impl.tools.ResourceAndTimeCalculator;
2525
import com.here.xyz.jobs.steps.resources.Load;
2626
import com.here.xyz.jobs.steps.resources.TooManyResourcesClaimed;
27+
import com.here.xyz.util.db.ConnectorParameters;
2728
import com.here.xyz.util.db.SQLQuery;
2829
import com.here.xyz.util.db.pg.IndexHelper;
2930
import com.here.xyz.util.db.pg.IndexHelper.Index;
@@ -131,9 +132,11 @@ private SQLQuery buildOnDemandIndexCreationQuery(OnDemandIndex onDemandIndex) th
131132
List<SQLQuery> indexCreationQueries = new ArrayList<>();
132133

133134
indexCreationQueries.addAll(loadPartitionNamesOf(rootTableName).stream()
134-
.map(partitionTableName -> new SQLQuery(IndexHelper.buildOnDemandIndexCreationQuery(schema, partitionTableName, onDemandIndex.getPropertyPath(), true).toExecutableQueryString()))
135+
.map(partitionTableName -> new SQLQuery(IndexHelper.buildOnDemandIndexCreationQuery(schema, partitionTableName, onDemandIndex,
136+
ConnectorParameters.TableLayout.OLD_LAYOUT, true).toExecutableQueryString()))
135137
.toList());
136-
indexCreationQueries.add(new SQLQuery(IndexHelper.buildOnDemandIndexCreationQuery(schema, rootTableName, onDemandIndex.getPropertyPath(),true).toExecutableQueryString()));
138+
indexCreationQueries.add(new SQLQuery(IndexHelper.buildOnDemandIndexCreationQuery(schema, rootTableName,
139+
onDemandIndex, ConnectorParameters.TableLayout.OLD_LAYOUT,true).toExecutableQueryString()));
137140

138141
return SQLQuery.join(indexCreationQueries, ";");
139142
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,8 @@ private void startTask(TaskProgress<I> taskProgressAndItem) throws TooManyResour
406406

407407
@Override
408408
public void execute(boolean resume) throws Exception {
409+
infoLog(STEP_EXECUTE, "execute called with resume=" + resume);
410+
409411
//The following code is running synchronously till the first task is getting started.
410412
String schema = getSchema(db());
411413
if (!resume) {
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (C) 2017-2025 HERE Europe B.V.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
* License-Filename: LICENSE
18+
*/
19+
20+
package com.here.xyz.psql;
21+
22+
import com.here.xyz.events.ModifySpaceEvent;
23+
import com.here.xyz.psql.query.ModifySpace;
24+
import com.here.xyz.responses.SuccessResponse;
25+
26+
import static com.here.xyz.util.db.ConnectorParameters.TableLayout.OLD_LAYOUT_WITH_SEARCHABLE;
27+
28+
public class PSQLXyzNLConnector extends PSQLXyzConnector {
29+
30+
@Override
31+
protected SuccessResponse processModifySpaceEvent(ModifySpaceEvent event) throws Exception {
32+
return write(new ModifySpace(event).withTableLayout(OLD_LAYOUT_WITH_SEARCHABLE));
33+
}
34+
}

xyz-psql-connector/src/main/java/com/here/xyz/psql/query/ModifySpace.java

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import static com.here.xyz.events.ModifySpaceEvent.Operation.UPDATE;
2626
import static com.here.xyz.psql.query.helpers.versioning.GetNextVersion.VERSION_SEQUENCE_SUFFIX;
2727
import static com.here.xyz.responses.XyzError.ILLEGAL_ARGUMENT;
28-
import static com.here.xyz.util.db.ConnectorParameters.TableLayout.NEW_LAYOUT;
2928
import static com.here.xyz.util.db.pg.XyzSpaceTableHelper.SCHEMA;
3029
import static com.here.xyz.util.db.pg.XyzSpaceTableHelper.TABLE;
3130
import static com.here.xyz.util.db.pg.XyzSpaceTableHelper.buildCreateSpaceTableQueries;
@@ -45,22 +44,8 @@
4544
import java.util.List;
4645
import static com.here.xyz.util.db.pg.XyzSpaceTableHelper.buildCleanUpQuery;
4746
import static com.here.xyz.util.db.pg.IndexHelper.getActivatedSearchableProperties;
48-
import static com.here.xyz.util.db.ConnectorParameters.TableLayout.OLD_LAYOUT;
49-
50-
import com.fasterxml.jackson.databind.node.ObjectNode;
51-
import com.here.xyz.connectors.ErrorResponseException;
52-
import com.here.xyz.events.ModifySpaceEvent;
53-
import com.here.xyz.events.ModifySpaceEvent.Operation;
54-
import com.here.xyz.responses.SuccessResponse;
55-
import com.here.xyz.util.db.ConnectorParameters;
56-
import com.here.xyz.util.db.SQLQuery;
57-
import com.here.xyz.util.db.datasource.DataSourceProvider;
58-
import com.here.xyz.util.db.pg.IndexHelper;
59-
import com.here.xyz.util.db.pg.XyzSpaceTableHelper;
60-
import java.sql.ResultSet;
61-
import java.sql.SQLException;
62-
import java.util.ArrayList;
63-
import java.util.List;
47+
import static com.here.xyz.util.db.ConnectorParameters.TableLayout;
48+
import static com.here.xyz.util.db.ConnectorParameters.TableLayout.NEW_LAYOUT;
6449

6550
public class ModifySpace extends ExtendedSpace<ModifySpaceEvent, SuccessResponse> {
6651

@@ -140,7 +125,9 @@ private void validateModifySpaceEvent(ModifySpaceEvent event) throws ErrorRespon
140125

141126
@Override
142127
protected SQLQuery buildQuery(ModifySpaceEvent event) throws SQLException {
143-
if(getTableLayout().equals(ConnectorParameters.TableLayout.OLD_LAYOUT)){
128+
TableLayout tableLayout = getTableLayout();
129+
130+
if(tableLayout.isOld()){
144131
if (event.getOperation() == CREATE || event.getOperation() == UPDATE) {
145132
List<SQLQuery> queries = new ArrayList<>();
146133
final String table = getDefaultTable(event);
@@ -151,7 +138,7 @@ protected SQLQuery buildQuery(ModifySpaceEvent event) throws SQLException {
151138
= getActivatedSearchableProperties(event.getSpaceDefinition().getSearchableProperties());
152139

153140
queries.addAll(buildCreateSpaceTableQueries(getSchema(), table, activatedSearchableProperties,
154-
event.getSpace(), OLD_LAYOUT));
141+
event.getSpace(), tableLayout));
155142
}
156143

157144
//Write metadata
@@ -160,20 +147,20 @@ protected SQLQuery buildQuery(ModifySpaceEvent event) throws SQLException {
160147
return SQLQuery.batchOf(queries).withLock(table);
161148
}
162149
else if (event.getOperation() == DELETE) {
163-
return SQLQuery.batchOf(buildCleanUpQuery(event, getSchema(), getDefaultTable(event), VERSION_SEQUENCE_SUFFIX, OLD_LAYOUT));
150+
return SQLQuery.batchOf(buildCleanUpQuery(event, getSchema(), getDefaultTable(event), VERSION_SEQUENCE_SUFFIX, tableLayout));
164151
}
165-
}else if(getTableLayout().equals(ConnectorParameters.TableLayout.NEW_LAYOUT)){
152+
}else if(tableLayout.equals(NEW_LAYOUT)){
166153
if (event.getOperation() == CREATE) {
167154
final String table = getDefaultTable(event);
168155
List<SQLQuery> queries = new ArrayList<>(buildCreateSpaceTableQueries(getSchema(), table,
169156
//No OnDemandIndices are supported in V2
170-
null, event.getSpace(), NEW_LAYOUT));
157+
null, event.getSpace(), tableLayout));
171158
return SQLQuery.batchOf(queries).withLock(table);
172159
}
173160
else if (event.getOperation() == DELETE)
174-
return SQLQuery.batchOf(buildCleanUpQuery(event, getSchema(), getDefaultTable(event), VERSION_SEQUENCE_SUFFIX, NEW_LAYOUT));
161+
return SQLQuery.batchOf(buildCleanUpQuery(event, getSchema(), getDefaultTable(event), VERSION_SEQUENCE_SUFFIX, tableLayout));
175162
}
176-
throw new IllegalArgumentException("Unsupported Table Layout: " + getTableLayout());
163+
throw new IllegalArgumentException("Unsupported Table Layout: " + tableLayout);
177164
}
178165

179166
@Override

xyz-psql-connector/src/test/java/com/here/xyz/psql/PSQLIndexIT.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.here.xyz.responses.StatisticsResponse;
2828
import com.here.xyz.responses.SuccessResponse;
2929
import com.here.xyz.responses.XyzError;
30+
import com.here.xyz.util.db.ConnectorParameters;
3031
import com.here.xyz.util.db.pg.IndexHelper.OnDemandIndex;
3132
import org.junit.After;
3233
import org.junit.Before;
@@ -182,7 +183,7 @@ public void testOnDemandIdxCreation() throws Exception {
182183
List<OnDemandIndex> activatedSearchableProperties = getActivatedSearchableProperties(searchableProperties);
183184

184185
for(OnDemandIndex onDemandIndex : activatedSearchableProperties)
185-
stmt.execute(buildOnDemandIndexCreationQuery("public", "foo", onDemandIndex.getPropertyPath(), false).toExecutableQueryString());
186+
stmt.execute(buildOnDemandIndexCreationQuery("public", "foo", onDemandIndex, ConnectorParameters.TableLayout.OLD_LAYOUT, false).toExecutableQueryString());
186187

187188
// Check which Indices are available
188189
ResultSet resultSet = stmt.executeQuery( DhString.format("select idx_property, src from xyz_index_list_all_available(%s, 'foo');",sqlSpaceSchema));

xyz-util/src/main/java/com/here/xyz/util/db/ConnectorParameters.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,23 @@ public class ConnectorParameters {
4040

4141
private TableLayout tableLayout;
4242
public enum TableLayout {
43-
OLD_LAYOUT, NEW_LAYOUT;
43+
OLD_LAYOUT(false),
44+
OLD_LAYOUT_WITH_SEARCHABLE(true),
45+
NEW_LAYOUT(false);
46+
47+
private final boolean hasSearchableColumn;
48+
49+
TableLayout(boolean hasSearchableColumn) {
50+
this.hasSearchableColumn = hasSearchableColumn;
51+
}
52+
53+
public boolean hasSearchableColumn() {
54+
return hasSearchableColumn;
55+
}
56+
57+
public boolean isOld() {
58+
return this == OLD_LAYOUT || this == OLD_LAYOUT_WITH_SEARCHABLE;
59+
}
4460
}
4561

4662
public ConnectorParameters() {}

0 commit comments

Comments
 (0)