junyang / radb

RA (radb): A relational algebra interpreter over relational databases
http://www.cs.duke.edu/~junyang/radb
Other
62 stars 14 forks source link

AttributeError: module 'radb' has no attribute 'ast' #4

Closed Ala-Jeb closed 3 years ago

Ala-Jeb commented 3 years ago

I have the following code:

import radb.parse dd = {} dd["Person"] = {"name": "string", "age": "integer", "gender": "string"} dd["Eats"] = {"name": "string", "pizza": "string"} stmt = """\project_{Person.name, Eats.pizza} \select_{Person.name = Eats.name}(Person \cross Eats);""" ra = radb.parse.one_statement_from_string(stmt) print(ra)

It shows me the following error Traceback (most recent call last): File "test.py", line 9, in ra = one_statement_from_string(stmt) File "/home/alajeb/.local/lib/python3.6/site-packages/radb/parse.py", line 262, in one_statement_from_string ast = ASTBuilder().visit(tree) File "/home/alajeb/.local/lib/python3.6/site-packages/antlr4/tree/Tree.py", line 34, in visit return tree.accept(self) File "/home/alajeb/.local/lib/python3.6/site-packages/radb/RAParser.py", line 1745, in accept return visitor.visitStatement(self) File "/home/alajeb/.local/lib/python3.6/site-packages/radb/parse.py", line 247, in visitStatement return self.visit(ctx.getChild(0)) File "/home/alajeb/.local/lib/python3.6/site-packages/antlr4/tree/Tree.py", line 34, in visit return tree.accept(self) File "/home/alajeb/.local/lib/python3.6/site-packages/radb/RAParser.py", line 972, in accept return visitor.visitProjectExpr(self) File "/home/alajeb/.local/lib/python3.6/site-packages/radb/parse.py", line 175, in visitProjectExpr return radb.ast.Project(self.visit(ctx.listOfValExprs()), self.visit(ctx.relExpr())) AttributeError: module 'radb' has no attribute 'ast'

junyang commented 3 years ago

radb isn't yet designed to be use as a library, but to get around the particular problem that you are facing, you can try:

from radb import parse, ast
stmt = """\project_{Person.name, Eats.pizza} \select_{Person.name = Eats.name}(Person \cross Eats);"""
ra = parse.one_statement_from_string(stmt)
print(ra)

--- Jun Y.