Skip to content

Commit 6097e82

Browse files
authored
Bug/sc 253458/error casting string to utf8 (#311)
- Fix - Fixed the error casting string to UTD8String in GeomReproject function
1 parent c75c127 commit 6097e82

File tree

9 files changed

+36
-17
lines changed

9 files changed

+36
-17
lines changed

clouds/databricks/CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ Changelog for databricks cloud. All notable changes to this project will be docu
33

44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
55

6+
## [1.0.3] - 2022-09-06
7+
8+
### Fixed
9+
- [accessors] Fix the bug in ST_COORDDIM that was adding z coordinate to geometries.
10+
- [indexing] Fix the cast ClassCastException in ST_GEOMREPROJECT.
11+
612
## [1.0.2] - 2022-09-01
713

814
### Changed

clouds/databricks/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ deploy-modules:
3939

4040
test:
4141
$(MAKE) test-modules
42+
$(MAKE) test-libraries
4243

4344
test-libraries:
4445
$(MAKE) -C libraries/scala test

clouds/databricks/libraries/scala/core/src/main/scala/com/carto/analyticstoolbox/modules/index/package.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import org.apache.spark.sql.types.{DataType, StringType}
1313

1414
package object index extends StandardEncoders {
1515
implicit def crsConverter: HConverter[CRS] = new HConverter[CRS] {
16-
def convert(argument: Any): CRS = CRS.fromString(argument.convert[String])
16+
def convert(argument: Any): CRS = CRS.fromString(argument.toString)
1717
}
1818

1919
implicit def extentConverter: HConverter[Extent] = new HConverter[Extent] {

clouds/databricks/libraries/scala/core/src/test/scala/com/carto/analyticstoolbox/modules/accessors/ST_CoordDimTest.scala

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package com.carto.analyticstoolbox.modules.accessors
22

3-
import com.carto.hiveless.spatial.util.TWKBUtils
4-
import org.locationtech.geomesa.spark.jts.udf.{GeometricConstructorFunctions, GeometricOutputFunctions}
5-
import org.locationtech.jts.geom.{Coordinate, CoordinateXY, Geometry, GeometryFactory, Point}
3+
import org.locationtech.geomesa.spark.jts.udf.GeometricConstructorFunctions
64
import org.scalatest.funspec.AnyFunSpec
75
import org.scalatest.matchers.should.Matchers.convertToAnyShouldWrapper
86

clouds/databricks/libraries/scala/core/src/test/scala/com/carto/analyticstoolbox/modules/index/STIndexSpec.scala

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ import org.scalatest.funspec.AnyFunSpec
2222
class STIndexSpec extends AnyFunSpec with HiveTestEnvironment with TestTables {
2323
describe("ST index functions spec") {
2424
it("ST_GEOMREPROJECT test") {
25-
val df2 = ssc.sql(
26-
"""SELECT ST_GEOMREPROJECT(ST_POINT(3, 5),
25+
val df = ssc.sql(
26+
"""SELECT ST_ASTEXT(ST_GEOMREPROJECT(ST_POINT(3, 5),
2727
|ST_CRSFROMTEXT('+proj=merc +lat_ts=56.5 +ellps=GRS80'),
28-
|ST_CRSFROMTEXT('+proj=longlat +ellps=GRS80 +datum=NAD83 +no_defs'))""".stripMargin
28+
|ST_CRSFROMTEXT('+proj=longlat +ellps=GRS80 +datum=NAD83 +no_defs')))""".stripMargin
2929
)
30-
print(df2.take(1).head.get(0))
30+
df.head.get(0) shouldEqual "POINT (0.0000269 0.0000452)"
3131
}
3232
}
3333
}
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
package com.carto.analyticstoolbox.modules.index
22

3-
import org.apache.spark.unsafe.types.UTF8String
43
import org.scalatest.funspec.AnyFunSpec
4+
import org.scalatest.matchers.should.Matchers.convertToAnyShouldWrapper
55

66
class ST_CrsFromTextTest extends AnyFunSpec {
77
describe("ST_CrsFromText") {
88
it ("Should return a CRS") {
9-
val cls = new ST_CrsFromText().function("+proj=merc +lat_ts=56.5 +ellps=GRS80")
10-
}
11-
it ("CRS string to utf8 string") {
12-
"+proj=merc +lat_ts=56.5 +ellps=GRS80".asInstanceOf[UTF8String] //esto falla
13-
UTF8String.fromString("+proj=merc +lat_ts=56.5 +ellps=GRS80") //esto no
9+
val crs = new ST_CrsFromText().function("+proj=merc +lat_ts=56.5 +ellps=GRS80")
10+
crs.proj4jCrs.getName shouldEqual "merc-CS"
1411
}
1512
}
1613
}

clouds/databricks/modules/Makefile

+3-1
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,7 @@ remove: check
3434

3535
drop-udfs:
3636
sed -e 's/@@DB_CLUSTER_ID@@/${DB_CLUSTER_ID}/g' -e 's!@@SQLPath@@!$(SQL_DEPLOY_PATH)/dropUDF!g' $(COMMON_DIR)/submit-run-template.json > $(COMMON_DIR)/submit-run.json
37-
databricks runs submit --json-file $(COMMON_DIR)/submit-run.json
37+
databricks runs submit --json-file $(COMMON_DIR)/submit-run.json --wait
38+
echo "- Removing drop script from the workspace"
39+
databricks workspace rm -r $(SQL_DEPLOY_PATH)
3840
echo "- Modules removed"

clouds/databricks/modules/doc/indexing/ST_GEOMREPROJECT.md_x renamed to clouds/databricks/modules/doc/indexing/ST_GEOMREPROJECT.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ Transform a `Geometry` from The Common Reference System _crsA_ to _crsB_.
1919
**Example**
2020

2121
```sql
22-
23-
--
22+
WITH t AS (
23+
SELECT carto.ST_POINT(3, 5) AS point,
24+
carto.ST_CRSFROMTEXT('+proj=merc +lat_ts=56.5 +ellps=GRS80') AS crsa,
25+
carto.ST_CRSFROMTEXT('+proj=longlat +ellps=GRS80 +datum=NAD83 +no_defs') AS crsb
26+
) SELECT carto.ST_ASTEXT(carto.ST_GEOMREPROJECT(point, crsa, crsb)) FROM t;
27+
-- POINT (0.0000269 0.0000452)
2428
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from python_utils.test_utils import run_query
2+
3+
4+
def test_st_geomreproject_success():
5+
query = """WITH t AS (
6+
SELECT @@DB_SCHEMA@@.ST_POINT(3, 5) AS point,
7+
@@DB_SCHEMA@@.ST_CRSFROMTEXT('+proj=merc +lat_ts=56.5 +ellps=GRS80') AS crsa,
8+
@@DB_SCHEMA@@.ST_CRSFROMTEXT('+proj=longlat +ellps=GRS80 +datum=NAD83 +no_defs') AS crsb
9+
) SELECT @@DB_SCHEMA@@.ST_ASTEXT(@@DB_SCHEMA@@.ST_GEOMREPROJECT(point, crsa, crsb)) FROM t;"""
10+
result = run_query(query)
11+
assert result[0][0] == 'POINT (0.0000269 0.0000452)'

0 commit comments

Comments
 (0)