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

added about_equal function for sqlalchemy #62

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions odata_query/grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"round": 1,
"floor": 1,
"ceiling": 1,
"aboutequal": 3,
# Geo functions
"geo.distance": 2,
"geo.length": 1,
Expand Down
8 changes: 8 additions & 0 deletions odata_query/sqlalchemy/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Any, Callable, Optional, Union

from sqlalchemy.sql import functions
from sqlalchemy import func
from sqlalchemy.sql.expression import (
BinaryExpression,
BindParameter,
Expand Down Expand Up @@ -301,6 +302,13 @@ def func_ceiling(self, field: ast._Node) -> functions.Function:
def func_floor(self, field: ast._Node) -> functions.Function:
":meta private:"
return functions_ext.floor(self.visit(field))

def func_aboutequal(self, field: ast._Node, value: ast._Node, tolerance: ast._Node) -> functions.Function:
":meta private:"
field = self.visit(field)
value = self.visit(value)
tolerance = self.visit(tolerance)
return operator.lt(func.abs(operator.sub(field, value)), tolerance)

def func_round(self, field: ast._Node) -> functions.Function:
":meta private:"
Expand Down
1 change: 1 addition & 0 deletions odata_query/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def infer_return_type(node: ast.Call) -> Optional[Type[ast._Node]]:
"ceiling",
"floor",
"round",
"aboutequal",
"geo.distance",
"geo.length",
):
Expand Down