Skip to content

Commit c64b95a

Browse files
committed
Format code
1 parent 93960ee commit c64b95a

File tree

9 files changed

+121
-117
lines changed

9 files changed

+121
-117
lines changed

baremaps-calcite/src/main/java/org/apache/baremaps/calcite/flatgeobuf/FlatGeoBufTable.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public FlatGeoBufTable(File file) throws IOException {
6262
this.file = file;
6363
this.reader = new FlatGeoBufReader(FileChannel.open(file.toPath(), StandardOpenOption.READ));
6464
this.tableName = file.getName();
65-
65+
6666
// Read header to get columns information
6767
FlatGeoBuf.Header header = reader.readHeader();
6868
this.columns = header.columns();
@@ -89,12 +89,12 @@ private RelDataType createRowType(RelDataTypeFactory typeFactory) {
8989
for (FlatGeoBuf.Column column : columns) {
9090
SqlTypeName sqlTypeName = mapFlatGeoBufTypeToSqlType(column.type());
9191
RelDataType fieldType = typeFactory.createSqlType(sqlTypeName);
92-
92+
9393
// Handle nullability
9494
if (column.nullable()) {
9595
fieldType = typeFactory.createTypeWithNullability(fieldType, true);
9696
}
97-
97+
9898
builder.add(column.name(), fieldType);
9999
}
100100

@@ -178,10 +178,10 @@ public boolean moveNext() {
178178

179179
// Convert feature to row
180180
List<Object> values = new ArrayList<>();
181-
181+
182182
// Add properties
183183
values.addAll(feature.properties());
184-
184+
185185
// Add geometry
186186
values.add(feature.geometry());
187187

baremaps-calcite/src/main/java/org/apache/baremaps/calcite/postgis/PostgisSchema.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@
3232
/**
3333
* A Calcite schema backed by PostGIS.
3434
*
35-
* <p>This schema exposes tables in a PostgreSQL database with PostGIS extensions
36-
* as Calcite tables.</p>
35+
* <p>
36+
* This schema exposes tables in a PostgreSQL database with PostGIS extensions as Calcite tables.
37+
* </p>
3738
*/
3839
public class PostgisSchema extends AbstractSchema {
3940

@@ -56,15 +57,15 @@ public PostgisSchema(DataSource dataSource, String schemaName) {
5657
protected Map<String, Table> getTableMap() {
5758
if (tableMap == null) {
5859
tableMap = new HashMap<>();
59-
60+
6061
try {
6162
// Use DatabaseMetadata to get all tables in the schema
6263
DatabaseMetadata metadata = new DatabaseMetadata(dataSource);
63-
var tables = metadata.getTableMetaData(null, schemaName, null, new String[]{"BASE TABLE"});
64-
64+
var tables = metadata.getTableMetaData(null, schemaName, null, new String[] {"BASE TABLE"});
65+
6566
// Find tables with geometry columns
6667
Set<String> tablesWithGeometry = findTablesWithGeometry();
67-
68+
6869
// Create a PostgisTable for each table with geometry columns
6970
for (TableMetadata tableMetadata : tables) {
7071
String tableName = tableMetadata.table().tableName();
@@ -76,10 +77,10 @@ protected Map<String, Table> getTableMap() {
7677
throw new RuntimeException("Error getting tables from schema: " + schemaName, e);
7778
}
7879
}
79-
80+
8081
return tableMap;
8182
}
82-
83+
8384
/**
8485
* Find all tables that have geometry columns.
8586
*
@@ -90,10 +91,10 @@ private Set<String> findTablesWithGeometry() throws SQLException {
9091
try (Connection connection = dataSource.getConnection()) {
9192
// Query to get all tables with geometry columns
9293
String sql = "SELECT DISTINCT f_table_name FROM geometry_columns WHERE f_table_schema = ?";
93-
94+
9495
try (var stmt = connection.prepareStatement(sql)) {
9596
stmt.setString(1, schemaName);
96-
97+
9798
try (ResultSet rs = stmt.executeQuery()) {
9899
Set<String> result = new java.util.HashSet<>();
99100
while (rs.next()) {
@@ -104,4 +105,4 @@ private Set<String> findTablesWithGeometry() throws SQLException {
104105
}
105106
}
106107
}
107-
}
108+
}

baremaps-calcite/src/main/java/org/apache/baremaps/calcite/postgis/PostgisSchemaFactory.java

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
package org.apache.baremaps.calcite.postgis;
1919

20+
import com.zaxxer.hikari.HikariConfig;
21+
import com.zaxxer.hikari.HikariDataSource;
2022
import java.sql.Connection;
2123
import java.sql.ResultSet;
2224
import java.sql.SQLException;
@@ -26,14 +28,14 @@
2628
import org.apache.calcite.schema.Schema;
2729
import org.apache.calcite.schema.SchemaFactory;
2830
import org.apache.calcite.schema.SchemaPlus;
29-
import com.zaxxer.hikari.HikariConfig;
30-
import com.zaxxer.hikari.HikariDataSource;
3131

3232
/**
3333
* A factory for {@link PostgisSchema} schemas.
3434
*
35-
* <p>This schema factory connects to a PostgreSQL database with PostGIS extensions
36-
* and exposes tables as Calcite tables.</p>
35+
* <p>
36+
* This schema factory connects to a PostgreSQL database with PostGIS extensions and exposes tables
37+
* as Calcite tables.
38+
* </p>
3739
*/
3840
public class PostgisSchemaFactory implements SchemaFactory {
3941

@@ -51,14 +53,14 @@ public Schema create(SchemaPlus parentSchema, String name, Map<String, Object> o
5153
String username = (String) operand.get("username");
5254
String password = (String) operand.get("password");
5355
String schema = (String) operand.getOrDefault("schema", "public");
54-
56+
5557
if (jdbcUrl == null) {
5658
throw new IllegalArgumentException("'jdbcUrl' must be specified");
5759
}
5860

5961
DataSource dataSource = createDataSource(jdbcUrl, username, password);
6062
validatePostgisAvailability(dataSource);
61-
63+
6264
return new PostgisSchema(dataSource, schema);
6365
}
6466

@@ -79,10 +81,10 @@ private static DataSource createDataSource(String jdbcUrl, String username, Stri
7981
config.setMaximumPoolSize(5);
8082
config.setAutoCommit(true);
8183
config.setConnectionTestQuery("SELECT 1");
82-
84+
8385
return new HikariDataSource(config);
8486
}
85-
87+
8688
/**
8789
* Validates that the database is PostgreSQL with PostGIS extension installed.
8890
*
@@ -92,15 +94,15 @@ private static DataSource createDataSource(String jdbcUrl, String username, Stri
9294
private static void validatePostgisAvailability(DataSource dataSource) {
9395
try (Connection connection = dataSource.getConnection()) {
9496
DatabaseMetadata metadata = new DatabaseMetadata(dataSource);
95-
97+
9698
// Get database metadata
9799
java.sql.DatabaseMetaData dbMetadata = connection.getMetaData();
98100
String productName = dbMetadata.getDatabaseProductName();
99-
101+
100102
if (!"PostgreSQL".equalsIgnoreCase(productName)) {
101103
throw new IllegalArgumentException("Database is not PostgreSQL: " + productName);
102104
}
103-
105+
104106
// Check for PostGIS extension
105107
try (ResultSet rs = connection.createStatement().executeQuery(
106108
"SELECT postgis_version()")) {
@@ -110,13 +112,14 @@ private static void validatePostgisAvailability(DataSource dataSource) {
110112
} catch (SQLException e) {
111113
throw new IllegalArgumentException("PostGIS extension not installed", e);
112114
}
113-
115+
114116
// Check for geometry_columns table
115117
try {
116-
var tables = metadata.getTableMetaData(null, "public", "geometry_columns",
117-
new String[]{"TABLE", "VIEW"});
118+
var tables = metadata.getTableMetaData(null, "public", "geometry_columns",
119+
new String[] {"TABLE", "VIEW"});
118120
if (tables.isEmpty()) {
119-
throw new IllegalArgumentException("geometry_columns table not found, PostGIS setup is incomplete");
121+
throw new IllegalArgumentException(
122+
"geometry_columns table not found, PostGIS setup is incomplete");
120123
}
121124
} catch (SQLException e) {
122125
throw new IllegalArgumentException("Failed to query geometry_columns table", e);
@@ -125,4 +128,4 @@ private static void validatePostgisAvailability(DataSource dataSource) {
125128
throw new RuntimeException("Failed to connect to PostgreSQL database", e);
126129
}
127130
}
128-
}
131+
}

baremaps-calcite/src/main/java/org/apache/baremaps/calcite/postgis/PostgisTable.java

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@
2020
import java.sql.*;
2121
import java.util.*;
2222
import javax.sql.DataSource;
23-
2423
import org.apache.baremaps.calcite.data.DataColumn;
2524
import org.apache.baremaps.calcite.data.DataColumnFixed;
2625
import org.apache.baremaps.calcite.data.DataSchema;
27-
import org.apache.baremaps.postgres.metadata.DatabaseMetadata;
2826
import org.apache.baremaps.postgres.metadata.ColumnResult;
27+
import org.apache.baremaps.postgres.metadata.DatabaseMetadata;
2928
import org.apache.calcite.DataContext;
3029
import org.apache.calcite.linq4j.AbstractEnumerable;
3130
import org.apache.calcite.linq4j.Enumerable;
@@ -40,8 +39,8 @@
4039
import org.locationtech.jts.io.WKBReader;
4140

4241
/**
43-
* A Calcite table implementation for PostGIS. This table allows querying spatial data
44-
* directly from a PostGIS-enabled PostgreSQL database.
42+
* A Calcite table implementation for PostGIS. This table allows querying spatial data directly from
43+
* a PostGIS-enabled PostgreSQL database.
4544
*/
4645
public class PostgisTable extends AbstractTable implements ScannableTable {
4746

@@ -69,7 +68,7 @@ public PostgisTable(DataSource dataSource, String tableName) throws SQLException
6968
* @param typeFactory the type factory
7069
* @throws SQLException if an SQL error occurs
7170
*/
72-
public PostgisTable(DataSource dataSource, String tableName, RelDataTypeFactory typeFactory)
71+
public PostgisTable(DataSource dataSource, String tableName, RelDataTypeFactory typeFactory)
7372
throws SQLException {
7473
this.dataSource = dataSource;
7574
this.tableName = tableName;
@@ -85,31 +84,32 @@ public PostgisTable(DataSource dataSource, String tableName, RelDataTypeFactory
8584
*/
8685
private DataSchema discoverSchema() throws SQLException {
8786
List<DataColumn> columns = new ArrayList<>();
88-
87+
8988
// Use DatabaseMetadata to get column information
9089
DatabaseMetadata metadata = new DatabaseMetadata(dataSource);
91-
var tableMetadata = metadata.getTableMetaData(null, null, tableName, new String[]{"TABLE", "VIEW"})
92-
.stream()
93-
.filter(meta -> meta.table().tableName().equalsIgnoreCase(tableName))
94-
.findFirst()
95-
.orElseThrow(() -> new SQLException("Table not found: " + tableName));
96-
90+
var tableMetadata =
91+
metadata.getTableMetaData(null, null, tableName, new String[] {"TABLE", "VIEW"})
92+
.stream()
93+
.filter(meta -> meta.table().tableName().equalsIgnoreCase(tableName))
94+
.findFirst()
95+
.orElseThrow(() -> new SQLException("Table not found: " + tableName));
96+
9797
// Get geometry column information separately since it's PostGIS specific
9898
Map<String, String> geometryTypes = getGeometryTypes();
99-
99+
100100
for (ColumnResult column : tableMetadata.columns()) {
101101
String columnName = column.columnName();
102102
String dataType = column.typeName();
103103
boolean isNullable = "YES".equalsIgnoreCase(column.isNullable());
104-
104+
105105
// Determine column cardinality
106-
DataColumn.Cardinality cardinality = isNullable ?
107-
DataColumn.Cardinality.OPTIONAL : DataColumn.Cardinality.REQUIRED;
108-
106+
DataColumn.Cardinality cardinality =
107+
isNullable ? DataColumn.Cardinality.OPTIONAL : DataColumn.Cardinality.REQUIRED;
108+
109109
// Create a data column based on the type
110110
RelDataTypeFactory typeFactory = new org.apache.calcite.jdbc.JavaTypeFactoryImpl();
111111
RelDataType relDataType;
112-
112+
113113
if ("geometry".equalsIgnoreCase(dataType) && geometryTypes.containsKey(columnName)) {
114114
// This is a geometry column
115115
relDataType = typeFactory.createSqlType(SqlTypeName.GEOMETRY);
@@ -118,13 +118,13 @@ private DataSchema discoverSchema() throws SQLException {
118118
relDataType = PostgisTypeConversion.postgresTypeToRelDataType(
119119
typeFactory, dataType);
120120
}
121-
121+
122122
columns.add(new DataColumnFixed(columnName, cardinality, relDataType));
123123
}
124-
124+
125125
return new DataSchema(tableName, columns);
126126
}
127-
127+
128128
/**
129129
* Gets geometry column types for the current table.
130130
*
@@ -133,14 +133,14 @@ private DataSchema discoverSchema() throws SQLException {
133133
*/
134134
private Map<String, String> getGeometryTypes() throws SQLException {
135135
Map<String, String> geometryTypes = new HashMap<>();
136-
136+
137137
try (Connection connection = dataSource.getConnection()) {
138138
// Query to get geometry column information
139139
String sql = "SELECT f_geometry_column, type FROM geometry_columns WHERE f_table_name = ?";
140-
140+
141141
try (PreparedStatement stmt = connection.prepareStatement(sql)) {
142142
stmt.setString(1, tableName);
143-
143+
144144
try (ResultSet rs = stmt.executeQuery()) {
145145
while (rs.next()) {
146146
String column = rs.getString("f_geometry_column");
@@ -150,10 +150,10 @@ private Map<String, String> getGeometryTypes() throws SQLException {
150150
}
151151
}
152152
}
153-
153+
154154
return geometryTypes;
155155
}
156-
156+
157157
@Override
158158
public RelDataType getRowType(RelDataTypeFactory typeFactory) {
159159
return rowType;
@@ -216,18 +216,18 @@ public PostgisEnumerator(DataSource dataSource, DataSchema schema) {
216216

217217
private String buildSelectQuery() {
218218
List<String> columnProjections = new ArrayList<>();
219-
219+
220220
for (DataColumn column : schema.columns()) {
221221
// Special handling for geometry columns to get WKB format
222222
if (column.sqlTypeName() == SqlTypeName.GEOMETRY) {
223-
columnProjections.add(String.format("ST_AsBinary(\"%s\") AS \"%s\"",
223+
columnProjections.add(String.format("ST_AsBinary(\"%s\") AS \"%s\"",
224224
column.name(), column.name()));
225225
} else {
226226
columnProjections.add(String.format("\"%s\"", column.name()));
227227
}
228228
}
229-
230-
return "SELECT " + String.join(", ", columnProjections) +
229+
230+
return "SELECT " + String.join(", ", columnProjections) +
231231
" FROM \"" + schema.name() + "\"";
232232
}
233233

@@ -236,15 +236,15 @@ private Object[] convertCurrentRow() throws SQLException {
236236
for (int i = 0; i < schema.columns().size(); i++) {
237237
DataColumn column = schema.columns().get(i);
238238
Object value;
239-
239+
240240
// Special handling for geometry columns
241241
if (column.sqlTypeName() == SqlTypeName.GEOMETRY) {
242242
byte[] wkb = resultSet.getBytes(i + 1);
243243
value = deserializeWkb(wkb);
244244
} else {
245245
value = resultSet.getObject(i + 1);
246246
}
247-
247+
248248
values[i] = value;
249249
}
250250
return values;
@@ -274,7 +274,7 @@ public boolean moveNext() {
274274
current = null;
275275
return false;
276276
}
277-
277+
278278
current = convertCurrentRow();
279279
hasNext = resultSet.next();
280280
return true;
@@ -321,4 +321,4 @@ public void close() {
321321
}
322322
}
323323
}
324-
}
324+
}

0 commit comments

Comments
 (0)