AISViz / AISdb

AISdb Python package for smart AIS data storage and interaction.
https://aisviz.cs.dal.ca
GNU Affero General Public License v3.0
9 stars 0 forks source link

Query Results Suggestion #5

Closed gabrielspadon closed 8 months ago

gabrielspadon commented 10 months ago

I have a suggestion to improve the behavior of AISdb when a query returns no results. Currently, AISdb does not return an empty set like an RDBMS would; instead, it requires users to add an extra try-catch to handle the situation on their side. To make things more straightforward and intuitive, I propose that AISdb should return an empty set when there are no results. This way, users would not have to write additional code to handle this scenario, and the behavior would be consistent with industry standards.

Traceback (most recent call last):

  File "/usr/local/lib/python3.9/dist-packages/IPython/core/interactiveshell.py", line 3553, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)

  File "<ipython-input-55-4ae9a9be14b0>", line 1, in <cell line: 1>
    for all_tracks in get_tracks(hours2batch=168):

  File "<ipython-input-54-7b2bb655fd9e>", line 36, in get_tracks
    yield list(tracks)

  File "/usr/local/lib/python3.9/dist-packages/aisdb/interp.py", line 29, in interp_time
    for track in tracks:

  File "/usr/local/lib/python3.9/dist-packages/aisdb/track_gen.py", line 361, in encode_greatcircledistance
    for track in tracks:

  File "/usr/local/lib/python3.9/dist-packages/aisdb/track_gen.py", line 154, in split_timedelta
    for track in tracks:

  File "/usr/local/lib/python3.9/dist-packages/aisdb/track_gen.py", line 129, in TrackGen
    for rows in rowgen:

  File "/usr/local/lib/python3.9/dist-packages/aisdb/database/dbqry.py", line 258, in gen_qry
    raise SyntaxError(f'no results for query!\n{qry}')

  File "<string>", line unknown
SyntaxError: no results for query!
  SELECT 
    d.mmsi, 
    d.time, 
    d.longitude,
    d.latitude,
    d.sog,
    d.cog
  FROM esrf_hydrophone_01.ais_201508_dynamic AS d
  WHERE
d.time >= 1438387200 AND
    d.time <= 1438992000
ORDER BY 1,2