[ https://issues.apache.org/jira/browse/DRILL-4091?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16497408#comment-16497408 ]
ASF GitHub Bot commented on DRILL-4091: --------------------------------------- ilooner closed pull request #258: DRILL-4091: Support for additional gis operations in gis contrib module URL: https://github.com/apache/drill/pull/258 This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/contrib/gis/pom.xml b/contrib/gis/pom.xml index fbd7a6053d..ef0f0afcc4 100644 --- a/contrib/gis/pom.xml +++ b/contrib/gis/pom.xml @@ -42,7 +42,11 @@ <artifactId>esri-geometry-api</artifactId> <version>1.2.1</version> </dependency> - + <dependency> + <groupId>org.osgeo</groupId> + <artifactId>proj4j</artifactId> + <version>0.1.0</version> + </dependency> <!-- Test dependencies --> <dependency> <groupId>org.apache.drill.exec</groupId> diff --git a/contrib/gis/sample-data/polygons.tsv b/contrib/gis/sample-data/polygons.tsv new file mode 100644 index 0000000000..f70c922b1a --- /dev/null +++ b/contrib/gis/sample-data/polygons.tsv @@ -0,0 +1,5 @@ +1 POLYGON((0 0, 0 1, 1 1, 1 0, 0 0)) +1 POLYGON((0 0, 0 -1, 1 -1, 1 0, 0 0)) +2 POLYGON((10 10, 10 11, 11 11, 11 10, 10 10)) +2 POLYGON((10 10, 10 9, 11 9, 11 10, 10 10)) +2 diff --git a/contrib/gis/src/main/java/com/esri/core/geometry/VertexGeomAccessor.java b/contrib/gis/src/main/java/com/esri/core/geometry/VertexGeomAccessor.java new file mode 100644 index 0000000000..f87d5d15a5 --- /dev/null +++ b/contrib/gis/src/main/java/com/esri/core/geometry/VertexGeomAccessor.java @@ -0,0 +1,25 @@ +/** + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 com.esri.core.geometry; + +public class VertexGeomAccessor { + public static MultiVertexGeometry getVertexGeometry(Geometry geom){ + return (MultiVertexGeometry) geom._getImpl(); + } +} diff --git a/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STBuffer.java b/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STBuffer.java new file mode 100644 index 0000000000..c08d146b11 --- /dev/null +++ b/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STBuffer.java @@ -0,0 +1,65 @@ +/** + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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.apache.drill.exec.expr.fn.impl.gis; + +import javax.inject.Inject; + +import org.apache.drill.exec.expr.DrillSimpleFunc; +import org.apache.drill.exec.expr.annotations.FunctionTemplate; +import org.apache.drill.exec.expr.annotations.Output; +import org.apache.drill.exec.expr.annotations.Param; +import org.apache.drill.exec.expr.holders.Float8Holder; +import org.apache.drill.exec.expr.holders.VarBinaryHolder; + +import io.netty.buffer.DrillBuf; + +@FunctionTemplate(name = "st_buffer", scope = FunctionTemplate.FunctionScope.SIMPLE, + nulls = FunctionTemplate.NullHandling.NULL_IF_NULL) +public class STBuffer implements DrillSimpleFunc { + @Param + VarBinaryHolder geom1Param; + + @Param(constant = true) + Float8Holder bufferRadiusParam; + + @Output + VarBinaryHolder out; + + @Inject + DrillBuf buffer; + + public void setup() { + } + + public void eval() { + double bufferRadius = bufferRadiusParam.value; + + com.esri.core.geometry.ogc.OGCGeometry geom1 = com.esri.core.geometry.ogc.OGCGeometry + .fromBinary(geom1Param.buffer.nioBuffer(geom1Param.start, geom1Param.end - geom1Param.start)); + + com.esri.core.geometry.ogc.OGCGeometry bufferedGeom = geom1.buffer(bufferRadius); + + java.nio.ByteBuffer bufferedGeomBytes = bufferedGeom.asBinary(); + + int outputSize = bufferedGeomBytes.remaining(); + buffer = out.buffer = buffer.reallocIfNeeded(outputSize); + out.start = 0; + out.end = outputSize; + buffer.setBytes(0, bufferedGeomBytes); + } +} diff --git a/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STContains.java b/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STContains.java new file mode 100644 index 0000000000..fad3b3e807 --- /dev/null +++ b/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STContains.java @@ -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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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.apache.drill.exec.expr.fn.impl.gis; + +import javax.inject.Inject; + +import org.apache.drill.exec.expr.DrillSimpleFunc; +import org.apache.drill.exec.expr.annotations.FunctionTemplate; +import org.apache.drill.exec.expr.annotations.Output; +import org.apache.drill.exec.expr.annotations.Param; +import org.apache.drill.exec.expr.holders.BitHolder; +import org.apache.drill.exec.expr.holders.VarBinaryHolder; + +import io.netty.buffer.DrillBuf; + +@FunctionTemplate(name = "st_contains", scope = FunctionTemplate.FunctionScope.SIMPLE, + nulls = FunctionTemplate.NullHandling.NULL_IF_NULL) +public class STContains implements DrillSimpleFunc { + @Param + VarBinaryHolder geom1Param; + + @Param + VarBinaryHolder geom2Param; + + @Output + BitHolder out; + + @Inject + DrillBuf buffer; + + public void setup() { + } + + public void eval() { + com.esri.core.geometry.ogc.OGCGeometry geom1; + com.esri.core.geometry.ogc.OGCGeometry geom2; + + geom1 = com.esri.core.geometry.ogc.OGCGeometry + .fromBinary(geom1Param.buffer.nioBuffer(geom1Param.start, geom1Param.end - geom1Param.start)); + geom2 = com.esri.core.geometry.ogc.OGCGeometry + .fromBinary(geom2Param.buffer.nioBuffer(geom2Param.start, geom2Param.end - geom2Param.start)); + + int contains = geom1.contains(geom2) ? 1 : 0; + + out.value = contains; + } +} diff --git a/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STCrosses.java b/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STCrosses.java new file mode 100644 index 0000000000..2e374d05ef --- /dev/null +++ b/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STCrosses.java @@ -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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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.apache.drill.exec.expr.fn.impl.gis; + +import javax.inject.Inject; + +import org.apache.drill.exec.expr.DrillSimpleFunc; +import org.apache.drill.exec.expr.annotations.FunctionTemplate; +import org.apache.drill.exec.expr.annotations.Output; +import org.apache.drill.exec.expr.annotations.Param; +import org.apache.drill.exec.expr.holders.BitHolder; +import org.apache.drill.exec.expr.holders.VarBinaryHolder; + +import io.netty.buffer.DrillBuf; + +@FunctionTemplate(name = "st_crosses", scope = FunctionTemplate.FunctionScope.SIMPLE, + nulls = FunctionTemplate.NullHandling.NULL_IF_NULL) +public class STCrosses implements DrillSimpleFunc { + @Param + VarBinaryHolder geom1Param; + + @Param + VarBinaryHolder geom2Param; + + @Output + BitHolder out; + + @Inject + DrillBuf buffer; + + public void setup() { + } + + public void eval() { + com.esri.core.geometry.ogc.OGCGeometry geom1; + com.esri.core.geometry.ogc.OGCGeometry geom2; + + geom1 = com.esri.core.geometry.ogc.OGCGeometry + .fromBinary(geom1Param.buffer.nioBuffer(geom1Param.start, geom1Param.end - geom1Param.start)); + geom2 = com.esri.core.geometry.ogc.OGCGeometry + .fromBinary(geom2Param.buffer.nioBuffer(geom2Param.start, geom2Param.end - geom2Param.start)); + + int crosses = geom1.crosses(geom2) ? 1 : 0; + + out.value = crosses; + } +} diff --git a/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STDifference.java b/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STDifference.java new file mode 100644 index 0000000000..3998e0f3f2 --- /dev/null +++ b/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STDifference.java @@ -0,0 +1,66 @@ +/** + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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.apache.drill.exec.expr.fn.impl.gis; + +import javax.inject.Inject; + +import org.apache.drill.exec.expr.DrillSimpleFunc; +import org.apache.drill.exec.expr.annotations.FunctionTemplate; +import org.apache.drill.exec.expr.annotations.Output; +import org.apache.drill.exec.expr.annotations.Param; +import org.apache.drill.exec.expr.holders.VarBinaryHolder; + +import io.netty.buffer.DrillBuf; + +@FunctionTemplate(name = "st_difference", scope = FunctionTemplate.FunctionScope.SIMPLE, + nulls = FunctionTemplate.NullHandling.NULL_IF_NULL) +public class STDifference implements DrillSimpleFunc { + @Param + VarBinaryHolder geom1Param; + + @Param + VarBinaryHolder geom2Param; + + @Output + VarBinaryHolder out; + + @Inject + DrillBuf buffer; + + public void setup() { + } + + public void eval() { + com.esri.core.geometry.ogc.OGCGeometry geom1; + com.esri.core.geometry.ogc.OGCGeometry geom2; + geom1 = com.esri.core.geometry.ogc.OGCGeometry + .fromBinary(geom1Param.buffer.nioBuffer(geom1Param.start, geom1Param.end - geom1Param.start)); + geom2 = com.esri.core.geometry.ogc.OGCGeometry + .fromBinary(geom2Param.buffer.nioBuffer(geom2Param.start, geom2Param.end - geom2Param.start)); + + com.esri.core.geometry.ogc.OGCGeometry diffGeom = geom1.difference(geom2); + + java.nio.ByteBuffer bufferedGeomBytes = diffGeom.asBinary(); + + int outputSize = bufferedGeomBytes.remaining(); + buffer = out.buffer = buffer.reallocIfNeeded(outputSize); + out.start = 0; + out.end = outputSize; + buffer.setBytes(0, bufferedGeomBytes); + } +} diff --git a/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STDisjoint.java b/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STDisjoint.java new file mode 100644 index 0000000000..cd321da39f --- /dev/null +++ b/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STDisjoint.java @@ -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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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.apache.drill.exec.expr.fn.impl.gis; + +import javax.inject.Inject; + +import org.apache.drill.exec.expr.DrillSimpleFunc; +import org.apache.drill.exec.expr.annotations.FunctionTemplate; +import org.apache.drill.exec.expr.annotations.Output; +import org.apache.drill.exec.expr.annotations.Param; +import org.apache.drill.exec.expr.holders.BitHolder; +import org.apache.drill.exec.expr.holders.VarBinaryHolder; + +import io.netty.buffer.DrillBuf; + +@FunctionTemplate(name = "st_disjoint", scope = FunctionTemplate.FunctionScope.SIMPLE, + nulls = FunctionTemplate.NullHandling.NULL_IF_NULL) +public class STDisjoint implements DrillSimpleFunc { + @Param + VarBinaryHolder geom1Param; + + @Param + VarBinaryHolder geom2Param; + + @Output + BitHolder out; + + @Inject + DrillBuf buffer; + + public void setup() { + } + + public void eval() { + com.esri.core.geometry.ogc.OGCGeometry geom1; + com.esri.core.geometry.ogc.OGCGeometry geom2; + + geom1 = com.esri.core.geometry.ogc.OGCGeometry + .fromBinary(geom1Param.buffer.nioBuffer(geom1Param.start, geom1Param.end - geom1Param.start)); + geom2 = com.esri.core.geometry.ogc.OGCGeometry + .fromBinary(geom2Param.buffer.nioBuffer(geom2Param.start, geom2Param.end - geom2Param.start)); + + int isDisjoint = geom1.disjoint(geom2) ? 1 : 0; + + out.value = isDisjoint; + } +} diff --git a/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STDistance.java b/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STDistance.java new file mode 100644 index 0000000000..6884566031 --- /dev/null +++ b/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STDistance.java @@ -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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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.apache.drill.exec.expr.fn.impl.gis; + +import javax.inject.Inject; + +import org.apache.drill.exec.expr.DrillSimpleFunc; +import org.apache.drill.exec.expr.annotations.FunctionTemplate; +import org.apache.drill.exec.expr.annotations.Output; +import org.apache.drill.exec.expr.annotations.Param; +import org.apache.drill.exec.expr.holders.Float8Holder; +import org.apache.drill.exec.expr.holders.VarBinaryHolder; + +import io.netty.buffer.DrillBuf; + +@FunctionTemplate(name = "st_distance", scope = FunctionTemplate.FunctionScope.SIMPLE, + nulls = FunctionTemplate.NullHandling.NULL_IF_NULL) +public class STDistance implements DrillSimpleFunc { + @Param + VarBinaryHolder geom1Param; + + @Param + VarBinaryHolder geom2Param; + + @Output + Float8Holder out; + + @Inject + DrillBuf buffer; + + public void setup() { + } + + public void eval() { + com.esri.core.geometry.ogc.OGCGeometry geom1; + com.esri.core.geometry.ogc.OGCGeometry geom2; + + geom1 = com.esri.core.geometry.ogc.OGCGeometry + .fromBinary(geom1Param.buffer.nioBuffer(geom1Param.start, geom1Param.end - geom1Param.start)); + geom2 = com.esri.core.geometry.ogc.OGCGeometry + .fromBinary(geom2Param.buffer.nioBuffer(geom2Param.start, geom2Param.end - geom2Param.start)); + + out.value = geom1.distance(geom2); + } +} diff --git a/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STEnvelope.java b/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STEnvelope.java new file mode 100644 index 0000000000..0159fbbe57 --- /dev/null +++ b/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STEnvelope.java @@ -0,0 +1,66 @@ +/** + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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.apache.drill.exec.expr.fn.impl.gis; + +import javax.inject.Inject; + +import org.apache.drill.exec.expr.DrillSimpleFunc; +import org.apache.drill.exec.expr.annotations.FunctionTemplate; +import org.apache.drill.exec.expr.annotations.Output; +import org.apache.drill.exec.expr.annotations.Param; +import org.apache.drill.exec.expr.holders.VarBinaryHolder; + +import io.netty.buffer.DrillBuf; + +@FunctionTemplate(name = "st_envelope", scope = FunctionTemplate.FunctionScope.SIMPLE, + nulls = FunctionTemplate.NullHandling.NULL_IF_NULL) +public class STEnvelope implements DrillSimpleFunc { + @Param + VarBinaryHolder geom1Param; + + @Output + VarBinaryHolder out; + + @Inject + DrillBuf buffer; + + public void setup() { + } + + public void eval() { + com.esri.core.geometry.ogc.OGCGeometry geom1; + geom1 = com.esri.core.geometry.ogc.OGCGeometry + .fromBinary(geom1Param.buffer.nioBuffer(geom1Param.start, geom1Param.end - geom1Param.start)); + + com.esri.core.geometry.ogc.OGCGeometry envelopeGeom; + if(geom1.geometryType().equals("Point")){ + envelopeGeom = geom1; + } + else{ + envelopeGeom = geom1.envelope(); + } + + java.nio.ByteBuffer envelopeGeomBytes = envelopeGeom.asBinary(); + + int outputSize = envelopeGeomBytes.remaining(); + buffer = out.buffer = buffer.reallocIfNeeded(outputSize); + out.start = 0; + out.end = outputSize; + buffer.setBytes(0, envelopeGeomBytes); + } +} diff --git a/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STEquals.java b/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STEquals.java new file mode 100644 index 0000000000..772f949bd3 --- /dev/null +++ b/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STEquals.java @@ -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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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.apache.drill.exec.expr.fn.impl.gis; + +import javax.inject.Inject; + +import org.apache.drill.exec.expr.DrillSimpleFunc; +import org.apache.drill.exec.expr.annotations.FunctionTemplate; +import org.apache.drill.exec.expr.annotations.Output; +import org.apache.drill.exec.expr.annotations.Param; +import org.apache.drill.exec.expr.holders.BitHolder; +import org.apache.drill.exec.expr.holders.VarBinaryHolder; + +import io.netty.buffer.DrillBuf; + +@FunctionTemplate(name = "st_equals", scope = FunctionTemplate.FunctionScope.SIMPLE, + nulls = FunctionTemplate.NullHandling.NULL_IF_NULL) +public class STEquals implements DrillSimpleFunc { + @Param + VarBinaryHolder geom1Param; + + @Param + VarBinaryHolder geom2Param; + + @Output + BitHolder out; + + @Inject + DrillBuf buffer; + + public void setup() { + } + + public void eval() { + com.esri.core.geometry.ogc.OGCGeometry geom1; + com.esri.core.geometry.ogc.OGCGeometry geom2; + + geom1 = com.esri.core.geometry.ogc.OGCGeometry + .fromBinary(geom1Param.buffer.nioBuffer(geom1Param.start, geom1Param.end - geom1Param.start)); + geom2 = com.esri.core.geometry.ogc.OGCGeometry + .fromBinary(geom2Param.buffer.nioBuffer(geom2Param.start, geom2Param.end - geom2Param.start)); + + int equals = geom1.equals(geom2) ? 1 : 0; + + out.value = equals; + } +} diff --git a/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STGeomFromTextSrid.java b/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STGeomFromTextSrid.java index 3da074430b..1439d1141b 100644 --- a/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STGeomFromTextSrid.java +++ b/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STGeomFromTextSrid.java @@ -64,5 +64,5 @@ public void eval() { out.start = 0; out.end = outputSize; buffer.setBytes(0, pointBytes); - } + } } diff --git a/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STIntersects.java b/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STIntersects.java new file mode 100644 index 0000000000..79e8b763c0 --- /dev/null +++ b/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STIntersects.java @@ -0,0 +1,61 @@ +/** + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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.apache.drill.exec.expr.fn.impl.gis; + +import javax.inject.Inject; + +import org.apache.drill.exec.expr.DrillSimpleFunc; +import org.apache.drill.exec.expr.annotations.FunctionTemplate; +import org.apache.drill.exec.expr.annotations.Output; +import org.apache.drill.exec.expr.annotations.Param; +import org.apache.drill.exec.expr.holders.BitHolder; +import org.apache.drill.exec.expr.holders.VarBinaryHolder; + +import io.netty.buffer.DrillBuf; + +@FunctionTemplate(name = "st_intersects", scope = FunctionTemplate.FunctionScope.SIMPLE, + nulls = FunctionTemplate.NullHandling.NULL_IF_NULL) +public class STIntersects implements DrillSimpleFunc { + @Param + VarBinaryHolder geom1Param; + + @Param + VarBinaryHolder geom2Param; + + @Output + BitHolder out; + + @Inject + DrillBuf buffer; + + public void setup() { + } + + public void eval() { + com.esri.core.geometry.ogc.OGCGeometry geom1; + com.esri.core.geometry.ogc.OGCGeometry geom2; + geom1 = com.esri.core.geometry.ogc.OGCGeometry + .fromBinary(geom1Param.buffer.nioBuffer(geom1Param.start, geom1Param.end - geom1Param.start)); + geom2 = com.esri.core.geometry.ogc.OGCGeometry + .fromBinary(geom2Param.buffer.nioBuffer(geom2Param.start, geom2Param.end - geom2Param.start)); + + int intersects = geom1.intersects(geom2) ? 1 : 0; + + out.value = intersects; + } +} diff --git a/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STOverlaps.java b/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STOverlaps.java new file mode 100644 index 0000000000..25f8c19ce3 --- /dev/null +++ b/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STOverlaps.java @@ -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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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.apache.drill.exec.expr.fn.impl.gis; + +import javax.inject.Inject; + +import org.apache.drill.exec.expr.DrillSimpleFunc; +import org.apache.drill.exec.expr.annotations.FunctionTemplate; +import org.apache.drill.exec.expr.annotations.Output; +import org.apache.drill.exec.expr.annotations.Param; +import org.apache.drill.exec.expr.holders.BitHolder; +import org.apache.drill.exec.expr.holders.VarBinaryHolder; + +import io.netty.buffer.DrillBuf; + +@FunctionTemplate(name = "st_overlaps", scope = FunctionTemplate.FunctionScope.SIMPLE, + nulls = FunctionTemplate.NullHandling.NULL_IF_NULL) +public class STOverlaps implements DrillSimpleFunc { + @Param + VarBinaryHolder geom1Param; + + @Param + VarBinaryHolder geom2Param; + + @Output + BitHolder out; + + @Inject + DrillBuf buffer; + + public void setup() { + } + + public void eval() { + com.esri.core.geometry.ogc.OGCGeometry geom1; + com.esri.core.geometry.ogc.OGCGeometry geom2; + + geom1 = com.esri.core.geometry.ogc.OGCGeometry + .fromBinary(geom1Param.buffer.nioBuffer(geom1Param.start, geom1Param.end - geom1Param.start)); + geom2 = com.esri.core.geometry.ogc.OGCGeometry + .fromBinary(geom2Param.buffer.nioBuffer(geom2Param.start, geom2Param.end - geom2Param.start)); + + int overlaps = geom1.overlaps(geom2) ? 1 : 0; + + out.value = overlaps; + } +} diff --git a/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STRelate.java b/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STRelate.java new file mode 100644 index 0000000000..f8b02b3fa1 --- /dev/null +++ b/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STRelate.java @@ -0,0 +1,68 @@ +/** + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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.apache.drill.exec.expr.fn.impl.gis; + +import javax.inject.Inject; + +import org.apache.drill.exec.expr.DrillSimpleFunc; +import org.apache.drill.exec.expr.annotations.FunctionTemplate; +import org.apache.drill.exec.expr.annotations.Output; +import org.apache.drill.exec.expr.annotations.Param; +import org.apache.drill.exec.expr.holders.BitHolder; +import org.apache.drill.exec.expr.holders.VarBinaryHolder; +import org.apache.drill.exec.expr.holders.VarCharHolder; + +import io.netty.buffer.DrillBuf; + +@FunctionTemplate(name = "st_relate", scope = FunctionTemplate.FunctionScope.SIMPLE, + nulls = FunctionTemplate.NullHandling.NULL_IF_NULL) +public class STRelate implements DrillSimpleFunc { + @Param + VarBinaryHolder geom1Param; + + @Param + VarBinaryHolder geom2Param; + + @Param + VarCharHolder matrixParam; + + @Output + BitHolder out; + + @Inject + DrillBuf buffer; + + public void setup() { + } + + public void eval() { + com.esri.core.geometry.ogc.OGCGeometry geom1; + com.esri.core.geometry.ogc.OGCGeometry geom2; + String matrix = org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(matrixParam.start, + matrixParam.end, matrixParam.buffer); + + geom1 = com.esri.core.geometry.ogc.OGCGeometry + .fromBinary(geom1Param.buffer.nioBuffer(geom1Param.start, geom1Param.end - geom1Param.start)); + geom2 = com.esri.core.geometry.ogc.OGCGeometry + .fromBinary(geom2Param.buffer.nioBuffer(geom2Param.start, geom2Param.end - geom2Param.start)); + + int relates = geom1.relate(geom2, matrix) ? 1 : 0; + + out.value = relates; + } +} diff --git a/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STTouches.java b/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STTouches.java new file mode 100644 index 0000000000..df50076b97 --- /dev/null +++ b/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STTouches.java @@ -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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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.apache.drill.exec.expr.fn.impl.gis; + +import javax.inject.Inject; + +import org.apache.drill.exec.expr.DrillSimpleFunc; +import org.apache.drill.exec.expr.annotations.FunctionTemplate; +import org.apache.drill.exec.expr.annotations.Output; +import org.apache.drill.exec.expr.annotations.Param; +import org.apache.drill.exec.expr.holders.BitHolder; +import org.apache.drill.exec.expr.holders.VarBinaryHolder; + +import io.netty.buffer.DrillBuf; + +@FunctionTemplate(name = "st_touches", scope = FunctionTemplate.FunctionScope.SIMPLE, + nulls = FunctionTemplate.NullHandling.NULL_IF_NULL) +public class STTouches implements DrillSimpleFunc { + @Param + VarBinaryHolder geom1Param; + + @Param + VarBinaryHolder geom2Param; + + @Output + BitHolder out; + + @Inject + DrillBuf buffer; + + public void setup() { + } + + public void eval() { + com.esri.core.geometry.ogc.OGCGeometry geom1; + com.esri.core.geometry.ogc.OGCGeometry geom2; + + geom1 = com.esri.core.geometry.ogc.OGCGeometry + .fromBinary(geom1Param.buffer.nioBuffer(geom1Param.start, geom1Param.end - geom1Param.start)); + geom2 = com.esri.core.geometry.ogc.OGCGeometry + .fromBinary(geom2Param.buffer.nioBuffer(geom2Param.start, geom2Param.end - geom2Param.start)); + + int touches = geom1.touches(geom2) ? 1 : 0; + + out.value = touches; + } +} diff --git a/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STTransform.java b/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STTransform.java new file mode 100644 index 0000000000..6c9b03305e --- /dev/null +++ b/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STTransform.java @@ -0,0 +1,112 @@ +/** + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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.apache.drill.exec.expr.fn.impl.gis; + +import javax.inject.Inject; + +import org.apache.drill.exec.expr.DrillSimpleFunc; +import org.apache.drill.exec.expr.annotations.FunctionTemplate; +import org.apache.drill.exec.expr.annotations.Output; +import org.apache.drill.exec.expr.annotations.Param; +import org.apache.drill.exec.expr.annotations.Workspace; +import org.apache.drill.exec.expr.holders.NullableIntHolder; +import org.apache.drill.exec.expr.holders.NullableVarCharHolder; +import org.apache.drill.exec.expr.holders.VarBinaryHolder; +import org.osgeo.proj4j.CRSFactory; +import org.osgeo.proj4j.CoordinateTransform; + +import io.netty.buffer.DrillBuf; + +@FunctionTemplate(name = "st_transform", scope = FunctionTemplate.FunctionScope.SIMPLE, + nulls = FunctionTemplate.NullHandling.NULL_IF_NULL) +public class STTransform implements DrillSimpleFunc { + @Param + VarBinaryHolder geom1Param; + + @Param + NullableIntHolder sridSrcParam; + + @Param + NullableIntHolder sridTgtParam; + + @Workspace + CoordinateTransform transform; + + @Workspace + CRSFactory crsFactory; + + @Workspace + int sridTgt; + + @Output + VarBinaryHolder out; + + @Inject + DrillBuf buffer; + + public void setup() { + int sridSrc = sridSrcParam.value; + sridTgt = sridTgtParam.value; + + org.osgeo.proj4j.CoordinateReferenceSystem srcCrs = + new org.osgeo.proj4j.CRSFactory().createFromName("EPSG:" + sridSrc); + + org.osgeo.proj4j.CoordinateReferenceSystem tgtCrs = + new org.osgeo.proj4j.CRSFactory().createFromName("EPSG:" + sridTgt); + + transform = new org.osgeo.proj4j.BasicCoordinateTransform(srcCrs, tgtCrs); + } + + public void eval() { + com.esri.core.geometry.ogc.OGCGeometry geomSrc = com.esri.core.geometry.ogc.OGCGeometry + .fromBinary(geom1Param.buffer.nioBuffer(geom1Param.start, geom1Param.end - geom1Param.start)); + + //int code = Integer.parseInt(transform.getTargetCRS().getName().substring(5, 9));//now sridTgt + org.osgeo.proj4j.ProjCoordinate result = new org.osgeo.proj4j.ProjCoordinate(); + com.esri.core.geometry.SpatialReference sr = com.esri.core.geometry.SpatialReference.create(sridTgt); + java.nio.ByteBuffer geomBytes = null; + + if(geomSrc != null && geomSrc.geometryType().equals("Point")){ + com.esri.core.geometry.ogc.OGCPoint pointGeom = (com.esri.core.geometry.ogc.OGCPoint) geomSrc; + result = transform.transform(new org.osgeo.proj4j.ProjCoordinate(pointGeom.X(), pointGeom.Y()), result); + + geomBytes = new com.esri.core.geometry.ogc.OGCPoint( + new com.esri.core.geometry.Point(result.x, result.y), sr).asBinary(); + } else { + com.esri.core.geometry.Geometry esriGeom = geomSrc.getEsriGeometry(); + com.esri.core.geometry.MultiVertexGeometry vertexGeom = + com.esri.core.geometry.VertexGeomAccessor.getVertexGeometry(esriGeom); + for (int i = 0; i < vertexGeom.getPointCount(); i++){ + com.esri.core.geometry.Point point = vertexGeom.getPoint(i); + result = transform.transform(new org.osgeo.proj4j.ProjCoordinate(point.getX(), point.getY()), result); + point.setXY(result.x, result.y); + vertexGeom.setPoint(i, point); + } + + com.esri.core.geometry.ogc.OGCGeometry tGeom = + com.esri.core.geometry.ogc.OGCGeometry.createFromEsriGeometry(esriGeom, sr); + geomBytes = tGeom.asBinary(); + } + + int outputSize = geomBytes.remaining(); + buffer = out.buffer = buffer.reallocIfNeeded(outputSize); + out.start = 0; + out.end = outputSize; + buffer.setBytes(0, geomBytes); + } +} diff --git a/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STUnion.java b/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STUnion.java new file mode 100644 index 0000000000..276ee8de9b --- /dev/null +++ b/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STUnion.java @@ -0,0 +1,66 @@ +/** + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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.apache.drill.exec.expr.fn.impl.gis; + +import javax.inject.Inject; + +import org.apache.drill.exec.expr.DrillSimpleFunc; +import org.apache.drill.exec.expr.annotations.FunctionTemplate; +import org.apache.drill.exec.expr.annotations.Output; +import org.apache.drill.exec.expr.annotations.Param; +import org.apache.drill.exec.expr.holders.VarBinaryHolder; + +import io.netty.buffer.DrillBuf; + +@FunctionTemplate(name = "st_union", scope = FunctionTemplate.FunctionScope.SIMPLE, + nulls = FunctionTemplate.NullHandling.NULL_IF_NULL) +public class STUnion implements DrillSimpleFunc { + @Param + VarBinaryHolder geom1Param; + + @Param + VarBinaryHolder geom2Param; + + @Output + VarBinaryHolder out; + + @Inject + DrillBuf buffer; + + public void setup() { + } + + public void eval() { + com.esri.core.geometry.ogc.OGCGeometry geom1; + com.esri.core.geometry.ogc.OGCGeometry geom2; + geom1 = com.esri.core.geometry.ogc.OGCGeometry + .fromBinary(geom1Param.buffer.nioBuffer(geom1Param.start, geom1Param.end - geom1Param.start)); + geom2 = com.esri.core.geometry.ogc.OGCGeometry + .fromBinary(geom2Param.buffer.nioBuffer(geom2Param.start, geom2Param.end - geom2Param.start)); + + com.esri.core.geometry.ogc.OGCGeometry unionGeom = geom1.union(geom2); + + java.nio.ByteBuffer bufferedGeomBytes = unionGeom.asBinary(); + + int outputSize = bufferedGeomBytes.remaining(); + buffer = out.buffer = buffer.reallocIfNeeded(outputSize); + out.start = 0; + out.end = outputSize; + buffer.setBytes(0, bufferedGeomBytes); + } +} diff --git a/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STUnionAggregate.java b/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STUnionAggregate.java new file mode 100644 index 0000000000..2e63e3c781 --- /dev/null +++ b/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STUnionAggregate.java @@ -0,0 +1,114 @@ +/** + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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.apache.drill.exec.expr.fn.impl.gis; + +import javax.inject.Inject; + +import org.apache.drill.exec.expr.DrillAggFunc; +import org.apache.drill.exec.expr.annotations.FunctionTemplate; +import org.apache.drill.exec.expr.annotations.Output; +import org.apache.drill.exec.expr.annotations.Param; +import org.apache.drill.exec.expr.annotations.Workspace; +import org.apache.drill.exec.expr.holders.BigIntHolder; +import org.apache.drill.exec.expr.holders.IntHolder; +import org.apache.drill.exec.expr.holders.NullableVarBinaryHolder; +import org.apache.drill.exec.expr.holders.ObjectHolder; +import org.apache.drill.exec.expr.holders.UInt1Holder; + +import com.esri.core.geometry.SpatialReference; + +import io.netty.buffer.DrillBuf; + +@FunctionTemplate(name = "st_unionaggregate", scope = FunctionTemplate.FunctionScope.POINT_AGGREGATE) +public class STUnionAggregate implements DrillAggFunc { + @Param NullableVarBinaryHolder in; + @Workspace ObjectHolder value; + @Workspace UInt1Holder init; + @Workspace BigIntHolder nonNullCount; + @Workspace IntHolder srid; + @Inject DrillBuf buf; + @Output NullableVarBinaryHolder out; + + public void setup() { + init = new UInt1Holder(); + nonNullCount = new BigIntHolder(); + nonNullCount.value = 0; + init.value = 0; + value = new ObjectHolder(); + value.obj = new java.util.ArrayList<com.esri.core.geometry.Geometry>(); + } + + @Override + public void add() { + sout: { + if (in.isSet == 0) { + // processing nullable input and the value is null, so don't do anything... + break sout; + } + nonNullCount.value = 1; + java.util.ArrayList<com.esri.core.geometry.Geometry> tmp = (java.util.ArrayList<com.esri.core.geometry.Geometry>) value.obj; + + com.esri.core.geometry.ogc.OGCGeometry geom; + geom = com.esri.core.geometry.ogc.OGCGeometry + .fromBinary(in.buffer.nioBuffer(in.start, in.end - in.start)); + + tmp.add(geom.getEsriGeometry()); + + if(init.value == 0) { + init.value = 1; + srid.value = geom.SRID(); + } + } // end of sout block + } + + @Override + public void output() { + if (nonNullCount.value > 0) { + out.isSet = 1; + + java.util.ArrayList<com.esri.core.geometry.Geometry> tmp = (java.util.ArrayList<com.esri.core.geometry.Geometry>) value.obj; + + com.esri.core.geometry.SpatialReference spatialRef = null; + if(srid.value != 0){ + spatialRef = com.esri.core.geometry.SpatialReference.create(4326); + } + com.esri.core.geometry.Geometry[] geomArr = + (com.esri.core.geometry.Geometry[]) tmp.toArray( new com.esri.core.geometry.Geometry[0] ); + com.esri.core.geometry.Geometry geom = com.esri.core.geometry.GeometryEngine.union(geomArr, spatialRef); + + com.esri.core.geometry.ogc.OGCGeometry unionGeom = com.esri.core.geometry.ogc.OGCGeometry.createFromEsriGeometry(geom, spatialRef); + java.nio.ByteBuffer unionGeomBytes = unionGeom.asBinary(); + + int outputSize = unionGeomBytes.remaining(); + buf = out.buffer = buf.reallocIfNeeded(outputSize); + out.start = 0; + out.end = outputSize; + buf.setBytes(0, unionGeomBytes); + } else { + out.isSet = 0; + } + } + + @Override + public void reset() { + value = new ObjectHolder(); + value.obj = new java.util.ArrayList<com.esri.core.geometry.Geometry>(); + init.value = 0; + nonNullCount.value = 0; + } +} diff --git a/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STXFunc.java b/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STXFunc.java new file mode 100644 index 0000000000..e96a6d0c38 --- /dev/null +++ b/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STXFunc.java @@ -0,0 +1,64 @@ +/** + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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.apache.drill.exec.expr.fn.impl.gis; + +import java.sql.Types; + +import javax.inject.Inject; + +import org.apache.drill.exec.expr.DrillSimpleFunc; +import org.apache.drill.exec.expr.annotations.FunctionTemplate; +import org.apache.drill.exec.expr.annotations.Output; +import org.apache.drill.exec.expr.annotations.Param; +import org.apache.drill.exec.expr.holders.Float8Holder; +import org.apache.drill.exec.expr.holders.VarBinaryHolder; + +import com.esri.core.geometry.Geometry.Type; +import com.esri.core.geometry.ogc.OGCPoint; + +import io.netty.buffer.DrillBuf; + +@FunctionTemplate(name = "st_x", scope = FunctionTemplate.FunctionScope.SIMPLE, + nulls = FunctionTemplate.NullHandling.NULL_IF_NULL) +public class STXFunc implements DrillSimpleFunc { + @Param + VarBinaryHolder geomParam; + + @Output + Float8Holder out; + + @Inject + DrillBuf buffer; + + public void setup() { + } + + public void eval() { + + com.esri.core.geometry.ogc.OGCGeometry geom; + + geom = com.esri.core.geometry.ogc.OGCGeometry + .fromBinary(geomParam.buffer.nioBuffer(geomParam.start, geomParam.end - geomParam.start)); + + if(geom != null && geom.geometryType().equals("Point")){ + out.value = ((com.esri.core.geometry.ogc.OGCPoint) geom).X(); + } else { + out.value = Double.NaN; + } + } +} diff --git a/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STXMax.java b/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STXMax.java new file mode 100644 index 0000000000..08526a6937 --- /dev/null +++ b/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STXMax.java @@ -0,0 +1,61 @@ +/** + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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.apache.drill.exec.expr.fn.impl.gis; + +import javax.inject.Inject; + +import org.apache.drill.exec.expr.DrillSimpleFunc; +import org.apache.drill.exec.expr.annotations.FunctionTemplate; +import org.apache.drill.exec.expr.annotations.Output; +import org.apache.drill.exec.expr.annotations.Param; +import org.apache.drill.exec.expr.holders.Float8Holder; +import org.apache.drill.exec.expr.holders.VarBinaryHolder; + +import io.netty.buffer.DrillBuf; + +@FunctionTemplate(name = "st_xmax", scope = FunctionTemplate.FunctionScope.SIMPLE, + nulls = FunctionTemplate.NullHandling.NULL_IF_NULL) +public class STXMax implements DrillSimpleFunc { + @Param + VarBinaryHolder geom1Param; + + @Output + Float8Holder out; + + @Inject + DrillBuf buffer; + + public void setup() { + } + + public void eval() { + com.esri.core.geometry.ogc.OGCGeometry geom1; + geom1 = com.esri.core.geometry.ogc.OGCGeometry + .fromBinary(geom1Param.buffer.nioBuffer(geom1Param.start, geom1Param.end - geom1Param.start)); + + com.esri.core.geometry.ogc.OGCGeometry envelopeGeom; + if(geom1.geometryType().equals("Point")){ + out.value = ((com.esri.core.geometry.ogc.OGCPoint) geom1).X(); + } + else{ + com.esri.core.geometry.Envelope envelope = new com.esri.core.geometry.Envelope(); + geom1.getEsriGeometry().queryEnvelope(envelope); + out.value = envelope.getXMax(); + } + } +} diff --git a/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STXMin.java b/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STXMin.java new file mode 100644 index 0000000000..ed206157ba --- /dev/null +++ b/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STXMin.java @@ -0,0 +1,61 @@ +/** + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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.apache.drill.exec.expr.fn.impl.gis; + +import javax.inject.Inject; + +import org.apache.drill.exec.expr.DrillSimpleFunc; +import org.apache.drill.exec.expr.annotations.FunctionTemplate; +import org.apache.drill.exec.expr.annotations.Output; +import org.apache.drill.exec.expr.annotations.Param; +import org.apache.drill.exec.expr.holders.Float8Holder; +import org.apache.drill.exec.expr.holders.VarBinaryHolder; + +import io.netty.buffer.DrillBuf; + +@FunctionTemplate(name = "st_xmin", scope = FunctionTemplate.FunctionScope.SIMPLE, + nulls = FunctionTemplate.NullHandling.NULL_IF_NULL) +public class STXMin implements DrillSimpleFunc { + @Param + VarBinaryHolder geom1Param; + + @Output + Float8Holder out; + + @Inject + DrillBuf buffer; + + public void setup() { + } + + public void eval() { + com.esri.core.geometry.ogc.OGCGeometry geom1; + geom1 = com.esri.core.geometry.ogc.OGCGeometry + .fromBinary(geom1Param.buffer.nioBuffer(geom1Param.start, geom1Param.end - geom1Param.start)); + + com.esri.core.geometry.ogc.OGCGeometry envelopeGeom; + if(geom1.geometryType().equals("Point")){ + out.value = ((com.esri.core.geometry.ogc.OGCPoint) geom1).X(); + } + else{ + com.esri.core.geometry.Envelope envelope = new com.esri.core.geometry.Envelope(); + geom1.getEsriGeometry().queryEnvelope(envelope); + out.value = envelope.getXMin(); + } + } +} diff --git a/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STYFunc.java b/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STYFunc.java new file mode 100644 index 0000000000..5a46609719 --- /dev/null +++ b/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STYFunc.java @@ -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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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.apache.drill.exec.expr.fn.impl.gis; + +import javax.inject.Inject; + +import org.apache.drill.exec.expr.DrillSimpleFunc; +import org.apache.drill.exec.expr.annotations.FunctionTemplate; +import org.apache.drill.exec.expr.annotations.Output; +import org.apache.drill.exec.expr.annotations.Param; +import org.apache.drill.exec.expr.holders.Float8Holder; +import org.apache.drill.exec.expr.holders.VarBinaryHolder; + +import com.esri.core.geometry.Geometry.Type; +import com.esri.core.geometry.ogc.OGCPoint; + +import io.netty.buffer.DrillBuf; + +@FunctionTemplate(name = "st_y", scope = FunctionTemplate.FunctionScope.SIMPLE, + nulls = FunctionTemplate.NullHandling.NULL_IF_NULL) +public class STYFunc implements DrillSimpleFunc { + @Param + VarBinaryHolder geomParam; + + @Output + Float8Holder out; + + @Inject + DrillBuf buffer; + + public void setup() { + } + + public void eval() { + + com.esri.core.geometry.ogc.OGCGeometry geom; + + geom = com.esri.core.geometry.ogc.OGCGeometry + .fromBinary(geomParam.buffer.nioBuffer(geomParam.start, geomParam.end - geomParam.start)); + + if(geom != null && geom.geometryType().equals("Point")){ + out.value = ((com.esri.core.geometry.ogc.OGCPoint) geom).Y(); + } else { + out.value = Double.NaN; + } + } +} diff --git a/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STYMax.java b/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STYMax.java new file mode 100644 index 0000000000..109a0e1e92 --- /dev/null +++ b/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STYMax.java @@ -0,0 +1,61 @@ +/** + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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.apache.drill.exec.expr.fn.impl.gis; + +import javax.inject.Inject; + +import org.apache.drill.exec.expr.DrillSimpleFunc; +import org.apache.drill.exec.expr.annotations.FunctionTemplate; +import org.apache.drill.exec.expr.annotations.Output; +import org.apache.drill.exec.expr.annotations.Param; +import org.apache.drill.exec.expr.holders.Float8Holder; +import org.apache.drill.exec.expr.holders.VarBinaryHolder; + +import io.netty.buffer.DrillBuf; + +@FunctionTemplate(name = "st_ymax", scope = FunctionTemplate.FunctionScope.SIMPLE, + nulls = FunctionTemplate.NullHandling.NULL_IF_NULL) +public class STYMax implements DrillSimpleFunc { + @Param + VarBinaryHolder geom1Param; + + @Output + Float8Holder out; + + @Inject + DrillBuf buffer; + + public void setup() { + } + + public void eval() { + com.esri.core.geometry.ogc.OGCGeometry geom1; + geom1 = com.esri.core.geometry.ogc.OGCGeometry + .fromBinary(geom1Param.buffer.nioBuffer(geom1Param.start, geom1Param.end - geom1Param.start)); + + com.esri.core.geometry.ogc.OGCGeometry envelopeGeom; + if(geom1.geometryType().equals("Point")){ + out.value = ((com.esri.core.geometry.ogc.OGCPoint) geom1).Y(); + } + else{ + com.esri.core.geometry.Envelope envelope = new com.esri.core.geometry.Envelope(); + geom1.getEsriGeometry().queryEnvelope(envelope); + out.value = envelope.getYMax(); + } + } +} diff --git a/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STYMin.java b/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STYMin.java new file mode 100644 index 0000000000..6f78cc6a73 --- /dev/null +++ b/contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STYMin.java @@ -0,0 +1,61 @@ +/** + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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.apache.drill.exec.expr.fn.impl.gis; + +import javax.inject.Inject; + +import org.apache.drill.exec.expr.DrillSimpleFunc; +import org.apache.drill.exec.expr.annotations.FunctionTemplate; +import org.apache.drill.exec.expr.annotations.Output; +import org.apache.drill.exec.expr.annotations.Param; +import org.apache.drill.exec.expr.holders.Float8Holder; +import org.apache.drill.exec.expr.holders.VarBinaryHolder; + +import io.netty.buffer.DrillBuf; + +@FunctionTemplate(name = "st_ymin", scope = FunctionTemplate.FunctionScope.SIMPLE, + nulls = FunctionTemplate.NullHandling.NULL_IF_NULL) +public class STYMin implements DrillSimpleFunc { + @Param + VarBinaryHolder geom1Param; + + @Output + Float8Holder out; + + @Inject + DrillBuf buffer; + + public void setup() { + } + + public void eval() { + com.esri.core.geometry.ogc.OGCGeometry geom1; + geom1 = com.esri.core.geometry.ogc.OGCGeometry + .fromBinary(geom1Param.buffer.nioBuffer(geom1Param.start, geom1Param.end - geom1Param.start)); + + com.esri.core.geometry.ogc.OGCGeometry envelopeGeom; + if(geom1.geometryType().equals("Point")){ + out.value = ((com.esri.core.geometry.ogc.OGCPoint) geom1).Y(); + } + else{ + com.esri.core.geometry.Envelope envelope = new com.esri.core.geometry.Envelope(); + geom1.getEsriGeometry().queryEnvelope(envelope); + out.value = envelope.getYMin(); + } + } +} diff --git a/contrib/gis/src/test/java/org/apache/drill/exec/expr/fn/impl/gis/TestGeometryFunctions.java b/contrib/gis/src/test/java/org/apache/drill/exec/expr/fn/impl/gis/TestGeometryFunctions.java index 059fb363a3..c909a16cc8 100644 --- a/contrib/gis/src/test/java/org/apache/drill/exec/expr/fn/impl/gis/TestGeometryFunctions.java +++ b/contrib/gis/src/test/java/org/apache/drill/exec/expr/fn/impl/gis/TestGeometryFunctions.java @@ -72,4 +72,241 @@ public void testSTWithinQuery() throws Exception { .build() .run(); } -} \ No newline at end of file + + @Test + public void testSTXQuery() throws Exception { + + testBuilder() + .sqlQuery("select ST_X(ST_Point(-121.895, 37.339)) " + + "from cp.`/sample-data/CA-cities.csv` limit 1") + .ordered().baselineColumns("EXPR$0") + .baselineValues(-121.895) + .build() + .run(); + } + + @Test + public void testSTYQuery() throws Exception { + + testBuilder() + .sqlQuery("select ST_Y(ST_Point(-121.895, 37.339)) " + + "from cp.`/sample-data/CA-cities.csv` limit 1") + .ordered().baselineColumns("EXPR$0") + .baselineValues(37.339) + .build() + .run(); + } + + + @Test + public void testSTX_STYGivesNaNForNonPointGeometry() throws Exception { + + testBuilder() + .sqlQuery("select ST_X(ST_GeomFromText('MULTIPOINT((16 64))')) " + + "from (VALUES(1))") + .ordered().baselineColumns("EXPR$0") + .baselineValues(Double.NaN) + .build() + .run(); + + testBuilder() + .sqlQuery("select ST_Y(ST_GeomFromText('MULTIPOINT((16 64))')) " + + "from (VALUES(1))") + .ordered().baselineColumns("EXPR$0") + .baselineValues(Double.NaN) + .build() + .run(); + } + + + @Test + public void testIntersectQuery() throws Exception { + + testBuilder() + .sqlQuery("SELECT ST_Intersects(ST_GeomFromText('POINT(0 0)'), ST_GeomFromText('LINESTRING(2 0,0 2)')) " + + "from (VALUES(1))") + .ordered().baselineColumns("EXPR$0") + .baselineValues(false) + .build() + .run(); + + testBuilder() + .sqlQuery("SELECT ST_Intersects(ST_GeomFromText('POINT(0 0)'), ST_GeomFromText('LINESTRING(0 0,0 2)')) " + + "from (VALUES(1))") + .ordered().baselineColumns("EXPR$0") + .baselineValues(true) + .build() + .run(); + } + + @Test + public void testRelateQuery() throws Exception { + + testBuilder() + .sqlQuery("SELECT ST_Relate(ST_GeomFromText('POINT(1 2)'), ST_Buffer(ST_GeomFromText('POINT(1 2)'),2), '0FFFFF212') " + + "from (VALUES(1))") + .ordered().baselineColumns("EXPR$0") + .baselineValues(true) + .build() + .run(); + + testBuilder() + .sqlQuery("SELECT ST_Relate(ST_GeomFromText('POINT(1 2)'), ST_Buffer(ST_GeomFromText('POINT(1 2)'),2), '*FF*FF212') " + + "from (VALUES(1))") + .ordered().baselineColumns("EXPR$0") + .baselineValues(true) + .build() + .run(); + + testBuilder() + .sqlQuery("SELECT ST_Relate(ST_GeomFromText('POINT(0 0)'), ST_Buffer(ST_GeomFromText('POINT(1 2)'),2), '*FF*FF212') " + + "from (VALUES(1))") + .ordered().baselineColumns("EXPR$0") + .baselineValues(false) + .build() + .run(); + + } + + @Test + public void testTouchesQuery() throws Exception { + + testBuilder() + .sqlQuery("SELECT ST_Touches(ST_GeomFromText('LINESTRING(0 0, 1 1, 0 2)'), ST_GeomFromText('POINT(1 1)')) " + + "from (VALUES(1))") + .ordered().baselineColumns("EXPR$0") + .baselineValues(false) + .build() + .run(); + + testBuilder() + .sqlQuery("SELECT ST_Touches(ST_GeomFromText('LINESTRING(0 0, 1 1, 0 2)'), ST_GeomFromText('POINT(0 2)')) " + + "from (VALUES(1))") + .ordered().baselineColumns("EXPR$0") + .baselineValues(true) + .build() + .run(); + + } + + @Test + public void testEqualsQuery() throws Exception { + + testBuilder() + .sqlQuery("SELECT ST_Equals(ST_GeomFromText('LINESTRING(0 0, 10 10)'), " + + "ST_GeomFromText('LINESTRING(0 0, 5 5, 10 10)')) from (VALUES(1))") + .ordered().baselineColumns("EXPR$0") + .baselineValues(true) + .build() + .run(); + + } + + @Test + public void testContainsQuery() throws Exception { + + testBuilder() + .sqlQuery("SELECT ST_Contains(smallc, bigc) As smallcontainsbig, " + + "ST_Contains(bigc,smallc) As bigcontainssmall, " + + "ST_Contains(bigc, ST_Union(smallc, bigc)) as bigcontainsunion, " + + "ST_Equals(bigc, ST_Union(smallc, bigc)) as bigisunion " + + "FROM (SELECT ST_Buffer(ST_GeomFromText('POINT(1 2)'), 10) As smallc, " + + "ST_Buffer(ST_GeomFromText('POINT(1 2)'), 20) As bigc from (VALUES(1)) ) As foo") + .ordered().baselineColumns("smallcontainsbig", "bigcontainssmall", "bigcontainsunion", "bigisunion") + .baselineValues(false, true, true, true) + .build() + .run(); + + } + + @Test + public void testOverlapsCrossesIntersectsContainsQuery() throws Exception { + + testBuilder() + .sqlQuery("SELECT ST_Overlaps(a,b) As a_overlap_b, " + + "ST_Crosses(a,b) As a_crosses_b, " + + "ST_Intersects(a, b) As a_intersects_b, " + + "ST_Contains(b,a) As b_contains_a " + + "FROM (SELECT ST_GeomFromText('POINT(1 0.5)') As a, ST_GeomFromText('LINESTRING(1 0, 1 1, 3 5)') As b " + + "from (VALUES(1)) ) As foo") + .ordered().baselineColumns("a_overlap_b", "a_crosses_b", "a_intersects_b", "b_contains_a") + .baselineValues(false, false, true, true) + .build() + .run(); + + } + + @Test + public void testDisjointQuery() throws Exception { + + testBuilder() + .sqlQuery("SELECT ST_Disjoint(ST_GeomFromText('POINT(0 0)'), ST_GeomFromText('LINESTRING( 2 0, 0 2 )')) " + + "from (VALUES(1))") + .ordered().baselineColumns("EXPR$0") + .baselineValues(true) + .build() + .run(); + + testBuilder() + .sqlQuery("SELECT ST_Disjoint(ST_GeomFromText('POINT(0 0)'), ST_GeomFromText('LINESTRING( 0 0, 0 2 )')) " + + "from (VALUES(1))") + .ordered().baselineColumns("EXPR$0") + .baselineValues(false) + .build() + .run(); + + } + + @Test + public void testTransfromQuery() throws Exception { + double targetX = -71.1776848522251; + double targetY = 42.3902896512902; + + testBuilder() + .sqlQuery("SELECT round(st_x(st_transform(st_geomfromtext('POINT (743238 2967416)'), 2249, 4326)), 13)," + + " round(st_y(st_transform(st_geomfromtext('POINT (743238 2967416)'), 2249, 4326)), 13) from (VALUES(1))") + .ordered().baselineColumns("EXPR$0", "EXPR$1") + .baselineValues(targetX, targetY) + .build() + .run(); + } + + @Test + public void testUnionAggregateQuery() throws Exception { + String targetAll = "MULTIPOLYGON (((0 -1, 1 -1, 1 0, 1 1, 0 1, 0 0, 0 -1)), " + + "((10 9, 11 9, 11 10, 11 11, 10 11, 10 10, 10 9)))"; + String targetFirstGroup = "POLYGON ((0 -1, 1 -1, 1 0, 1 1, 0 1, 0 0, 0 -1))"; + String targetSecondGroup = "POLYGON ((10 9, 11 9, 11 10, 11 11, 10 11, 10 10, 10 9))"; + + testBuilder() + .sqlQuery("select ST_AsText(ST_UnionAggregate(ST_GeomFromText(columns[1]))) from cp.`sample-data/polygons.tsv`") + .ordered().baselineColumns("EXPR$0") + .baselineValues(targetAll) + .build() + .run(); + + testBuilder() + .sqlQuery("select columns[0], ST_AsText(ST_UnionAggregate(ST_GeomFromText(columns[1])))" + + " from cp.`sample-data/polygons.tsv` group by columns[0] having columns[0] = 1") + .ordered().baselineColumns("EXPR$0", "EXPR$1") + .baselineValues("1", targetFirstGroup) + .build() + .run(); + + testBuilder() + .sqlQuery("select columns[0], ST_AsText(ST_UnionAggregate(ST_GeomFromText(columns[1])))" + + " from cp.`sample-data/polygons.tsv` group by columns[0] having columns[0] = 2") + .ordered().baselineColumns("EXPR$0", "EXPR$1") + .baselineValues("2", targetSecondGroup) + .build() + .run(); + + testBuilder() + .sqlQuery("select count(*) from (select columns[0], ST_AsText(ST_UnionAggregate(ST_GeomFromText(columns[1])))" + + " from cp.`sample-data/polygons.tsv` group by columns[0])") + .ordered().baselineColumns("EXPR$0") + .baselineValues(2L) + .build() + .run(); + } +} ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Support more functions in gis contrib module > -------------------------------------------- > > Key: DRILL-4091 > URL: https://issues.apache.org/jira/browse/DRILL-4091 > Project: Apache Drill > Issue Type: Improvement > Components: Functions - Drill > Reporter: Karol Potocki > Assignee: Karol Potocki > Priority: Major > Labels: ready-to-commit > > Support for commonly used gis functions in gis contrib module: relate, > contains, crosses, intersects, touches, difference, disjoint, buffer, union > etc. -- This message was sent by Atlassian JIRA (v7.6.3#76005)