Merge aggregate columns written in uppercase across shards (#1352)

This commit is contained in:
Raashish Aggarwal
2026-10-07 09:00:39 -04:00
committed by GitHub
parent c486f4706e
commit 9c718f7876
2 changed files with 17 additions and 5 deletions
+6 -5
View File
@@ -63,14 +63,15 @@ class Aggregate(SQL):
aggregates = {}
for column in columns:
column = column.lower()
if column.startswith(("count(", "sum(", "total(")):
# Match function names case-insensitively but keep the column name as returned
name = column.lower()
if name.startswith(("count(", "sum(", "total(")):
aggregates[column] = sum
elif column.startswith("max("):
elif name.startswith("max("):
aggregates[column] = max
elif column.startswith("min("):
elif name.startswith("min("):
aggregates[column] = min
elif column.startswith("avg("):
elif name.startswith("avg("):
aggregates[column] = self.avg
return aggregates
+11
View File
@@ -62,6 +62,17 @@ class TestSQL(unittest.TestCase):
with self.assertRaises(SQLError):
aggregate("select avg(price) from txtai", [{"avg(price)": 100.0}, {"avg(price)": 10.0}])
def testAggregateCase(self):
"""
Test Aggregate combines aggregate columns written in any case
"""
aggregate = Aggregate()
query = "select COUNT(*), Sum(price), MAX(price) from txtai"
results = [{"COUNT(*)": 1, "Sum(price)": 1.0, "MAX(price)": 1.0}, {"COUNT(*)": 2, "Sum(price)": 5.0, "MAX(price)": 4.0}]
self.assertEqual(aggregate(query, results), [{"COUNT(*)": 3, "Sum(price)": 6.0, "MAX(price)": 4.0}])
def testAggregateNull(self):
"""
Test Aggregate skips NULL values returned by shards with no matching rows