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

Handle boolean in ecql like cql_text #108

Open
wants to merge 1 commit into
base: main
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
2 changes: 1 addition & 1 deletion pygeofilter/parsers/ecql/grammar.lark
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ period: DATETIME "/" DATETIME

envelope: "ENVELOPE" "(" number number number number ")"

BOOLEAN: ( "TRUE" | "FALSE" )
BOOLEAN.2: ( "TRUE"i | "FALSE"i )

DOUBLE_QUOTED: "\"" /.*?/ "\""
SINGLE_QUOTED: "'" /.*?/ "'"
Expand Down
2 changes: 1 addition & 1 deletion pygeofilter/parsers/ecql/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def FLOAT(self, value):
return float(value)

def BOOLEAN(self, value):
return value == "TRUE"
return value.lower() == "true"

def DOUBLE_QUOTED(self, token):
return token[1:-1]
Expand Down
34 changes: 34 additions & 0 deletions tests/parsers/ecql/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ def test_namespace_attribute_eq_literal():
"A",
)


def test_prefixed_attribute_eq_literal():
result = parse("properties.ns:attr = 'A'")
assert result == ast.Equal(
ast.Attribute("properties.ns:attr"),
"A",
)


def test_attribute_eq_literal():
result = parse("attr = 'A'")
assert result == ast.Equal(
Expand Down Expand Up @@ -595,3 +597,35 @@ def test_function_attr_string_arg():
],
),
)


def test_attribute_eq_true_uppercase():
result = parse("attr = TRUE")
assert result == ast.Equal(
ast.Attribute("attr"),
True,
)


def test_attribute_eq_true_lowercase():
result = parse("attr = true")
assert result == ast.Equal(
ast.Attribute("attr"),
True,
)


def test_attribute_eq_false_uppercase():
result = parse("attr = FALSE")
assert result == ast.Equal(
ast.Attribute("attr"),
False,
)


def test_attribute_eq_false_lowercase():
result = parse("attr = false")
assert result == ast.Equal(
ast.Attribute("attr"),
False,
)