Skip to content

Commit

Permalink
[Driver] Fix V3IO driver handling of single quote in strings where do…
Browse files Browse the repository at this point in the history
…uble quote is not present (#498)
  • Loading branch information
tomerm-iguazio authored Jan 28, 2024
1 parent b85265c commit b369026
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
32 changes: 32 additions & 0 deletions integration/test_flow_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
V3ioDriver,
build_flow,
)
from storey.dtypes import V3ioError
from storey.flow import DropColumns

from .conftest import ContextForTests
Expand Down Expand Up @@ -1107,6 +1108,37 @@ def test_writing_int_key(setup_teardown_test):
controller.await_termination()


@pytest.mark.parametrize(
"color, v3io_failed", [(["gre'en", 'bl"ue', "red"], False), (["gr\"e'en", "bl\"u'e", "red"], True)]
)
def test_writing_quote_in_value(setup_teardown_test, color, v3io_failed):
keys = ["num"]
table = _get_table(setup_teardown_test, {"num": int, "color": str}, keys)

df = pd.DataFrame({"num": [0, 1, 2], "color": color})
records = df.to_dict(orient="records")
if isinstance(table._storage, V3ioDriver) and v3io_failed:
with pytest.raises(V3ioError):
controller = build_flow(
[
DataframeSource(df, key_field="num"),
NoSqlTarget(table),
]
).run()
controller.await_termination()
else:
controller = build_flow(
[
DataframeSource(df, key_field="num"),
NoSqlTarget(table),
]
).run()
controller.await_termination()
assert get_key_all_attrs_test_helper(setup_teardown_test, "0", keys) == records[0]
assert get_key_all_attrs_test_helper(setup_teardown_test, "1", keys) == records[1]
assert get_key_all_attrs_test_helper(setup_teardown_test, "2", keys) == records[2]


def test_writing_timedelta_key(setup_teardown_test):
if setup_teardown_test.driver_name == "SQLDriver":
pytest.skip("test_writing_timedelta_key not testing over SQLDriver because SQLITE not support interval type")
Expand Down
4 changes: 4 additions & 0 deletions storey/drivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,10 @@ def _build_simplified_feature_store_request(self, aggregation_element):
@staticmethod
def _convert_python_obj_to_expression_value(value):
if isinstance(value, str):
# in order to handle ' or " in a value.
# using both double (") and single (') quotation marks in the same value is not supported.
if "'" in value:
return f'"{value}"'
return f"'{value}'"
if isinstance(value, bool) or isinstance(value, float) or isinstance(value, int):
return str(value)
Expand Down

0 comments on commit b369026

Please sign in to comment.