Skip to content

Commit

Permalink
Merge branch 'validation-22.0' into validation-22.1
Browse files Browse the repository at this point in the history
# Conflicts:
#	pom.xml
  • Loading branch information
sheinbergon committed Feb 25, 2023
2 parents 2fc77e1 + 385192b commit 83f7611
Show file tree
Hide file tree
Showing 27 changed files with 862 additions and 7 deletions.
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);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* 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 STMakeValidParameters implements SimpleFunction {
@Param
org.apache.arrow.vector.holders.NullableVarBinaryHolder binaryInput;

@Param
org.apache.arrow.vector.holders.NullableVarCharHolder parametersInput;

@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);
String parameters = org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.toUTF8String(parametersInput);
org.locationtech.jts.geom.Geometry repaired = org.sheinbergon.dremio.udf.gis.util.GeometryReparation.repair(geom, parameters);
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,13 @@ Value.Sides process(
};

public static Parameters valueFrom(final @Nonnull String value) {
return Parameters.valueOf(value.toUpperCase());
try {
return Parameters.valueOf(value.toUpperCase());
} catch (IllegalArgumentException iax) {
throw new IllegalArgumentException(
String.format("Invalid parameter name '%s'",
value));
}
}

abstract Value<?> process(@Nonnull String value, @Nonnull BufferParameters instance);
Expand Down
Loading

0 comments on commit 83f7611

Please sign in to comment.