Repository: mabel-dev/opteryx

Issue:
🪲 PUSHED filters and COUNT aren't playing nicely
~~~sql
SELECT count(*) FROM testdata.flat.formats.parquet WHERE followers = 10
~~~
~~~
SELECT * FROM testdata.flat.formats.parquet WHERE followers = 10
~~~


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__ = 414
+__build__ = 416
 
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -29,7 +29,7 @@ class VersionStatus(Enum):
 _major = 0
 _minor = 14
 _revision = 1
-_status = VersionStatus.ALPHA
+_status = VersionStatus.RELEASE
 
 __author__ = "@joocer"
 __version__ = f"{_major}.{_minor}.{_revision}" + (
diff --git a/opteryx/utils/file_decoders.py b/opteryx/utils/file_decoders.py
--- a/opteryx/utils/file_decoders.py
+++ b/opteryx/utils/file_decoders.py
@@ -127,6 +127,7 @@ def parquet_decoder(buffer, projection: List = None, selection=None, just_schema
 
     # Convert the selection to DNF format if applicable
     _select, selection = PredicatePushable.to_dnf(selection) if selection else (None, None)
+    selected_columns = None
 
     stream: BinaryIO = None
     if isinstance(buffer, memoryview):
@@ -150,19 +151,17 @@ def parquet_decoder(buffer, projection: List = None, selection=None, just_schema
         # If no columns are selected, set to None
         if not selected_columns:
             selected_columns = None
+
     # Special handling for projection of [] (usually means COUNT(*))
     if projection == []:
-        parquet_file = parquet.ParquetFile(stream)
-        return pyarrow.Table.from_pydict(
-            {"_": numpy.full(parquet_file.metadata.num_rows, True, dtype=numpy.bool_)}
-        )
-    else:
-        selected_columns = None
+        selected_columns = []
 
     # Read the parquet table with the optimized column list and selection filters
     table = parquet.read_table(stream, columns=selected_columns, pre_buffer=False, filters=_select)
     if selection:
         table = filter_records(selection, table)
+    if projection == []:
+        return pyarrow.Table.from_pydict({"_": numpy.full(table.num_rows, True, dtype=numpy.bool_)})
     return table
 
 


Test patch:
diff --git a/tests/sql_battery/tests/results/regression_002.results_tests b/tests/sql_battery/tests/results/regression_002.results_tests
new file mode 100644
--- /dev/null
+++ b/tests/sql_battery/tests/results/regression_002.results_tests
@@ -0,0 +1,5 @@
+{
+    "summary": "Pushing Filters and Count optimizations were run in the wrong order",
+    "statement": "SELECT count(*) AS ten_followers FROM testdata.flat.formats.parquet WHERE followers = 10;",
+    "result": {"ten_followers": [353]}
+}
\ No newline at end of file
diff --git a/tests/storage/test_blob_s3.py b/tests/storage/test_blob_s3.py
--- a/tests/storage/test_blob_s3.py
+++ b/tests/storage/test_blob_s3.py
@@ -12,7 +12,6 @@
 from tests.tools import is_arm, is_mac, is_windows, skip_if
 
 BUCKET_NAME = "mabellabs"
-SECRETS = None
 
 
 @skip_if(is_arm() or is_windows() or is_mac())  # reduce cost
@@ -23,13 +22,13 @@ def test_minio_storage():
 
     # SELECT EVERYTHING
     cur = conn.cursor()
-    cur.execute(f"SELECT * FROM {BUCKET_NAME}.space_missions WITH(NO_PARTITION);")
+    cur.execute(f"SELECT * FROM {BUCKET_NAME}.space_missions;")
     assert cur.rowcount == 4630, cur.rowcount
 
     # PROCESS THE DATA IN SOME WAY
     cur = conn.cursor()
     cur.execute(
-        f"SELECT COUNT(*) AS Missions, Company FROM {BUCKET_NAME}.space_missions WITH(NO_PARTITION) GROUP BY Company;"
+        f"SELECT COUNT(*) AS Missions, Company FROM {BUCKET_NAME}.space_missions GROUP BY Company;"
     )
     assert cur.rowcount == 62, cur.rowcount