Repository: googleapis/python-spanner

Issue:
float value cannot be used to insert data to NUMERIC field.
Float data type is mapped to float: spanner.param_types.FLOAT64 [Link](https://github.com/googleapis/python-spanner/blob/master/google/cloud/spanner_dbapi/parse_utils.py#L35).

We need to add support to map decimal.Decimal type in python to Numeric type in spanner.

#### Environment details

  - OS type and version: MacOS Big Sur 11.2.3
  - Python version: 3.8.8
  - pip version: pip 21.0.1
  - `google-cloud-spanner` version: 3.2.0

#### Steps to reproduce

  1. Create a table with Numeric field.
  2. Insert data in field with type float

#### Code example

```python
sql='INSERT INTO t (x) VALUES (%s)', 
params=[3.194387483193242e+19]
```

Thanks!


Discussion:
vi3k6i5: github actions are not running, causing this PL and will retry.

Patch:
diff --git a/google/cloud/spanner_dbapi/parse_utils.py b/google/cloud/spanner_dbapi/parse_utils.py
index 0a7d505..1744874 100644
--- a/google/cloud/spanner_dbapi/parse_utils.py
+++ b/google/cloud/spanner_dbapi/parse_utils.py
@@ -509,25 +509,11 @@ def sql_pyformat_args_to_spanner(sql, params):
             resolved_value = pyfmt % params
             named_args[key] = resolved_value
         else:
-            named_args[key] = cast_for_spanner(params[i])
+            named_args[key] = params[i]
 
     return sanitize_literals_for_upload(sql), named_args
 
 
-def cast_for_spanner(value):
-    """Convert the param to its Cloud Spanner equivalent type.
-
-    :type value: Any
-    :param value: The value to convert to a Cloud Spanner type.
-
-    :rtype: Any
-    :returns: The value converted to a Cloud Spanner type.
-    """
-    if isinstance(value, decimal.Decimal):
-        return str(value)
-    return value
-
-
 def get_param_types(params):
     """Determine Cloud Spanner types for the given parameters.
 


Test patch:
diff --git a/tests/unit/spanner_dbapi/test_parse_utils.py b/tests/unit/spanner_dbapi/test_parse_utils.py
index c612659..73277a7 100644
--- a/tests/unit/spanner_dbapi/test_parse_utils.py
+++ b/tests/unit/spanner_dbapi/test_parse_utils.py
@@ -307,7 +307,7 @@ class TestParseUtils(unittest.TestCase):
                 ),
                 (
                     "SELECT (an.p + @a0) AS np FROM an WHERE (an.p + @a1) = @a2",
-                    {"a0": 1, "a1": 1.0, "a2": str(31)},
+                    {"a0": 1, "a1": 1.0, "a2": decimal.Decimal("31")},
                 ),
             ),
         ]
@@ -339,17 +339,6 @@ class TestParseUtils(unittest.TestCase):
                     lambda: sql_pyformat_args_to_spanner(sql, params),
                 )
 
-    def test_cast_for_spanner(self):
-        import decimal
-
-        from google.cloud.spanner_dbapi.parse_utils import cast_for_spanner
-
-        dec = 3
-        value = decimal.Decimal(dec)
-        self.assertEqual(cast_for_spanner(value), str(dec))
-        self.assertEqual(cast_for_spanner(5), 5)
-        self.assertEqual(cast_for_spanner("string"), "string")
-
     @unittest.skipIf(skip_condition, skip_message)
     def test_get_param_types(self):
         import datetime