You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@tajo.apache.org by jinossy <gi...@git.apache.org> on 2015/04/06 08:25:11 UTC

[GitHub] tajo pull request: TAJO-1529: Implement json_extract_path_text(str...

GitHub user jinossy opened a pull request:

    https://github.com/apache/tajo/pull/512

    TAJO-1529: Implement json_extract_path_text(string, string) function

    

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

    $ git pull https://github.com/jinossy/tajo TAJO-1529

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

    https://github.com/apache/tajo/pull/512.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 #512
    
----
commit dcad10beb9263592f453492245d6b62802927c68
Author: Jinho Kim <jh...@apache.org>
Date:   2015-04-06T06:23:33Z

    TAJO-1529: Implement json_extract_path_text(string, string) function

commit 74a6ec6d1c3da3fdcf011836cb0d4c9c0a26a5ef
Author: Jinho Kim <jh...@apache.org>
Date:   2015-04-06T06:23:48Z

    Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/tajo into TAJO-1529

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] tajo pull request: TAJO-1529: Implement json_extract_path_text(str...

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

    https://github.com/apache/tajo/pull/512#discussion_r27851381
  
    --- Diff: tajo-core/src/main/java/org/apache/tajo/engine/function/json/JsonExtractPathText.java ---
    @@ -0,0 +1,86 @@
    +/**
    + * 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.apache.tajo.engine.function.json;
    +
    +import com.jayway.jsonpath.JsonPath;
    +import net.minidev.json.JSONObject;
    +import net.minidev.json.parser.JSONParser;
    +import org.apache.tajo.catalog.Column;
    +import org.apache.tajo.common.TajoDataTypes;
    +import org.apache.tajo.datum.Datum;
    +import org.apache.tajo.datum.DatumFactory;
    +import org.apache.tajo.datum.NullDatum;
    +import org.apache.tajo.engine.function.annotation.Description;
    +import org.apache.tajo.engine.function.annotation.ParamTypes;
    +import org.apache.tajo.plan.function.GeneralFunction;
    +import org.apache.tajo.storage.Tuple;
    +
    +/**
    + * json_extract_path_text(string, string) -
    + * Extracts JSON string from a JSON string based on json path specified,
    + * and returns JSON string pointed to by xPath.
    + *
    + *
    + * Returns null if either argument is null.
    + *
    + * Example:
    + * SELECT json_extract_path_text('{"sample" : {"name" : "tajo"}}','$.sample.name') FROM src LIMIT 1;\n"
    + * -> result: 'tajo'
    + */
    +@Description(
    +    functionName = "json_extract_path_text",
    +    description = "Returns JSON string pointed to by xPath",
    +    detail = "Extracts JSON string from a JSON string based on json path specified,\n"
    +        + "and returns JSON string pointed to by xPath.",
    +    example = "> SELECT json_extract_path_text('{\"sample\" : {\"name\" : \"tajo\"}}','$.sample.name');\n"
    +        + "tajo",
    +    returnType = TajoDataTypes.Type.TEXT,
    +    paramTypes = {@ParamTypes(paramTypes = {TajoDataTypes.Type.TEXT, TajoDataTypes.Type.TEXT})}
    +)
    +public class JsonExtractPathText extends GeneralFunction {
    +  private JSONParser parser;
    +
    +  public JsonExtractPathText() {
    +    super(new Column[]{
    +        new Column("string", TajoDataTypes.Type.TEXT),
    +        new Column("string", TajoDataTypes.Type.TEXT),
    +    });
    +    parser = new JSONParser(JSONParser.MODE_JSON_SIMPLE | JSONParser.IGNORE_CONTROL_CHAR);
    --- End diff --
    
    I agree, we need pre-initialization with const params


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] tajo pull request: TAJO-1529: Implement json_extract_path_text(str...

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

    https://github.com/apache/tajo/pull/512#discussion_r27849794
  
    --- Diff: tajo-core/src/main/java/org/apache/tajo/engine/function/json/JsonExtractPathText.java ---
    @@ -0,0 +1,86 @@
    +/**
    + * 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.apache.tajo.engine.function.json;
    +
    +import com.jayway.jsonpath.JsonPath;
    +import net.minidev.json.JSONObject;
    +import net.minidev.json.parser.JSONParser;
    +import org.apache.tajo.catalog.Column;
    +import org.apache.tajo.common.TajoDataTypes;
    +import org.apache.tajo.datum.Datum;
    +import org.apache.tajo.datum.DatumFactory;
    +import org.apache.tajo.datum.NullDatum;
    +import org.apache.tajo.engine.function.annotation.Description;
    +import org.apache.tajo.engine.function.annotation.ParamTypes;
    +import org.apache.tajo.plan.function.GeneralFunction;
    +import org.apache.tajo.storage.Tuple;
    +
    +/**
    + * json_extract_path_text(string, string) -
    + * Extracts JSON string from a JSON string based on json path specified,
    + * and returns JSON string pointed to by xPath.
    + *
    + *
    + * Returns null if either argument is null.
    + *
    + * Example:
    + * SELECT json_extract_path_text('{"sample" : {"name" : "tajo"}}','$.sample.name') FROM src LIMIT 1;\n"
    + * -> result: 'tajo'
    + */
    +@Description(
    +    functionName = "json_extract_path_text",
    +    description = "Returns JSON string pointed to by xPath",
    +    detail = "Extracts JSON string from a JSON string based on json path specified,\n"
    +        + "and returns JSON string pointed to by xPath.",
    +    example = "> SELECT json_extract_path_text('{\"sample\" : {\"name\" : \"tajo\"}}','$.sample.name');\n"
    +        + "tajo",
    +    returnType = TajoDataTypes.Type.TEXT,
    +    paramTypes = {@ParamTypes(paramTypes = {TajoDataTypes.Type.TEXT, TajoDataTypes.Type.TEXT})}
    +)
    +public class JsonExtractPathText extends GeneralFunction {
    +  private JSONParser parser;
    +
    +  public JsonExtractPathText() {
    +    super(new Column[]{
    +        new Column("string", TajoDataTypes.Type.TEXT),
    +        new Column("string", TajoDataTypes.Type.TEXT),
    +    });
    +    parser = new JSONParser(JSONParser.MODE_JSON_SIMPLE | JSONParser.IGNORE_CONTROL_CHAR);
    --- End diff --
    
    It would be better if this initialization is moved into bind(Schema) method.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] tajo pull request: TAJO-1529: Implement json_extract_path_text(str...

Posted by jihoonson <gi...@git.apache.org>.
Github user jihoonson commented on the pull request:

    https://github.com/apache/tajo/pull/512#issuecomment-90106275
  
    +1
    Thanks for your nice work!


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] tajo pull request: TAJO-1529: Implement json_extract_path_text(str...

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

    https://github.com/apache/tajo/pull/512#discussion_r27850825
  
    --- Diff: tajo-core/src/main/java/org/apache/tajo/engine/function/json/JsonExtractPathText.java ---
    @@ -0,0 +1,86 @@
    +/**
    + * 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.apache.tajo.engine.function.json;
    +
    +import com.jayway.jsonpath.JsonPath;
    +import net.minidev.json.JSONObject;
    +import net.minidev.json.parser.JSONParser;
    +import org.apache.tajo.catalog.Column;
    +import org.apache.tajo.common.TajoDataTypes;
    +import org.apache.tajo.datum.Datum;
    +import org.apache.tajo.datum.DatumFactory;
    +import org.apache.tajo.datum.NullDatum;
    +import org.apache.tajo.engine.function.annotation.Description;
    +import org.apache.tajo.engine.function.annotation.ParamTypes;
    +import org.apache.tajo.plan.function.GeneralFunction;
    +import org.apache.tajo.storage.Tuple;
    +
    +/**
    + * json_extract_path_text(string, string) -
    + * Extracts JSON string from a JSON string based on json path specified,
    + * and returns JSON string pointed to by xPath.
    + *
    + *
    + * Returns null if either argument is null.
    + *
    + * Example:
    + * SELECT json_extract_path_text('{"sample" : {"name" : "tajo"}}','$.sample.name') FROM src LIMIT 1;\n"
    + * -> result: 'tajo'
    + */
    +@Description(
    +    functionName = "json_extract_path_text",
    +    description = "Returns JSON string pointed to by xPath",
    +    detail = "Extracts JSON string from a JSON string based on json path specified,\n"
    +        + "and returns JSON string pointed to by xPath.",
    +    example = "> SELECT json_extract_path_text('{\"sample\" : {\"name\" : \"tajo\"}}','$.sample.name');\n"
    +        + "tajo",
    +    returnType = TajoDataTypes.Type.TEXT,
    +    paramTypes = {@ParamTypes(paramTypes = {TajoDataTypes.Type.TEXT, TajoDataTypes.Type.TEXT})}
    +)
    +public class JsonExtractPathText extends GeneralFunction {
    +  private JSONParser parser;
    +
    +  public JsonExtractPathText() {
    +    super(new Column[]{
    +        new Column("string", TajoDataTypes.Type.TEXT),
    +        new Column("string", TajoDataTypes.Type.TEXT),
    +    });
    +    parser = new JSONParser(JSONParser.MODE_JSON_SIMPLE | JSONParser.IGNORE_CONTROL_CHAR);
    --- End diff --
    
    I misunderstood it. It's just a function. So, it does not have bind() method. We may need pre-initialization method like bind in Eval.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] tajo pull request: TAJO-1529: Implement json_extract_path_text(str...

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

    https://github.com/apache/tajo/pull/512


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---