Skip to content

Commit

Permalink
fix: Improve handling of 'not null' in the JSON format
Browse files Browse the repository at this point in the history
  • Loading branch information
robsavoye committed Sep 10, 2023
1 parent f44979b commit fb5964e
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions osm_rawdata/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,12 @@ def createJson(self,
join_or[tables[table]].append(key)
if item['op'] == 'and':
join_and[tables[table]].append(key)
filters['tags'][tables[table]]['join_or'][key] = item[key]
filters['tags'][tables[table]]['join_and'][key] = item[key]
if item[key][0] == 'not null':
filters['tags'][tables[table]]['join_or'][key] = []
filters['tags'][tables[table]]['join_and'][key] = []
else:
filters['tags'][tables[table]]['join_or'][key] = item[key]
filters['tags'][tables[table]]['join_and'][key] = item[key]
feature.update({"filters": filters})

attributes = list()
Expand Down Expand Up @@ -288,7 +292,10 @@ def createSQL(self,
if k == 'op':
continue
if len(v) == 1:
v1 = f"=\'{v[0]}\'"
if v[0] == 'not null':
v1 = f"IS NOT NULL"
else:
v1 = f"=\'{v[0]}\'"
elif len(v) > 0:
v1 = f" IN {str(tuple(v))}"
else:
Expand All @@ -302,7 +309,10 @@ def createSQL(self,
if k == 'op':
continue
if len(v) == 1:
v1 = f"=\'{v[0]}\'"
if v[0] == 'not null':
v1 = f"IS NOT NULL"
else:
v1 = f"=\'{v[0]}\'"
elif len(v) > 0:
v1 = f" IN {str(tuple(v))}"
else:
Expand Down Expand Up @@ -385,7 +395,8 @@ def queryLocal(self,
# This should be the version
tags[res[3][:-1]] = item[2]
features.append(Feature(geometry=geom, properties=tags))
return FeatureCollection(features)
# return FeatureCollection(features)
return features


def queryRemote(self,
Expand All @@ -396,7 +407,8 @@ def queryRemote(self,
backend to the HOT Export Tool.
Args:
query (str): The SQL query to execute
query (str): The JSON query to execute
Returns:
(FeatureCollection): the results of the query
"""
Expand Down Expand Up @@ -501,7 +513,7 @@ def execQuery(self,
log.info("Extracting features from Postgres...")

if 'features' in boundary:
# FIXME: ideally this shyould support multipolygons
# FIXME: ideally this should support multipolygons
poly = boundary['features'][0]['geometry']
else:
poly = boundary["geometry"]
Expand All @@ -514,13 +526,13 @@ def execQuery(self,
else:
sql = [customsql]
for query in sql:
print(query)
result = self.queryLocal(query, allgeom, wkt)
if len(result) > 0:
alldata.append(result)
collection = FeatureCollection(alldata)
else:
request = self.createJson(self.qc, poly, allgeom)
# print(f"FIXME: {request}")
collection = self.queryRemote(request)
return collection

Expand Down

0 comments on commit fb5964e

Please sign in to comment.