-
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.
Merge pull request #44 from sheinbergon/validation-23.1
23.1.x - Validation Functionality
- Loading branch information
Showing
30 changed files
with
866 additions
and
11 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
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
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
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
49 changes: 49 additions & 0 deletions
49
src/main/java/org/sheinbergon/dremio/udf/gis/STIsValid.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,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
53
src/main/java/org/sheinbergon/dremio/udf/gis/STIsValidFlags.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,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
56
src/main/java/org/sheinbergon/dremio/udf/gis/STIsValidReason.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,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); | ||
} | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
src/main/java/org/sheinbergon/dremio/udf/gis/STIsValidReasonFlags.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,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
58
src/main/java/org/sheinbergon/dremio/udf/gis/STMakeValid.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,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); | ||
} | ||
} | ||
} |
Oops, something went wrong.