Skip to content

Commit 2ca38c2

Browse files
authored
Merge pull request #44 from sheinbergon/validation-23.1
23.1.x - Validation Functionality
2 parents 1342feb + 6a9045d commit 2ca38c2

30 files changed

+866
-11
lines changed

.github/workflows/development-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
steps:
1313

1414
- name: Git checkout
15-
uses: actions/checkout@v2
15+
uses: actions/checkout@v3
1616

1717
- name: Java JDK 11 setup
1818
uses: actions/setup-java@v3

.github/workflows/release-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
steps:
1313

1414
- name: Git checkout
15-
uses: actions/checkout@v2
15+
uses: actions/checkout@v3
1616

1717
- name: Java JDK 11 setup
1818
uses: actions/setup-java@v3

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<checkstyle.version>9.3</checkstyle.version>
99
<dremio.version>23.1.0-202211250136090978-a79618c7</dremio.version>
1010
<dremio-arrow.version>9.0.0-20220922165652-3a8c29faef-dremio</dremio-arrow.version>
11-
<proj4j.version>1.2.0</proj4j.version>
11+
<proj4j.version>1.2.3</proj4j.version>
1212
<jts-core.version>1.19.0</jts-core.version>
1313
<jts-io-common.version>1.19.0</jts-io-common.version>
1414
<commons-io.version>2.11.0</commons-io.version>
@@ -21,7 +21,7 @@
2121
<carrotsearch.version>0.7.0</carrotsearch.version>
2222
<arrow-memory-netty.version>9.0.0</arrow-memory-netty.version>
2323
</properties>
24-
<version>0.8.4${artifact.version.suffix}</version>
24+
<version>0.8.6${artifact.version.suffix}</version>
2525
<name>dremio-udf-gis</name>
2626
<description>GIS UDF extensions for Dremio</description>
2727
<url>https://github.com/sheinbergon/dremio-udf-gis</url>

