Skip to content

Commit

Permalink
Replace CTE with subquery in PostgresTileStore and do some cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
bchapuis committed Nov 26, 2023
1 parent 2fc612d commit 5e08ba7
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 40 deletions.
7 changes: 6 additions & 1 deletion .run/basemap-dev.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
<configuration default="false" name="basemap-dev" type="Application" factoryName="Application">
<option name="MAIN_CLASS_NAME" value="org.apache.baremaps.cli.Baremaps" />
<module name="baremaps-cli" />
<option name="PROGRAM_PARAMETERS" value="map dev --tileset tileset.js --style style.js" />
<option name="PROGRAM_PARAMETERS" value="map dev --tileset tileset.js --style style.js --log-level DEBUG" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/basemap" />
<extension name="software.aws.toolkits.jetbrains.core.execution.JavaAwsConnectionExtension">
<option name="credential" />
<option name="region" />
<option name="useCurrentConnection" value="false" />
</extension>
<method v="2">
<option name="Make" enabled="true" />
</method>
Expand Down
11 changes: 0 additions & 11 deletions .run/basemap-export-mbtiles.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,6 @@
<module name="baremaps-cli" />
<option name="PROGRAM_PARAMETERS" value="map export --tileset tileset.js --repository tiles.mbtiles --format mbtiles" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/basemap" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="org.apache.baremaps.server.ogcapi.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<extension name="software.aws.toolkits.jetbrains.core.execution.JavaAwsConnectionExtension">
<option name="credential" />
<option name="region" />
<option name="useCurrentConnection" value="false" />
</extension>
<method v="2">
<option name="Make" enabled="true" />
</method>
Expand Down
11 changes: 0 additions & 11 deletions .run/basemap-export-pmtiles.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,6 @@
<module name="baremaps-cli" />
<option name="PROGRAM_PARAMETERS" value="map export --tileset tileset.js --repository tiles.mbtiles --format pmtiles" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/basemap" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="org.apache.baremaps.server.ogcapi.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<extension name="software.aws.toolkits.jetbrains.core.execution.JavaAwsConnectionExtension">
<option name="credential" />
<option name="region" />
<option name="useCurrentConnection" value="false" />
</extension>
<method v="2">
<option name="Make" enabled="true" />
</method>
Expand Down
5 changes: 0 additions & 5 deletions .run/basemap-workflow.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
<module name="baremaps-cli" />
<option name="PROGRAM_PARAMETERS" value="workflow execute --file import.js" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/basemap" />
<extension name="software.aws.toolkits.jetbrains.core.execution.JavaAwsConnectionExtension">
<option name="credential" />
<option name="region" />
<option name="useCurrentConnection" value="false" />
</extension>
<method v="2">
<option name="Make" enabled="true" />
</method>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,8 @@ public static Entry findTile(List<Entry> entries, long tileId) {
public static Directories buildRootLeaves(List<Entry> entries, int leafSize) throws IOException {
var rootEntries = new ArrayList<Entry>();
var numLeaves = 0;
byte[] leavesBytes = null;
byte[] rootBytes = null;
byte[] leavesBytes;
byte[] rootBytes;

try (var leavesOutput = new ByteArrayOutputStream();
var leavesDataOutput = new LittleEndianDataOutputStream(leavesOutput)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,12 @@ public Header getHeader() {
public List<Entry> getRootDirectory() {
if (rootEntries == null) {
var header = getHeader();
rootEntries =
getDirectory(header.getRootDirectoryOffset(), (int) header.getRootDirectoryLength());
rootEntries = getDirectory(header.getRootDirectoryOffset());
}
return rootEntries;
}

public List<Entry> getDirectory(long offset, int length) {
public List<Entry> getDirectory(long offset) {
var header = getHeader();
try (var input = Files.newInputStream(path)) {
input.skip(offset);

Check notice

Code scanning / CodeQL

Ignored error status of call Note

Method getDirectory ignores exceptional return value of InputStream.skip.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public ByteBuffer read(TileCoord tileCoord) throws TileStoreException {
protected static Query prepareQuery(Tileset tileset, int zoom) {
// Initialize a builder for the tile sql
var tileSql = new StringBuilder();
tileSql.append("SELECT (");
tileSql.append("SELECT ");

// Iterate over the layers and keep track of the number of layers and parameters included in the
// final sql
Expand All @@ -139,7 +139,7 @@ protected static Query prepareQuery(Tileset tileset, int zoom) {

// Initialize a builder for the layer sql
var layerSql = new StringBuilder();
var layerHead = "(WITH mvtGeom AS (";
var layerHead = String.format("(SELECT ST_AsMVT(mvtGeom.*, '%s') FROM (", layer.getId());
layerSql.append(layerHead);

// Iterate over the queries and keep track of the number of queries included in the final
Expand Down Expand Up @@ -175,8 +175,7 @@ protected static Query prepareQuery(Tileset tileset, int zoom) {
}

// Add the tail of the layer sql
var layerQueryTail =
String.format(") SELECT ST_AsMVT(mvtGeom.*, '%s') FROM mvtGeom)", layer.getId());
var layerQueryTail = ") AS mvtGeom)";
layerSql.append(layerQueryTail);

// Only include the layer sql if queries were included for this layer
Expand All @@ -196,7 +195,7 @@ protected static Query prepareQuery(Tileset tileset, int zoom) {
}

// Add the tail of the tile sql
var tileQueryTail = ") mvtTile";
var tileQueryTail = " mvtTile";
tileSql.append(tileQueryTail);

// Format the sql query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,6 @@ void encodeHeader() throws IOException {
var output = new LittleEndianDataOutputStream(array);
PMTiles.serializeHeader(output, header);

var array2 = array.toByteArray();

var input = new LittleEndianDataInputStream(new ByteArrayInputStream(array.toByteArray()));
var header2 = PMTiles.deserializeHeader(input);

Expand Down

0 comments on commit 5e08ba7

Please sign in to comment.