Skip to content

Commit

Permalink
PR #9 'ApplyLimitOffset' from mjohns-databricks/databricks-geotools-p…
Browse files Browse the repository at this point in the history
  • Loading branch information
mjohns-databricks committed Mar 6, 2023
1 parent 98911bc commit 5a29d84
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
4 changes: 2 additions & 2 deletions geotools-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ Additionally, for data engineering, you may want to install the following useful
- sedona (PyPI)
- shapely (PyPI)
- apache-sedona\[spark\] (PyPI)
- h3 (PyPI) (provided by Mosaic, JAR by DBR)
- geospark (PyPI) (provided by DBR)
- h3 (PyPI) (Optional)
- geospark (PyPI) (Optional)
- geopandas (PyPI) (Optional)

For instructions on how to install libraries on your cluster, see the [documentation here](https://docs.databricks.com/libraries/index.html).
Expand Down
6 changes: 3 additions & 3 deletions geotools-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
<modelVersion>4.0.0</modelVersion>

<groupId>com.databricks.geotools</groupId>
<artifactId>databricks-gt_0.0.2</artifactId>
<version>0.0.2-SNAPSHOT</version>
<artifactId>databricks-gt_0.0.5</artifactId>
<version>0.0.1-SNAPSHOT</version>

<name>databricks-gt_0.0.2</name>
<name>databricks-gt_0.0.5</name>
<url>http://www.databricks.com</url>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,16 @@ public void setMetadataTableName(String tableName) {

public DatabricksSQLDialect(JDBCDataStore dataStore, Integer refreshPeriod) {
super(dataStore);

LOGGER.fine("Creating DatabricksSQLDialect");

this.wktReader = new WKTReader(new GeometryFactory(new PrecisionModel(PrecisionModel.FLOATING), 4326));
this.wkbReader = ThreadLocal.withInitial(() -> new WKBReader(new GeometryFactory(new PrecisionModel(PrecisionModel.FLOATING), 4326)));
this.metadataTableName = GT_PK_METADATA;
this.refreshPeriod = refreshPeriod;
this.layersList = new LayersList();

LOGGER.fine("DatabricksSQLDialect creation complete");
}

@Override
Expand All @@ -48,9 +53,35 @@ public boolean includeTable(String schemaName, String tableName, Connection cx)
if (mtn == null) mtn = GT_PK_METADATA;

return layersList.includeTable(schemaName, tableName, mtn, dataStore, cx, refreshPeriod);

}

public LayersList getLayersList() {return layersList;}

@Override
public boolean isLimitOffsetSupported() {
LOGGER.fine("In DatabricksSQLDialect.isLimitOffsetSupported");

return true;
}

@Override
public void applyLimitOffset(StringBuffer sql, int limit, int offset) {
LOGGER.fine("In DatabricksSQLDialect.applyLimitOffset...");
LOGGER.fine("Value of of sql BEFORE limit is applied: " + sql);
LOGGER.fine("Value of of limit: " + limit);
LOGGER.fine("Value of of offset: " + offset);

if (limit >= 0 && limit < Integer.MAX_VALUE) {
sql.append(" LIMIT " + limit);
if (offset > 0) {
sql.append(" OFFSET " + offset);
}
} else if (offset > 0) {
sql.append(" LIMIT " + Integer.MAX_VALUE);
sql.append(" OFFSET " + offset);
}
LOGGER.fine("Value of of sql AFTER limit is applied: " + sql);

}

}

0 comments on commit 5a29d84

Please sign in to comment.