Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Excution ERR['int' object does not support indexing] #10

Open
afidegnum opened this issue Dec 2, 2021 · 5 comments
Open

Excution ERR['int' object does not support indexing] #10

afidegnum opened this issue Dec 2, 2021 · 5 comments

Comments

@afidegnum
Copy link
Contributor

afidegnum commented Dec 2, 2021

I'm trying to run a recursive query that will enable me to process the nodes which can be used for additional operations, and came across the error above:
when I tested individual queries, they works perfectly

def graph_nodes(tag_id):
    top = ag.execCypher("MATCH (n:node) WHERE id(n) = %s RETURN n", params=(tag_id,))
    x = [r[0] for r in top]
    print(x[0]["tag"])
    children = ag.execCypher("MATCH (v:node)-[R:connect]-(V2) WHERE id(v) = %s RETURN V2", params=(x[0]).id,)
    for c in children:
        print(c)
        graph_nodes(c[0].id)

cursor = ag.execCypher("MATCH (n:node {tag: 'html'}) RETURN n")    
t = [x[0].id for x in cursor]
print(t[0])
graph_nodes(t[0])
TypeError                                 Traceback (most recent call last)
~/.virtualenvs/orgs/lib/python3.9/site-packages/age/age.py in execCypher(conn, graphName, cypherStmt, cols, params)
    106     try:
--> 107         cursor.execute(stmt, params)
    108         return cursor

TypeError: 'int' object does not support indexing

During handling of the above exception, another exception occurred:

SqlExcutionError                          Traceback (most recent call last)
/tmp/ipykernel_117955/2082054997.py in <module>
     11 t = [x[0].id for x in cursor]
     12 print(t[0])
---> 13 graph_nodes(t[0])

/tmp/ipykernel_117955/2082054997.py in graph_nodes(tags)
      3     x = [r[0] for r in top]
      4     print(x[0]["tag"])
----> 5     children = ag.execCypher("MATCH (v:node)-[R:connect]-(V2) WHERE id(v) = %s RETURN V2", params=(x[0].id,)
      6     for c in children:
      7         print(c)

~/.virtualenvs/orgs/lib/python3.9/site-packages/age/age.py in execCypher(self, cypherStmt, cols, params)
    156 
    157     def execCypher(self, cypherStmt:str, cols:list=None, params:tuple=None) -> ext.cursor :
--> 158         return execCypher(self.connection, self.graphName, cypherStmt, cols=cols, params=params)
    159 
    160     def cypher(self, cursor:ext.cursor, cypherStmt:str, cols:list=None, params:tuple=None) -> ext.cursor :

~/.virtualenvs/orgs/lib/python3.9/site-packages/age/age.py in execCypher(conn, graphName, cypherStmt, cols, params)
    112     except Exception as cause:
    113         conn.rollback()
--> 114         raise SqlExcutionError("Excution ERR[" + str(cause) +"](" + stmt +")", cause)
    115 
    116 

SqlExcutionError: ("Excution ERR['int' object does not support indexing](SELECT * from cypher('text_test', $$ MATCH (v:node)-[R:connect]-(V2) WHERE id(v) = %s RETURN V2 $$) as (v agtype);)", TypeError("'int' object does not support indexing"))

@rhizome-ai
Copy link
Owner

Tracing log says "TypeError: 'int' object does not support indexing"
And, the code line where error occurs is

children = ag.execCypher("MATCH (v:node)-[R:connect]-(V2) WHERE id(v) = %s RETURN V2", params=(x[0].id,)

So, I think variable 'x' is int value, and 'x[0]' is not supported.
Please check the variable 'x'.

@afidegnum
Copy link
Contributor Author

@rhizome-ai I posted a question about traversing recursively a graph, can you please have a look? https://stackoverflow.com/q/70213240/5713751

@afidegnum afidegnum reopened this Dec 3, 2021
@rhizome-ai
Copy link
Owner

I think you should call graph_dom(did) recursively in the children loop .

cursor = ag.execCypher("MATCH (n:node {tag: 'html'}) RETURN n")    
t = [x[0].id for x in cursor]
print(t[0])

def graph_dom(t_id):
    parent = ag.execCypher("MATCH (n:node) WHERE id(n) = %s RETURN n", params=(t_id,))
    p = [x[0] for x in parent]
    pt = p[0]["tag"]       
    pid = p[0].id
    print(f"|> parent Id: {pid} --- parent tag {pt}")
    parent_tag = soup.new_tag(name=p[0]["tag"])
    soup.append(parent_tag)
    children = ag.execCypher("MATCH (v:node)-[R:connect]->(V2) WHERE id(v) = %s RETURN V2", params=(p[0].id,))
    for d in children:
        children_tag = soup.new_tag(name=d[0]["tag"])
        parent_tag.append(children_tag)
        dt = d[0]["tag"]
        did = d[0].id
        print(f"child id {did} child tag: {dt}")        
        graph_dom(did)   # Call graph_dom recursively.   
        
graph_dom(t[0])

file_soup = soup.prettify()
with open("helloworld.html", "w") as file:
    file.write(str(file_soup))

@afidegnum
Copy link
Contributor Author

I tried that approach and it didn't work. here is my notebook

@rhizome-ai
Copy link
Owner

Fix Agtype parser #13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants