mirror of
https://github.com/neuml/txtai.git
synced 2026-10-11 21:39:55 +00:00
Merge aggregate columns written in uppercase across shards (#1352)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user