Repository: mabel-dev/opteryx

Issue:
🪲 Empty partitions raise a invalid Tuple error
### Thank you for taking the time to report a problem with Opteryx.
_To help us to respond to your request we ask that you try to provide the below detail about the bug._

**Describe the bug** _A clear and specific description of what the bug is. What the error, incorrect or unexpected behaviour was._


**Expected behaviour** _A clear and concise description of what you expected to happen._


**Sample Code/Statement** _If you can, please submit the SQL statement or Python code snippet, or a representative example using the sample datasets._

~~~sql

~~~

**Additional context** _Add any other context about the problem here, for example what you have done to try to diagnose or workaround the problem._



Discussion:

Resolving patch:
diff --git a/opteryx/__version__.py b/opteryx/__version__.py
--- a/opteryx/__version__.py
+++ b/opteryx/__version__.py
@@ -1,4 +1,4 @@
-__build__ = 313
+__build__ = 314
 
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
diff --git a/opteryx/exceptions.py b/opteryx/exceptions.py
--- a/opteryx/exceptions.py
+++ b/opteryx/exceptions.py
@@ -353,7 +353,9 @@ class EmptyDatasetError(DataError):
 
     def __init__(self, dataset: str):
         self.dataset = dataset
-        message = f"The requested dataset, '{dataset}', appears to exist but no matching partitions were found."
+        message = (
+            f"The requested dataset, '{dataset}', was found, but there was no valid partition."
+        )
         super().__init__(message)
 
 
diff --git a/opteryx/managers/schemes/mabel_partitions.py b/opteryx/managers/schemes/mabel_partitions.py
--- a/opteryx/managers/schemes/mabel_partitions.py
+++ b/opteryx/managers/schemes/mabel_partitions.py
@@ -43,14 +43,16 @@ def is_complete_and_not_invalid(blobs, as_at):
     complete_suffix = f"{as_at}{OS_SEP}frame.complete"
     invalid_suffix = f"{as_at}{OS_SEP}frame.ignore"
 
-    complete, ignore = zip(
-        *(
-            (complete_suffix in blob, invalid_suffix in blob)
-            for blob in blobs
-            if f"{OS_SEP}frame." in blob
-        )
+    frame_blobs = (
+        (complete_suffix in blob, invalid_suffix in blob)
+        for blob in blobs
+        if f"{as_at}{OS_SEP}frame." in blob
     )
 
+    first_item = next(frame_blobs, (False, False))
+
+    complete, ignore = zip(first_item, *frame_blobs)
+
     return any(complete) and not any(ignore)
 
 


Test patch:
diff --git a/tests/sql_battery/test_shapes_and_errors_battery.py b/tests/sql_battery/test_shapes_and_errors_battery.py
--- a/tests/sql_battery/test_shapes_and_errors_battery.py
+++ b/tests/sql_battery/test_shapes_and_errors_battery.py
@@ -1478,6 +1478,8 @@
         ("SELECT * FROM $planets, $satellites, $astronauts", None, None, UnsupportedSyntaxError),
         # 1448
         ("SELECT COUNT(*), planetId FROM $satellites", None, None, SqlError),
+        # 1462 - unhandled exception when working with empty datasets
+        ("SELECT * FROM testdata.partitioned.empty FOR '2000-01-01'", None, None, EmptyDatasetError),
 ]
 # fmt:on