You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@drill.apache.org by ChrisSandison <gi...@git.apache.org> on 2017/11/14 21:27:12 UTC

[GitHub] drill pull request #1036: Adding ST_AsJSON functionality

GitHub user ChrisSandison opened a pull request:

    https://github.com/apache/drill/pull/1036

    Adding ST_AsJSON functionality

    Fixes #DRILL-5962

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/ChrisSandison/drill DRILL-5962

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/drill/pull/1036.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #1036
    
----
commit fe633ab7282d69b8eca30a255f84ec68f2bafb3b
Author: chris <ch...@thinkdataworks.com>
Date:   2017-11-14T21:26:21Z

    Adding ST_AsJSON functionality
    
    Fixes #DRILL-5962

----


---

[GitHub] drill pull request #1036: DRILL-5962: Adding ST_AsJSON functionality

Posted by arina-ielchiieva <gi...@git.apache.org>.
Github user arina-ielchiieva commented on a diff in the pull request:

    https://github.com/apache/drill/pull/1036#discussion_r151184263
  
    --- Diff: contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STAsJSON.java ---
    @@ -0,0 +1,59 @@
    +/*
    + * 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 org.apache.drill.exec.expr.holders.VarCharHolder;
    +
    +import io.netty.buffer.DrillBuf;
    +
    +@FunctionTemplate(name = "st_asjson", scope = FunctionTemplate.FunctionScope.SIMPLE,
    +  nulls = FunctionTemplate.NullHandling.NULL_IF_NULL)
    +public class STAsJSON implements DrillSimpleFunc {
    --- End diff --
    
    `StAsJson`


---

[GitHub] drill pull request #1036: DRILL-5962: Adding ST_AsJSON functionality

Posted by ChrisSandison <gi...@git.apache.org>.
Github user ChrisSandison commented on a diff in the pull request:

    https://github.com/apache/drill/pull/1036#discussion_r151142574
  
    --- Diff: contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STAsJSON.java ---
    @@ -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
    + *
    + * 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 org.apache.drill.exec.expr.holders.VarCharHolder;
    +
    +import io.netty.buffer.DrillBuf;
    +
    +@FunctionTemplate(name = "st_asjson", scope = FunctionTemplate.FunctionScope.SIMPLE,
    +  nulls = FunctionTemplate.NullHandling.NULL_IF_NULL)
    +public class STAsJSON implements DrillSimpleFunc {
    +  @Param
    +  VarBinaryHolder geom1Param;
    +
    +  @Output
    +  VarCharHolder out;
    +
    +  @Inject
    +  DrillBuf buffer;
    +
    +  public void setup() {
    +  }
    +
    +  public void eval() {
    +    com.esri.core.geometry.ogc.OGCGeometry geom1 = com.esri.core.geometry.ogc.OGCGeometry
    +      .fromBinary(geom1Param.buffer.nioBuffer(geom1Param.start, geom1Param.end - geom1Param.start));
    +
    +    String json = geom1.asJson();
    +
    +    int outputSize = json.getBytes().length;
    --- End diff --
    
    Good call, I'm going to make that same change in #1034 


---

[GitHub] drill pull request #1036: DRILL-5962: Adding ST_AsJSON functionality

Posted by arina-ielchiieva <gi...@git.apache.org>.
Github user arina-ielchiieva commented on a diff in the pull request:

    https://github.com/apache/drill/pull/1036#discussion_r151143439
  
    --- Diff: contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STAsJSON.java ---
    @@ -0,0 +1,58 @@
    +/**
    --- End diff --
    
    @ChrisSandison Apache header should be in a from of comment. Please here and in other PR.


---

[GitHub] drill pull request #1036: DRILL-5962: Adding ST_AsJSON functionality

Posted by brendanstennett <gi...@git.apache.org>.
Github user brendanstennett commented on a diff in the pull request:

    https://github.com/apache/drill/pull/1036#discussion_r151267136
  
    --- Diff: contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STAsJson.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.
    + */
    +
    +/*
    + * Wrapper for ESRI ST_AsJson to convert geometry into REST Json.
    + * Emulates functionality from spatial-framework-for-hadoop.
    + */
    +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 org.apache.drill.exec.expr.holders.VarCharHolder;
    +
    +import io.netty.buffer.DrillBuf;
    +
    +@FunctionTemplate(name = "st_as_json", scope = FunctionTemplate.FunctionScope.SIMPLE,
    +  nulls = FunctionTemplate.NullHandling.NULL_IF_NULL)
    +public class STAsJson implements DrillSimpleFunc {
    --- End diff --
    
    @ChrisSandison I would suggest naming this `ST_AsGeoJSON` to stay in line with the conventions set forth in PostGIS.
    
    http://www.postgis.net/docs/ST_AsGeoJSON.html


---

[GitHub] drill pull request #1036: DRILL-5962: Adding ST_AsJSON functionality

Posted by arina-ielchiieva <gi...@git.apache.org>.
Github user arina-ielchiieva commented on a diff in the pull request:

    https://github.com/apache/drill/pull/1036#discussion_r151184679
  
    --- Diff: contrib/gis/src/test/java/org/apache/drill/exec/expr/fn/impl/gis/TestGeometryFunctions.java ---
    @@ -49,6 +50,28 @@ public void testGeometryPointCreation() throws Exception {
       }
     
       @Test
    +  public void testJSONFromPointCreation() throws Exception {
    +    testBuilder()
    +      .sqlQuery("select ST_AsJSON(ST_Point(-121.895, 37.339)) "
    +        + "from cp.`/sample-data/CA-cities.csv` limit 1")
    +      .ordered().baselineColumns("EXPR$0")
    --- End diff --
    
    Please put `baselineColumns("EXPR$0")` to the new line.


---

[GitHub] drill pull request #1036: DRILL-5962: Adding ST_AsJSON functionality

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/drill/pull/1036


---

[GitHub] drill pull request #1036: DRILL-5962: Adding ST_AsJSON functionality

Posted by paul-rogers <gi...@git.apache.org>.
Github user paul-rogers commented on a diff in the pull request:

    https://github.com/apache/drill/pull/1036#discussion_r150999524
  
    --- Diff: contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STAsJSON.java ---
    @@ -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
    + *
    + * 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 org.apache.drill.exec.expr.holders.VarCharHolder;
    +
    +import io.netty.buffer.DrillBuf;
    +
    +@FunctionTemplate(name = "st_asjson", scope = FunctionTemplate.FunctionScope.SIMPLE,
    +  nulls = FunctionTemplate.NullHandling.NULL_IF_NULL)
    +public class STAsJSON implements DrillSimpleFunc {
    +  @Param
    +  VarBinaryHolder geom1Param;
    +
    +  @Output
    +  VarCharHolder out;
    +
    +  @Inject
    +  DrillBuf buffer;
    +
    +  public void setup() {
    +  }
    +
    +  public void eval() {
    +    com.esri.core.geometry.ogc.OGCGeometry geom1 = com.esri.core.geometry.ogc.OGCGeometry
    +      .fromBinary(geom1Param.buffer.nioBuffer(geom1Param.start, geom1Param.end - geom1Param.start));
    +
    +    String json = geom1.asJson();
    +
    +    int outputSize = json.getBytes().length;
    --- End diff --
    
    Better to cache the bytes, and use it twice, rather than converting the string from UTF-16 to UTF-8 twice.


---

[GitHub] drill pull request #1036: DRILL-5962: Adding ST_AsJSON functionality

Posted by arina-ielchiieva <gi...@git.apache.org>.
Github user arina-ielchiieva commented on a diff in the pull request:

    https://github.com/apache/drill/pull/1036#discussion_r151184326
  
    --- Diff: contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STAsJSON.java ---
    @@ -0,0 +1,59 @@
    +/*
    + * 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 org.apache.drill.exec.expr.holders.VarCharHolder;
    +
    +import io.netty.buffer.DrillBuf;
    +
    +@FunctionTemplate(name = "st_asjson", scope = FunctionTemplate.FunctionScope.SIMPLE,
    +  nulls = FunctionTemplate.NullHandling.NULL_IF_NULL)
    +public class STAsJSON implements DrillSimpleFunc {
    +  @Param
    +  VarBinaryHolder geom1Param;
    +
    +  @Output
    +  VarCharHolder out;
    +
    +  @Inject
    +  DrillBuf buffer;
    +
    +  public void setup() {
    +  }
    +
    +  public void eval() {
    +    com.esri.core.geometry.ogc.OGCGeometry geom1 = com.esri.core.geometry.ogc.OGCGeometry
    --- End diff --
    
    `geom`


---

[GitHub] drill pull request #1036: DRILL-5962: Adding ST_AsJSON functionality

Posted by arina-ielchiieva <gi...@git.apache.org>.
Github user arina-ielchiieva commented on a diff in the pull request:

    https://github.com/apache/drill/pull/1036#discussion_r151184182
  
    --- Diff: contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STAsJSON.java ---
    @@ -0,0 +1,59 @@
    +/*
    + * 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 org.apache.drill.exec.expr.holders.VarCharHolder;
    +
    +import io.netty.buffer.DrillBuf;
    +
    +@FunctionTemplate(name = "st_asjson", scope = FunctionTemplate.FunctionScope.SIMPLE,
    --- End diff --
    
    1. `st_as_json` (more sql like way)
    2. Please add description of the function in the java doc?


---

[GitHub] drill issue #1036: DRILL-5962: Adding ST_AsJSON functionality

Posted by arina-ielchiieva <gi...@git.apache.org>.
Github user arina-ielchiieva commented on the issue:

    https://github.com/apache/drill/pull/1036
  
    Please update commit message. +1, LGTM.


---

[GitHub] drill pull request #1036: DRILL-5962: Adding ST_AsJSON functionality

Posted by arina-ielchiieva <gi...@git.apache.org>.
Github user arina-ielchiieva commented on a diff in the pull request:

    https://github.com/apache/drill/pull/1036#discussion_r151184397
  
    --- Diff: contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STAsJSON.java ---
    @@ -0,0 +1,59 @@
    +/*
    + * 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 org.apache.drill.exec.expr.holders.VarCharHolder;
    +
    +import io.netty.buffer.DrillBuf;
    +
    +@FunctionTemplate(name = "st_asjson", scope = FunctionTemplate.FunctionScope.SIMPLE,
    +  nulls = FunctionTemplate.NullHandling.NULL_IF_NULL)
    +public class STAsJSON implements DrillSimpleFunc {
    +  @Param
    +  VarBinaryHolder geom1Param;
    --- End diff --
    
    `geomParam`


---

[GitHub] drill pull request #1036: DRILL-5962: Adding ST_AsJSON functionality

Posted by arina-ielchiieva <gi...@git.apache.org>.
Github user arina-ielchiieva commented on a diff in the pull request:

    https://github.com/apache/drill/pull/1036#discussion_r152032716
  
    --- Diff: contrib/gis/src/main/java/org/apache/drill/exec/expr/fn/impl/gis/STAsJson.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.
    + */
    +
    +/*
    + * Wrapper for ESRI ST_AsJson to convert geometry into REST Json.
    + * Emulates functionality from spatial-framework-for-hadoop.
    + */
    +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 org.apache.drill.exec.expr.holders.VarCharHolder;
    +
    +import io.netty.buffer.DrillBuf;
    +
    +@FunctionTemplate(name = "st_as_json", scope = FunctionTemplate.FunctionScope.SIMPLE,
    --- End diff --
    
    Please revert function name and squash the commits.


---