nebula icon indicating copy to clipboard operation
nebula copied to clipboard

function to parse json format string prop

Open wey-gu opened this issue 3 years ago • 8 comments

context: https://discuss.nebula-graph.com.cn/t/topic/6991

wey-gu avatar Dec 21 '21 02:12 wey-gu

Return a map?

jievince avatar Dec 21 '21 11:12 jievince

Hello. I am Akshata Kulkarni. I am interested in working on this issue. Is this issue still open to work on??It would be my first issue. Could you also please guide through this issue.Thanks

akshatakulkarni25 avatar Sep 05 '22 07:09 akshatakulkarni25

Dear @akshatakulkarni25 ,

Welcome to the community, this issue is still open!

I think a function similar to JSON_EXTRACT could be introduced here.

@jievince do you see it as reasonable/feasible?

why

The motivation of this issue was NebulaGraph doesn't support nested datatype, in some cases, user may like to serialize JSON data in a string as properties of Tag/edgeType, thus, this function would enable data extracting in return expression. (We should consider stopping user from using it in filter expression, as this will lead to a data full scan. @jievince ? )

what

  • It takes a string and returns a map:
YIELD JSON_EXTRACT('{"a": 1, "b": 2, "c": {"d": 4}}') AS map_foo
+-------------------------+
| map_foo                 |
+-------------------------+
| {a: 1, b: 2, c: {d: 4}} |
+-------------------------+

~~- It takes path as args, too (@jievince do you think this is needed?, this makes the function a lot more complex to be implemented)~~

YIELD JSON_EXTRACT('{"a": 1, "b": 2, "c": {"d": 4}}', '$.c') AS map_foo_dot_c
+-----------+
| map_foo   |
+-----------+
| {d: 4}    |
+-----------+

wey-gu avatar Sep 05 '22 07:09 wey-gu

Dear @akshatakulkarni25 ,

Welcome to the community, this issue is still open!

I think a function similar to JSON_EXTRACT could be introduced here.

@jievince do you see it as reasonable/feasible?

why

The motivation of this issue was NebulaGraph doesn't support nested datatype, in some cases, user may like to serialize JSON data in a string as properties of Tag/edgeType, thus, this function would enable data extracting in return expression. (We should consider stopping user from using it in filter expression, as this will lead to a data full scan. @jievince ? )

what

  • It takes a string and returns a map:
YIELD JSON_EXTRACT('{"a": 1, "b": 2, "c": {"d": 4}}') AS map_foo
+-------------------------+
| map_foo                 |
+-------------------------+
| {a: 1, b: 2, c: {d: 4}} |
+-------------------------+
  • It takes path as args, too (@jievince do you think this is needed?, this makes the function a lot more complex to be implemented)
YIELD JSON_EXTRACT('{"a": 1, "b": 2, "c": {"d": 4}}', '$.c') AS map_foo_dot_c
+-----------+
| map_foo   |
+-----------+
| {d: 4}    |
+-----------+

That's a good point. But it may be a bit troublesome to implement all the json functions in mysql. I suggest you could first implement a simple function, such as convertToMap, which takes a json string, and returns a map value it represents.

jievince avatar Sep 05 '22 07:09 jievince

The implementation of the builtin functions is here: https://github.com/vesoft-inc/nebula/blob/master/src/common/function/FunctionManager.cpp

Looking forward to your contribution.

jievince avatar Sep 05 '22 08:09 jievince

also, one PR on introducing functions here

Let us know your questions any time :) @akshatakulkarni25

wey-gu avatar Sep 05 '22 08:09 wey-gu

Respected Sir,

Thank you for your reply. I look forward to learning from and contributing to the repository.

Could I also reach out to you in case I have any doubts or queries throughout the process through emails

Thank you.

Regards, Akshata Kulkarni On Mon, 5 Sep 2022 at 1:43 PM, Wey Gu @.***> wrote:

also, one PR on introducing functions here https://github.com/vesoft-inc/nebula/pull/4526

— Reply to this email directly, view it on GitHub https://github.com/vesoft-inc/nebula/issues/3513#issuecomment-1236677597, or unsubscribe https://github.com/notifications/unsubscribe-auth/AYHIZFKB7YX3VH3B56ULTC3V4WTSHANCNFSM5KPCCL2A . You are receiving this because you were mentioned.Message ID: @.***>

akshatakulkarni25 avatar Sep 05 '22 08:09 akshatakulkarni25

Dear @akshatakulkarni25 , Sure, you could mail/slack me when needed :)

  • email could be found: https://siwei.io/en/about/#contact
  • slack

wey-gu avatar Sep 05 '22 08:09 wey-gu

Hi @akshatakulkarni25

May I know your status on this issue? It's ok if you could not make it, I am trying to prepare a PR on it, and in case yours is ready, we could co-work on yours instead.

Thanks!

wey-gu avatar Oct 19 '22 03:10 wey-gu

checked on 3.3-rc checked on 3.3-ent-rc

jinyingsunny avatar Oct 26 '22 02:10 jinyingsunny