You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by bl...@apache.org on 2022/01/19 23:21:58 UTC

[iceberg] branch master updated: Python: Fix quote handling in expression parser (#3875)

This is an automated email from the ASF dual-hosted git repository.

blue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iceberg.git


The following commit(s) were added to refs/heads/master by this push:
     new edbad92  Python: Fix quote handling in expression parser (#3875)
edbad92 is described below

commit edbad927f8125bf153f6b86f1f3344810100bf8a
Author: Pucheng Yang <80...@users.noreply.github.com>
AuthorDate: Wed Jan 19 15:21:44 2022 -0800

    Python: Fix quote handling in expression parser (#3875)
---
 python_legacy/iceberg/api/expressions/expression_parser.py |  3 ++-
 python_legacy/tests/api/expressions/test_str_to_expr.py    | 12 ++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/python_legacy/iceberg/api/expressions/expression_parser.py b/python_legacy/iceberg/api/expressions/expression_parser.py
index 0ffde4e..e231747 100644
--- a/python_legacy/iceberg/api/expressions/expression_parser.py
+++ b/python_legacy/iceberg/api/expressions/expression_parser.py
@@ -30,6 +30,7 @@ from pyparsing import (
     opAssoc,
     pyparsing_common as ppc,
     quotedString,
+    removeQuotes,
     Word
 )
 
@@ -50,7 +51,7 @@ intNum = ppc.signed_integer()
 
 columnRval = (realNum
               | intNum
-              | quotedString
+              | quotedString.setParseAction(removeQuotes)
               | columnName)  # need to add support for alg expressions
 whereCondition = Group(
     (columnName + binop + columnRval)
diff --git a/python_legacy/tests/api/expressions/test_str_to_expr.py b/python_legacy/tests/api/expressions/test_str_to_expr.py
index 34b3abd..d0ca8e6 100644
--- a/python_legacy/tests/api/expressions/test_str_to_expr.py
+++ b/python_legacy/tests/api/expressions/test_str_to_expr.py
@@ -22,6 +22,18 @@ def test_equal():
     assert expected_expr == conv_expr
 
 
+def test_str_equal_single_quotes():
+    expected_expr = Expressions.equal("col_a", "123")
+    conv_expr = Expressions.convert_string_to_expr("col_a='123'")
+    assert expected_expr == conv_expr
+
+
+def test_str_equal_double_quotes():
+    expected_expr = Expressions.equal("col_a", "123")
+    conv_expr = Expressions.convert_string_to_expr("col_a=\"123\"")
+    assert expected_expr == conv_expr
+
+
 def test_equal_alt_syntax():
     expected_expr = Expressions.equal("col_a", 1)
     conv_expr = Expressions.convert_string_to_expr("col_a==1")