@@ -131,7 +131,7 @@ def compare_sql_keyed_rows(
131
131
132
132
comps : dict [str , pd .DataFrame ] = {}
133
133
134
- def query (column ) :
134
+ def query (column : str ) -> str :
135
135
lc = f'"left"."{ column } "'
136
136
rc = f'"right"."{ column } "'
137
137
return f"""
@@ -143,10 +143,41 @@ def query(column):
143
143
WHERE { lc } IS DISTINCT FROM { rc }
144
144
"""
145
145
146
+ def spatial_query (column : str ) -> str :
147
+ lc = f'"left"."{ column } "'
148
+ rc = f'"right"."{ column } "'
149
+ return f"""
150
+ SELECT
151
+ { left_keys } ,
152
+ st_orderingequals({ lc } , { rc } ) AS "ordering_equal",
153
+ st_equals({ lc } , { rc } ) AS "spatially_equal"
154
+ FROM { left } AS "left"
155
+ INNER JOIN { right } AS "right"
156
+ ON { on }
157
+ WHERE { lc } IS DISTINCT FROM { rc }
158
+ """
159
+
160
+ left_geom_columns = client .get_geometry_columns (left )
161
+ right_geom_columns = client .get_geometry_columns (right )
162
+
146
163
for column in non_key_columns :
147
- comp_df = client .execute_select_query (query (column ))
148
- comp_df = comp_df .set_index (key_columns )
149
- comp_df .columns = pd .Index (["left" , "right" ])
164
+ # simple inequality is not informative for spatial columns
165
+ if (column in left_geom_columns ) and (column in right_geom_columns ):
166
+ comp_df = client .execute_select_query (spatial_query (column ))
167
+ comp_df = comp_df .set_index (key_columns )
168
+ comp_df .columns = pd .Index (["ordering_equal" , "spatially_equal" ])
169
+
170
+ elif (column not in left_geom_columns ) and (column not in right_geom_columns ):
171
+ comp_df = client .execute_select_query (query (column ))
172
+ comp_df = comp_df .set_index (key_columns )
173
+ comp_df .columns = pd .Index (["left" , "right" ])
174
+
175
+ # No point comparing geom and non-geom.
176
+ # This should be caught in `column_comparison` of report
177
+ # Other non-equivalent types are allowed - text vs varchar can produce valid comps
178
+ else :
179
+ continue
180
+
150
181
if len (comp_df ) > 0 :
151
182
comps [column ] = comp_df .copy ()
152
183
0 commit comments