Skip to content

Commit

Permalink
Merge pull request #44 from sheinbergon/validation-23.1
Browse files Browse the repository at this point in the history
23.1.x - Validation Functionality
  • Loading branch information
sheinbergon authored Feb 28, 2023
2 parents 1342feb + 6a9045d commit 2ca38c2
Show file tree
Hide file tree
Showing 30 changed files with 866 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/development-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
steps:

- name: Git checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Java JDK 11 setup
uses: actions/setup-java@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
steps:

- name: Git checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Java JDK 11 setup
uses: actions/setup-java@v3
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<checkstyle.version>9.3</checkstyle.version>
<dremio.version>23.1.0-202211250136090978-a79618c7</dremio.version>
<dremio-arrow.version>9.0.0-20220922165652-3a8c29faef-dremio</dremio-arrow.version>
<proj4j.version>1.2.0</proj4j.version>
<proj4j.version>1.2.3</proj4j.version>
<jts-core.version>1.19.0</jts-core.version>
<jts-io-common.version>1.19.0</jts-io-common.version>
<commons-io.version>2.11.0</commons-io.version>
Expand All @@ -21,7 +21,7 @@
<carrotsearch.version>0.7.0</carrotsearch.version>
<arrow-memory-netty.version>9.0.0</arrow-memory-netty.version>
</properties>
<version>0.8.4${artifact.version.suffix}</version>
<version>0.8.6${artifact.version.suffix}</version>
<name>dremio-udf-gis</name>
<description>GIS UDF extensions for Dremio</description>
<url>https://github.com/sheinbergon/dremio-udf-gis</url>
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/sheinbergon/dremio/udf/gis/STCentroid.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
@FunctionTemplate(
name = "ST_Centroid",
scope = FunctionTemplate.FunctionScope.SIMPLE,
nulls = FunctionTemplate.NullHandling.INTERNAL)
nulls = FunctionTemplate.NullHandling.INTERNAL,
costCategory = FunctionTemplate.FunctionCostCategory.MEDIUM)
public class STCentroid implements SimpleFunction {
@Param
org.apache.arrow.vector.holders.NullableVarBinaryHolder binaryInput;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
@FunctionTemplate(
name = "ST_ConcaveHull",
scope = FunctionTemplate.FunctionScope.SIMPLE,
nulls = FunctionTemplate.NullHandling.INTERNAL)
nulls = FunctionTemplate.NullHandling.INTERNAL,
costCategory = FunctionTemplate.FunctionCostCategory.MEDIUM)
public class STConcaveHull implements SimpleFunction {
@Param
org.apache.arrow.vector.holders.NullableVarBinaryHolder binaryInput;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
@FunctionTemplate(
name = "ST_ConcaveHull",
scope = FunctionTemplate.FunctionScope.SIMPLE,
nulls = FunctionTemplate.NullHandling.INTERNAL)
nulls = FunctionTemplate.NullHandling.INTERNAL,
costCategory = FunctionTemplate.FunctionCostCategory.MEDIUM)
public class STConcaveHullNoHolesAllowed implements SimpleFunction {
@Param
org.apache.arrow.vector.holders.NullableVarBinaryHolder binaryInput;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
@FunctionTemplate(
name = "ST_ConvexHull",
scope = FunctionTemplate.FunctionScope.SIMPLE,
nulls = FunctionTemplate.NullHandling.INTERNAL)
nulls = FunctionTemplate.NullHandling.INTERNAL,
costCategory = FunctionTemplate.FunctionCostCategory.MEDIUM)
public class STConvexHull implements SimpleFunction {
@Param
org.apache.arrow.vector.holders.NullableVarBinaryHolder binaryInput;
Expand Down
49 changes: 49 additions & 0 deletions src/main/java/org/sheinbergon/dremio/udf/gis/STIsValid.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* 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;

@FunctionTemplate(
name = "ST_IsValid",
scope = FunctionTemplate.FunctionScope.SIMPLE,
nulls = FunctionTemplate.NullHandling.INTERNAL,
costCategory = FunctionTemplate.FunctionCostCategory.MEDIUM)
public class STIsValid implements SimpleFunction {
@Param
org.apache.arrow.vector.holders.NullableVarBinaryHolder binaryInput;

@Output
org.apache.arrow.vector.holders.NullableBitHolder output;

public void setup() {
}

public void eval() {
if (org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.isHolderSet(binaryInput)) {
org.locationtech.jts.geom.Geometry geom = org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.toGeometry(binaryInput);
org.sheinbergon.dremio.udf.gis.util.GeometryValidationResult result = org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.validate(geom, 0);
org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.setBooleanValue(output, result.isValid());
} else {
org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.markHolderNotSet(output);
}
}
}
53 changes: 53 additions & 0 deletions src/main/java/org/sheinbergon/dremio/udf/gis/STIsValidFlags.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* 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;

@FunctionTemplate(
name = "ST_IsValid",
scope = FunctionTemplate.FunctionScope.SIMPLE,
nulls = FunctionTemplate.NullHandling.INTERNAL,
costCategory = FunctionTemplate.FunctionCostCategory.MEDIUM)
public class STIsValidFlags implements SimpleFunction {
@Param
org.apache.arrow.vector.holders.NullableVarBinaryHolder binaryInput;

@Param
org.apache.arrow.vector.holders.IntHolder flagsInput;

@Output
org.apache.arrow.vector.holders.NullableBitHolder output;

public void setup() {
}

public void eval() {
if (org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.areHoldersSet(binaryInput)) {
int flags = flagsInput.value;
org.locationtech.jts.geom.Geometry geom = org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.toGeometry(binaryInput);
org.sheinbergon.dremio.udf.gis.util.GeometryValidationResult result = org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.validate(geom, flags);
org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.setBooleanValue(output, result.isValid());
} else {
org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.markHolderNotSet(output);
}
}
}
56 changes: 56 additions & 0 deletions src/main/java/org/sheinbergon/dremio/udf/gis/STIsValidReason.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* 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_IsValidReason",
scope = FunctionTemplate.FunctionScope.SIMPLE,
nulls = FunctionTemplate.NullHandling.INTERNAL,
costCategory = FunctionTemplate.FunctionCostCategory.MEDIUM)
public class STIsValidReason implements SimpleFunction {
@Param
org.apache.arrow.vector.holders.NullableVarBinaryHolder binaryInput;

@Output
org.apache.arrow.vector.holders.NullableVarCharHolder textOutput;

@Inject
org.apache.arrow.memory.ArrowBuf buffer;

public void setup() {
}

public void eval() {
if (org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.isHolderSet(binaryInput)) {
org.locationtech.jts.geom.Geometry geom = org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.toGeometry(binaryInput);
org.sheinbergon.dremio.udf.gis.util.GeometryValidationResult result = org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.validate(geom, 0);
byte[] bytes = result.getFormattedReason().getBytes(java.nio.charset.StandardCharsets.UTF_8);
buffer = buffer.reallocIfNeeded(bytes.length);
org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.populate(bytes, buffer, textOutput);
} else {
org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.markHolderNotSet(textOutput);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* 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_IsValidReason",
scope = FunctionTemplate.FunctionScope.SIMPLE,
nulls = FunctionTemplate.NullHandling.INTERNAL,
costCategory = FunctionTemplate.FunctionCostCategory.MEDIUM)
public class STIsValidReasonFlags implements SimpleFunction {
@Param
org.apache.arrow.vector.holders.NullableVarBinaryHolder binaryInput;

@Param
org.apache.arrow.vector.holders.IntHolder flagsInput;

@Output
org.apache.arrow.vector.holders.NullableVarCharHolder textOutput;

@Inject
org.apache.arrow.memory.ArrowBuf buffer;

public void setup() {
}

public void eval() {
if (org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.areHoldersSet(binaryInput)) {
int flags = flagsInput.value;
org.locationtech.jts.geom.Geometry geom = org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.toGeometry(binaryInput);
org.sheinbergon.dremio.udf.gis.util.GeometryValidationResult result = org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.validate(geom, flags);
byte[] bytes = result.getFormattedReason().getBytes(java.nio.charset.StandardCharsets.UTF_8);
buffer = buffer.reallocIfNeeded(bytes.length);
org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.populate(bytes, buffer, textOutput);
} else {
org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.markHolderNotSet(textOutput);
}
}
}
58 changes: 58 additions & 0 deletions src/main/java/org/sheinbergon/dremio/udf/gis/STMakeValid.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* 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 org.apache.arrow.memory.ArrowBuf;

import javax.inject.Inject;

@FunctionTemplate(
name = "ST_MakeValid",
scope = FunctionTemplate.FunctionScope.SIMPLE,
nulls = FunctionTemplate.NullHandling.INTERNAL,
costCategory = FunctionTemplate.FunctionCostCategory.MEDIUM)
public class STMakeValid implements SimpleFunction {
@Param
org.apache.arrow.vector.holders.NullableVarBinaryHolder binaryInput;

@Output
org.apache.arrow.vector.holders.NullableVarBinaryHolder binaryOutput;

@Inject
ArrowBuf buffer;

public void setup() {
}

public void eval() {
if (org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.isHolderSet(binaryInput)) {
org.locationtech.jts.geom.Geometry geom = org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.toGeometry(binaryInput);
org.locationtech.jts.geom.Geometry repaired = org.sheinbergon.dremio.udf.gis.util.GeometryReparation.repair(geom, null);
repaired.setSRID(geom.getSRID());
byte[] bytes = org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.toEWKB(repaired);
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);
}
}
}
Loading

0 comments on commit 2ca38c2

Please sign in to comment.