-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Back port new functionality to 24.1.x
- Loading branch information
1 parent
93246e4
commit 3336776
Showing
7 changed files
with
135 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/main/java/org/sheinbergon/dremio/udf/gis/STGeomFromGeoJson.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.sheinbergon.dremio.udf.gis; | ||
|
||
import com.dremio.exec.expr.SimpleFunction; | ||
import com.dremio.exec.expr.annotations.FunctionTemplate; | ||
import com.dremio.exec.expr.annotations.Output; | ||
import com.dremio.exec.expr.annotations.Param; | ||
|
||
import javax.inject.Inject; | ||
|
||
@FunctionTemplate( | ||
name = "ST_GeomFromGeoJSON", | ||
scope = FunctionTemplate.FunctionScope.SIMPLE, | ||
nulls = FunctionTemplate.NullHandling.INTERNAL) | ||
public class STGeomFromGeoJson implements SimpleFunction { | ||
|
||
@Param | ||
org.apache.arrow.vector.holders.NullableVarCharHolder jsonInput; | ||
|
||
@Output | ||
org.apache.arrow.vector.holders.NullableVarBinaryHolder binaryOutput; | ||
|
||
@Inject | ||
org.apache.arrow.memory.ArrowBuf buffer; | ||
|
||
public void setup() { | ||
} | ||
|
||
public void eval() { | ||
if (org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.isHolderSet(jsonInput)) { | ||
org.locationtech.jts.geom.Geometry geom = org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.toGeometryFromGeoJson(jsonInput); | ||
byte[] bytes = org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.toEWKB(geom); | ||
buffer = buffer.reallocIfNeeded(bytes.length); | ||
org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.populate(bytes, buffer, binaryOutput); | ||
} else { | ||
org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.markHolderNotSet(binaryOutput); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/test/kotlin/org/sheinbergon/dremio/udf/gis/STGeomFromGeoJsonTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.sheinbergon.dremio.udf.gis | ||
|
||
import org.apache.arrow.vector.holders.NullableVarBinaryHolder | ||
import org.apache.arrow.vector.holders.NullableVarCharHolder | ||
import org.sheinbergon.dremio.udf.gis.spec.GeometryInputFunSpec | ||
import org.sheinbergon.dremio.udf.gis.util.allocateBuffer | ||
|
||
internal class STGeomFromGeoJsonTests : GeometryInputFunSpec.NullableVarChar<STGeomFromGeoJson>() { | ||
|
||
init { | ||
testGeometryInput( | ||
"Calling ST_GeomFromGeoJSON on a POINT", | ||
""" | ||
{"type":"Point","coordinates":[0.5,0.5],"crs":{"type":"name","properties":{"name":"EPSG:4326"}}} | ||
""".trimIndent(), | ||
byteArrayOf(1, 1, 0, 0, 32, -26, 16, 0, 0, 0, 0, 0, 0, 0, 0, -32, 63, 0, 0, 0, 0, 0, 0, -32, 63) | ||
) | ||
|
||
testInvalidGeometryInput( | ||
"Calling ST_GeomFromGeoJSON on rubbish text", | ||
"42ifon2 fA!@", | ||
) | ||
|
||
testNullGeometryInput( | ||
"Calling ST_GeomFromGeoJSON on null input" | ||
) | ||
} | ||
|
||
override val function = STGeomFromGeoJson().apply { | ||
jsonInput = NullableVarCharHolder() | ||
binaryOutput = NullableVarBinaryHolder() | ||
buffer = allocateBuffer() | ||
} | ||
|
||
override val STGeomFromGeoJson.input: NullableVarCharHolder get() = function.jsonInput | ||
override val STGeomFromGeoJson.output: NullableVarBinaryHolder get() = function.binaryOutput | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters