[GitHub] [age] AadilBashir489 commented on issue #113: How to work with dynamic property

2023-06-19 Thread via GitHub


AadilBashir489 commented on issue #113:
URL: https://github.com/apache/age/issues/113#issuecomment-1597173727

   I also the got exact same issue. I posted it on stackoverflow and got the 
answer.
   Answer:
   You can later use the SET clause to insert the properties. Assuming that 
{name: 'John Doe'} is the JSON provided by the user, the following code 
demonstrates its usage:
   `SELECT * FROM cypher('test', $$
 CREATE (:Person)   
   $$) AS (res agtype);  
res 
   -
   (0 rows)
   
   SELECT * FROM cypher('test', $$
 MATCH (n:Person)
 SET n = {name: 'John Doe'} 
 RETURN n
   $$) AS (res agtype);
 res
   
  
   
-
{"id": 1407374883553281, "label": "Person", "properties": {"name": "John 
Doe"}}::vertex
   (1 row)`
   
   If you intend to incorporate user input, you'll need to use one of the 
drivers available for AGE, such as the Python driver.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@age.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



[GitHub] [age] WendelLana commented on issue #981: Analyse MATCH clause performance (basic node finding)

2023-06-19 Thread via GitHub


WendelLana commented on issue #981:
URL: https://github.com/apache/age/issues/981#issuecomment-1597409977

   ### **Basic node finding**
   Logic: each vertex and edge will have a unique identifier using the UUID 
type of Postgres. UUIDs provide a stronger guarantee of uniqueness compared to 
sequence generators. This eliminates the need for a separate table to store IDs 
that have been deleted and simplifies the process of transferring data between 
graphs and databases.
   
   **Creating vertices and edges:**
   Postgres provides a function called gen_random_uuid(), which we can utilize 
to generate our unique identifiers. We will replace the existing logic with 
this method.
   
   Query:
   ```
   CREATE ()-[]->()
   ```
   
   Pseudo-code:
   ```
   UUID previous_vertex, next_vertex;
   FOR EACH node IN path
   IF node.type == VERTEX AND previous_vertex != next_vertex THEN
   previous_vertex = create_vertex() //generates UUID calling 
gen_random_uuid() and creates vertex
   ELSE IF node.type == EDGE
   next_vertex = create_vertex()
   create_edge(previous_vertex, next_vertex) //generates UUID and 
creates edge
   previous_vertex = next_vertex
   ENDIF
   NEXT node
   ```
   
   - The loop iterates `n` times
   - Inside the loop, the operations `create_vertex()` and `create_edge()` have 
a constant time complexity
   - Therefore, the overall time complexity of this pseudo code is O(n)
   
   **Get all nodes**
   ```
   MATCH (n)
   RETURN n
   ```
   This query will sequentially scan all vertices.
   
   **Get all nodes with a label**
   ```
   MATCH (movie:Movie)
   RETURN movie.title
   ```
   This query will use an index to efficiently scan vertices with the label 
"movie".
   
   **Related nodes**
   ```
   MATCH (director {name: 'Oliver Stone'})--(movie)
   RETURN movie.title
   ```
   This query will sequentially scan all vertices, looking for nodes with the 
property `name` equal to 'Oliver Stone'. It will then scan all edges to find 
matches where the `start_id` or `end_id` correspond to the previously found 
nodes. 
   
   **Match with labels**
   ```
   MATCH (:Person {name: 'Oliver Stone'})--(movie:Movie)
   RETURN movie.title
   ```
   This query will use the index for "Person" to efficiently find nodes with 
the name 'Oliver Stone'. Then, it will scan the edges to find connections 
between those nodes and other vertices. The query ensures that the connected 
vertices have the label "Movie" by utilizing an index for the "Movie" label.
   
   Note: I have prioritized filtering properties such as name when creating the 
query plan, but it is also possible to explore alternative search approaches.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@age.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: Offset and out of bounds

2023-06-19 Thread John Gemignani
You are looking at why it is called, right? In gdb you can use the *up *command
to look up the call stack to see what called something.

That function, btw, will get called by anything that needs to deserialize
agtype to agtype_value, even multiple times within a single agtype, due to
nested structures.

john



On Mon, Jun 12, 2023 at 12:08 PM Panagiotis Foliadis 
wrote:

> Yes of course.
>
> When we run the basic select * from cypher
> ('test', $$ create (u) return u) as (u agtype), fill_agtype_value() is
> being called multiple times.
> There are times when its called with the base_addr having the value
> "idlabelproperties" and the offset
> helps breaking down this string to fill correctly the json object that
> will be return to the client. But there
> are cases that when the fill_agtype_value() is called, for example when
> the node we are creating has
> no label, that the offset is 32, which is larger than the length of the
> base_addr. Running gdb with
> fill_agtype_value() as a breaking point would make it easier to understand
> what im trying to say.
>
> 
> Από: John Gemignani 
> Στάλθηκε: Δευτέρα, 12 Ιουνίου 2023 10:03 μμ
> Προς: dev@age.apache.org 
> Θέμα: Re: Offset and out of bounds
>
> Could you give some example cases?
>
> john
>
> On Mon, Jun 12, 2023 at 11:12 AM Panagiotis Foliadis <
> pfolia...@hotmail.com>
> wrote:
>
> > Hey all,
> >
> > I'm having a hard time understanding the offset​ functionality in
> > fill_agtype_value​().
> > There are many times when this function is called that the offset​ is
> > greater than the
> > length of the base_addr​ resulting in fetching a value from out of
> bounds.
> > How do the
> > out-of-bounds values get initialized and what are we trying to achieve by
> > having the offset
> > reach for the out-of-bounds values?
> >
>


Απ: Offset and out of bounds

2023-06-19 Thread Panagiotis Foliadis
Ive figured out everything that I needed thank you for your response!

Από: John Gemignani 
Στάλθηκε: Δευτέρα, 19 Ιουνίου 2023 9:25 μμ
Προς: dev@age.apache.org 
Θέμα: Re: Offset and out of bounds

You are looking at why it is called, right? In gdb you can use the *up *command
to look up the call stack to see what called something.

That function, btw, will get called by anything that needs to deserialize
agtype to agtype_value, even multiple times within a single agtype, due to
nested structures.

john



On Mon, Jun 12, 2023 at 12:08 PM Panagiotis Foliadis 
wrote:

> Yes of course.
>
> When we run the basic select * from cypher
> ('test', $$ create (u) return u) as (u agtype), fill_agtype_value() is
> being called multiple times.
> There are times when its called with the base_addr having the value
> "idlabelproperties" and the offset
> helps breaking down this string to fill correctly the json object that
> will be return to the client. But there
> are cases that when the fill_agtype_value() is called, for example when
> the node we are creating has
> no label, that the offset is 32, which is larger than the length of the
> base_addr. Running gdb with
> fill_agtype_value() as a breaking point would make it easier to understand
> what im trying to say.
>
> 
> Από: John Gemignani 
> Στάλθηκε: Δευτέρα, 12 Ιουνίου 2023 10:03 μμ
> Προς: dev@age.apache.org 
> Θέμα: Re: Offset and out of bounds
>
> Could you give some example cases?
>
> john
>
> On Mon, Jun 12, 2023 at 11:12 AM Panagiotis Foliadis <
> pfolia...@hotmail.com>
> wrote:
>
> > Hey all,
> >
> > I'm having a hard time understanding the offset​ functionality in
> > fill_agtype_value​().
> > There are many times when this function is called that the offset​ is
> > greater than the
> > length of the base_addr​ resulting in fetching a value from out of
> bounds.
> > How do the
> > out-of-bounds values get initialized and what are we trying to achieve by
> > having the offset
> > reach for the out-of-bounds values?
> >
>