|
19 | 19 | import struct |
20 | 20 | import threading |
21 | 21 | import time |
22 | | - |
| 22 | +import json |
23 | 23 | import pytest |
24 | 24 |
|
25 | 25 | import grpc |
|
43 | 43 | BYTES_2 = b"Ym9vdHM=" |
44 | 44 | NUMERIC_1 = decimal.Decimal("0.123456789") |
45 | 45 | NUMERIC_2 = decimal.Decimal("1234567890") |
| 46 | +JSON_1 = json.dumps( |
| 47 | + { |
| 48 | + "sample_boolean": True, |
| 49 | + "sample_int": 872163, |
| 50 | + "sample float": 7871.298, |
| 51 | + "sample_null": None, |
| 52 | + "sample_string": "abcdef", |
| 53 | + "sample_array": [23, 76, 19], |
| 54 | + }, |
| 55 | + sort_keys=True, |
| 56 | + separators=(",", ":"), |
| 57 | +) |
| 58 | +JSON_2 = json.dumps( |
| 59 | + {"sample_object": {"name": "Anamika", "id": 2635}}, |
| 60 | + sort_keys=True, |
| 61 | + separators=(",", ":"), |
| 62 | +) |
| 63 | + |
46 | 64 | COUNTERS_TABLE = "counters" |
47 | 65 | COUNTERS_COLUMNS = ("name", "value") |
48 | 66 | ALL_TYPES_TABLE = "all_types" |
|
64 | 82 | "timestamp_array", |
65 | 83 | "numeric_value", |
66 | 84 | "numeric_array", |
| 85 | + "json_value", |
| 86 | + "json_array", |
67 | 87 | ) |
68 | | -EMULATOR_ALL_TYPES_COLUMNS = LIVE_ALL_TYPES_COLUMNS[:-2] |
| 88 | +EMULATOR_ALL_TYPES_COLUMNS = LIVE_ALL_TYPES_COLUMNS[:-4] |
69 | 89 | AllTypesRowData = collections.namedtuple("AllTypesRowData", LIVE_ALL_TYPES_COLUMNS) |
70 | 90 | AllTypesRowData.__new__.__defaults__ = tuple([None for colum in LIVE_ALL_TYPES_COLUMNS]) |
71 | 91 | EmulatorAllTypesRowData = collections.namedtuple( |
|
88 | 108 | AllTypesRowData(pkey=107, timestamp_value=SOME_TIME), |
89 | 109 | AllTypesRowData(pkey=108, timestamp_value=NANO_TIME), |
90 | 110 | AllTypesRowData(pkey=109, numeric_value=NUMERIC_1), |
| 111 | + AllTypesRowData(pkey=110, json_value=JSON_1), |
91 | 112 | # empty array values |
92 | 113 | AllTypesRowData(pkey=201, int_array=[]), |
93 | 114 | AllTypesRowData(pkey=202, bool_array=[]), |
|
97 | 118 | AllTypesRowData(pkey=206, string_array=[]), |
98 | 119 | AllTypesRowData(pkey=207, timestamp_array=[]), |
99 | 120 | AllTypesRowData(pkey=208, numeric_array=[]), |
| 121 | + AllTypesRowData(pkey=209, json_array=[]), |
100 | 122 | # non-empty array values, including nulls |
101 | 123 | AllTypesRowData(pkey=301, int_array=[123, 456, None]), |
102 | 124 | AllTypesRowData(pkey=302, bool_array=[True, False, None]), |
|
106 | 128 | AllTypesRowData(pkey=306, string_array=["One", "Two", None]), |
107 | 129 | AllTypesRowData(pkey=307, timestamp_array=[SOME_TIME, NANO_TIME, None]), |
108 | 130 | AllTypesRowData(pkey=308, numeric_array=[NUMERIC_1, NUMERIC_2, None]), |
| 131 | + AllTypesRowData(pkey=309, json_array=[JSON_1, JSON_2, None]), |
109 | 132 | ) |
110 | 133 | EMULATOR_ALL_TYPES_ROWDATA = ( |
111 | 134 | # all nulls |
@@ -1867,6 +1890,12 @@ def test_execute_sql_w_numeric_bindings(not_emulator, sessions_database): |
1867 | 1890 | ) |
1868 | 1891 |
|
1869 | 1892 |
|
| 1893 | +def test_execute_sql_w_json_bindings(not_emulator, sessions_database): |
| 1894 | + _bind_test_helper( |
| 1895 | + sessions_database, spanner_v1.TypeCode.JSON, JSON_1, [JSON_1, JSON_2], |
| 1896 | + ) |
| 1897 | + |
| 1898 | + |
1870 | 1899 | def test_execute_sql_w_query_param_struct(sessions_database): |
1871 | 1900 | name = "Phred" |
1872 | 1901 | count = 123 |
|
0 commit comments