src/main/java/org/sheinbergon/dremio/udf/gis/STCentroid.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
@FunctionTemplate(
2828
name = "ST_Centroid",
2929
scope = FunctionTemplate.FunctionScope.SIMPLE,
30-
nulls = FunctionTemplate.NullHandling.INTERNAL)
30+
nulls = FunctionTemplate.NullHandling.INTERNAL,
31+
costCategory = FunctionTemplate.FunctionCostCategory.MEDIUM)
3132
public class STCentroid implements SimpleFunction {
3233
@Param
3334
org.apache.arrow.vector.holders.NullableVarBinaryHolder binaryInput;

src/main/java/org/sheinbergon/dremio/udf/gis/STConcaveHull.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
@FunctionTemplate(
2828
name = "ST_ConcaveHull",
2929
scope = FunctionTemplate.FunctionScope.SIMPLE,
30-
nulls = FunctionTemplate.NullHandling.INTERNAL)
30+
nulls = FunctionTemplate.NullHandling.INTERNAL,
31+
costCategory = FunctionTemplate.FunctionCostCategory.MEDIUM)
3132
public class STConcaveHull implements SimpleFunction {
3233
@Param
3334
org.apache.arrow.vector.holders.NullableVarBinaryHolder binaryInput;

src/main/java/org/sheinbergon/dremio/udf/gis/STConcaveHullNoHolesAllowed.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
@FunctionTemplate(
2828
name = "ST_ConcaveHull",
2929
scope = FunctionTemplate.FunctionScope.SIMPLE,
30-
nulls = FunctionTemplate.NullHandling.INTERNAL)
30+
nulls = FunctionTemplate.NullHandling.INTERNAL,
31+
costCategory = FunctionTemplate.FunctionCostCategory.MEDIUM)
3132
public class STConcaveHullNoHolesAllowed implements SimpleFunction {
3233
@Param
3334
org.apache.arrow.vector.holders.NullableVarBinaryHolder binaryInput;

src/main/java/org/sheinbergon/dremio/udf/gis/STConvexHull.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
@FunctionTemplate(
2828
name = "ST_ConvexHull",
2929
scope = FunctionTemplate.FunctionScope.SIMPLE,
30-
nulls = FunctionTemplate.NullHandling.INTERNAL)
30+
nulls = FunctionTemplate.NullHandling.INTERNAL,
31+
costCategory = FunctionTemplate.FunctionCostCategory.MEDIUM)
3132
public class STConvexHull implements SimpleFunction {
3233
@Param
3334
org.apache.arrow.vector.holders.NullableVarBinaryHolder binaryInput;
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
* <p>
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
* <p>
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.sheinbergon.dremio.udf.gis;
19+
20+
import com.dremio.exec.expr.SimpleFunction;
21+
import com.dremio.exec.expr.annotations.FunctionTemplate;
22+
import com.dremio.exec.expr.annotations.Output;
23+
import com.dremio.exec.expr.annotations.Param;
24+
25+
@FunctionTemplate(
26+
name = "ST_IsValid",
27+
scope = FunctionTemplate.FunctionScope.SIMPLE,
28+
nulls = FunctionTemplate.NullHandling.INTERNAL,
29+
costCategory = FunctionTemplate.FunctionCostCategory.MEDIUM)
30+
public class STIsValid implements SimpleFunction {
31+
@Param
32+
org.apache.arrow.vector.holders.NullableVarBinaryHolder binaryInput;
33+
34+
@Output
35+
org.apache.arrow.vector.holders.NullableBitHolder output;
36+
37+
public void setup() {
38+
}
39+
40+
public void eval() {
41+
if (org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.isHolderSet(binaryInput)) {
42+
org.locationtech.jts.geom.Geometry geom = org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.toGeometry(binaryInput);
43+
org.sheinbergon.dremio.udf.gis.util.GeometryValidationResult result = org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.validate(geom, 0);
44+
org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.setBooleanValue(output, result.isValid());
45+
} else {
46+
org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.markHolderNotSet(output);
47+
}
48+
}
49+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
* <p>
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
* <p>
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.sheinbergon.dremio.udf.gis;
19+
20+
import com.dremio.exec.expr.SimpleFunction;
21+
import com.dremio.exec.expr.annotations.FunctionTemplate;
22+
import com.dremio.exec.expr.annotations.Output;
23+
import com.dremio.exec.expr.annotations.Param;
24+
25+
@FunctionTemplate(
26+
name = "ST_IsValid",
27+
scope = FunctionTemplate.FunctionScope.SIMPLE,
28+
nulls = FunctionTemplate.NullHandling.INTERNAL,
29+
costCategory = FunctionTemplate.FunctionCostCategory.MEDIUM)
30+
public class STIsValidFlags implements SimpleFunction {
31+
@Param
32+
org.apache.arrow.vector.holders.NullableVarBinaryHolder binaryInput;
33+
34+
@Param
35+
org.apache.arrow.vector.holders.IntHolder flagsInput;
36+
37+
@Output
38+
org.apache.arrow.vector.holders.NullableBitHolder output;
39+
40+
public void setup() {
41+
}
42+
43+
public void eval() {
44+
if (org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.areHoldersSet(binaryInput)) {
45+
int flags = flagsInput.value;
46+
org.locationtech.jts.geom.Geometry geom = org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.toGeometry(binaryInput);
47+
org.sheinbergon.dremio.udf.gis.util.GeometryValidationResult result = org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.validate(geom, flags);
48+
org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.setBooleanValue(output, result.isValid());
49+
} else {
50+
org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.markHolderNotSet(output);
51+
}
52+
}
53+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
* <p>
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
* <p>
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.sheinbergon.dremio.udf.gis;
19+
20+
import com.dremio.exec.expr.SimpleFunction;
21+
import com.dremio.exec.expr.annotations.FunctionTemplate;
22+
import com.dremio.exec.expr.annotations.Output;
23+
import com.dremio.exec.expr.annotations.Param;
24+
25+
import javax.inject.Inject;
26+
27+
@FunctionTemplate(
28+
name = "ST_IsValidReason",
29+
scope = FunctionTemplate.FunctionScope.SIMPLE,
30+
nulls = FunctionTemplate.NullHandling.INTERNAL,
31+
costCategory = FunctionTemplate.FunctionCostCategory.MEDIUM)
32+
public class STIsValidReason implements SimpleFunction {
33+
@Param
34+
org.apache.arrow.vector.holders.NullableVarBinaryHolder binaryInput;
35+
36+
@Output
37+
org.apache.arrow.vector.holders.NullableVarCharHolder textOutput;
38+
39+
@Inject
40+
org.apache.arrow.memory.ArrowBuf buffer;
41+
42+
public void setup() {
43+
}
44+
45+
public void eval() {
46+
if (org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.isHolderSet(binaryInput)) {
47+
org.locationtech.jts.geom.Geometry geom = org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.toGeometry(binaryInput);
48+
org.sheinbergon.dremio.udf.gis.util.GeometryValidationResult result = org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.validate(geom, 0);
49+
byte[] bytes = result.getFormattedReason().getBytes(java.nio.charset.StandardCharsets.UTF_8);
50+
buffer = buffer.reallocIfNeeded(bytes.length);
51+
org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.populate(bytes, buffer, textOutput);
52+
} else {
53+
org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.markHolderNotSet(textOutput);
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)