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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support of float32 type #1113

Merged
merged 8 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Next Next commit
incorporate changes
  • Loading branch information
rahul2393 committed Mar 12, 2024
commit bff3ec299d26205081bc93ef2d9a69514242a09c
1 change: 1 addition & 0 deletions google/cloud/spanner_v1/streamed.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ def _merge_struct(lhs, rhs, type_):
TypeCode.BYTES: _merge_string,
TypeCode.DATE: _merge_string,
TypeCode.FLOAT64: _merge_float64,
TypeCode.FLOAT32: _merge_float64,
TypeCode.INT64: _merge_string,
TypeCode.STRING: _merge_string,
TypeCode.STRUCT: _merge_struct,
Expand Down
3 changes: 3 additions & 0 deletions tests/system/_sample_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,8 @@ def _check_cell_data(found_cell, expected_cell, recurse_into_lists=True):
for found_item, expected_item in zip(found_cell, expected_cell):
_check_cell_data(found_item, expected_item)

elif isinstance(found_cell, float):
assert abs(found_cell - expected_cell) < 0.00001
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


else:
assert found_cell == expected_cell
41 changes: 41 additions & 0 deletions tests/system/test_session_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2216,6 +2216,47 @@ def test_execute_sql_w_float_bindings_transfinite(sessions_database, database_di
)


def test_execute_sql_w_float32_bindings(sessions_database, database_dialect):
pytest.skip(f"float32 is not yet supported in production.")
_bind_test_helper(
sessions_database,
database_dialect,
spanner_v1.param_types.FLOAT32,
42.3,
[12.3, 456.0, 7.89],
)


def test_execute_sql_w_float32_bindings_transfinite(
sessions_database, database_dialect
):
pytest.skip(f"float32 is not yet supported in production.")
key = "p1" if database_dialect == DatabaseDialect.POSTGRESQL else "neg_inf"
placeholder = "$1" if database_dialect == DatabaseDialect.POSTGRESQL else f"@{key}"

# Find -inf
_check_sql_results(
sessions_database,
sql=f"SELECT {placeholder}",
params={key: NEG_INF},
param_types={key: spanner_v1.param_types.FLOAT64},
olavloite marked this conversation as resolved.
Show resolved Hide resolved
expected=[(NEG_INF,)],
order=False,
)

key = "p1" if database_dialect == DatabaseDialect.POSTGRESQL else "pos_inf"
placeholder = "$1" if database_dialect == DatabaseDialect.POSTGRESQL else f"@{key}"
# Find +inf
_check_sql_results(
sessions_database,
sql=f"SELECT {placeholder}",
params={key: POS_INF},
param_types={key: spanner_v1.param_types.FLOAT64},
olavloite marked this conversation as resolved.
Show resolved Hide resolved
expected=[(POS_INF,)],
order=False,
)


def test_execute_sql_w_bytes_bindings(sessions_database, database_dialect):
_bind_test_helper(
sessions_database,
Expand Down