gorilla-co / odata-query

An OData v4 query parser and transpiler for Python
MIT License
71 stars 17 forks source link

Base AST visitor for SQL throws type warning, if sql function argument has the field name #55

Closed oi-raanne closed 1 month ago

oi-raanne commented 1 month ago

Base AST visitor for SQL throws warning 'Failed to infer type for Identifier(name='CompanyName', namespace=())' for endswith(CompanyName,'Futterkiste'). This is harmless warning, but needs to be fixed as this is a valid expression as per OData spec

oi-raanne commented 1 month ago

Test code: ` my_odata_query2 = "endswith(CompanyName,'Futterkiste')".strip()

lexer = ODataLexer()

parser = ODataParser()

ast = parser.parse(lexer.tokenize(my_odata_query2))

bqVisitor = AstToSqlVisitor()

print("***")

print(f"SQL query: {bqVisitor.visit(ast)}") `

Output

Failed to infer type for Identifier(name='CompanyName', namespace=()) SQL query: "CompanyName" LIKE '%Futterkiste'

OliverHofkens commented 1 month ago

Fair point. I've turned it into a debug log for now, so it's easier to turn off but users can at least know the cause of type-related failures.

The reason we need type inference is to know which functions we'd need to call, e.g. endswith(x, y) is valid for both string and list types and we need to pick the correct implementation based on the types of the arguments. odata-query cannot infer this type for every Node. The main failure case is for Identifier nodes, for which we'd have to know the entire schema of the database up front.