@@ -74,43 +74,45 @@ def test_simple_literal(value, expected_pattern):
74
74
75
75
76
76
@pytest .mark .parametrize (
77
- ("value" , "expected " ),
77
+ ("value" , "expected_pattern " ),
78
78
(
79
79
# Try to have some list of literals for each scalar data type:
80
80
# https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types
81
- ([None , None ], "[NULL, NULL]" ),
82
- ([True , False ], "[True, False]" ),
81
+ ([None , None ], re . escape ( "[NULL, NULL]" ) ),
82
+ ([True , False ], re . escape ( "[True, False]" ) ),
83
83
(
84
84
[b"\x01 \x02 \x03 ABC" , b"\x01 \x02 \x03 ABC" ],
85
- "[b'\\ x01\\ x02\\ x03ABC', b'\\ x01\\ x02\\ x03ABC']" ,
85
+ re . escape ( "[b'\\ x01\\ x02\\ x03ABC', b'\\ x01\\ x02\\ x03ABC']" ) ,
86
86
),
87
87
(
88
88
[datetime .date (2025 , 1 , 1 ), datetime .date (2025 , 1 , 1 )],
89
- "[DATE('2025-01-01'), DATE('2025-01-01')]" ,
89
+ re . escape ( "[DATE('2025-01-01'), DATE('2025-01-01')]" ) ,
90
90
),
91
91
(
92
92
[datetime .datetime (2025 , 1 , 2 , 3 , 45 , 6 , 789123 )],
93
- "[DATETIME('2025-01-02T03:45:06.789123')]" ,
93
+ re . escape ( "[DATETIME('2025-01-02T03:45:06.789123')]" ) ,
94
94
),
95
95
(
96
- [shapely .Point (0 , 1 ), shapely .Point (0 , 2 )],
97
- " [ST_GEOGFROMTEXT('POINT (0 1)' ), ST_GEOGFROMTEXT('POINT (0 2)') ]" ,
96
+ [shapely .geometry . Point (0 , 1 ), shapely . geometry .Point (0 , 2 )],
97
+ r"\ [ST_GEOGFROMTEXT\ ('POINT \(0[.]?0* 1[.]?0*\)'\ ), ST_GEOGFROMTEXT\ ('POINT \(0[.]?0* 2[.]?0*\)'\)\ ]" ,
98
98
),
99
99
# TODO: INTERVAL type (e.g. from dateutil.relativedelta)
100
100
# TODO: JSON type (TBD what Python object that would correspond to)
101
- ([123 , 456 ], "[123, 456]" ),
101
+ ([123 , 456 ], re . escape ( "[123, 456]" ) ),
102
102
(
103
103
[decimal .Decimal ("123.75" ), decimal .Decimal ("456.78" )],
104
- "[CAST('123.75' AS NUMERIC), CAST('456.78' AS NUMERIC)]" ,
104
+ re . escape ( "[CAST('123.75' AS NUMERIC), CAST('456.78' AS NUMERIC)]" ) ,
105
105
),
106
106
# TODO: support BIGNUMERIC by looking at precision/scale of the DECIMAL
107
- ([123.75 , 456.78 ], "[123.75, 456.78]" ),
107
+ ([123.75 , 456.78 ], re . escape ( "[123.75, 456.78]" ) ),
108
108
# TODO: support RANGE type
109
- (["abc" , "def" ], "['abc', 'def']" ),
109
+ (["abc" , "def" ], re . escape ( "['abc', 'def']" ) ),
110
110
# TODO: support STRUCT type (possibly another method?)
111
111
(
112
112
[datetime .time (12 , 34 , 56 , 789123 ), datetime .time (11 , 25 , 56 , 789123 )],
113
- "[TIME(DATETIME('1970-01-01 12:34:56.789123')), TIME(DATETIME('1970-01-01 11:25:56.789123'))]" ,
113
+ re .escape (
114
+ "[TIME(DATETIME('1970-01-01 12:34:56.789123')), TIME(DATETIME('1970-01-01 11:25:56.789123'))]"
115
+ ),
114
116
),
115
117
(
116
118
[
@@ -121,13 +123,15 @@ def test_simple_literal(value, expected_pattern):
121
123
2025 , 2 , 1 , 4 , 45 , 6 , 789123 , tzinfo = datetime .timezone .utc
122
124
),
123
125
],
124
- "[TIMESTAMP('2025-01-02T03:45:06.789123+00:00'), TIMESTAMP('2025-02-01T04:45:06.789123+00:00')]" ,
126
+ re .escape (
127
+ "[TIMESTAMP('2025-01-02T03:45:06.789123+00:00'), TIMESTAMP('2025-02-01T04:45:06.789123+00:00')]"
128
+ ),
125
129
),
126
130
),
127
131
)
128
- def test_simple_literal_w_list (value : list , expected : str ):
132
+ def test_simple_literal_w_list (value : list , expected_pattern : str ):
129
133
got = sql .simple_literal (value )
130
- assert got == expected
134
+ assert re . match ( expected_pattern , got ) is not None
131
135
132
136
133
137
def test_create_vector_search_sql_simple ():
0 commit comments