💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows
Python agentsaiai-agentsembeddingsinformation-retrievallanguage-modellarge-language-modelsllmnlppythonragretrieval-augmented-generationsearchsearch-enginesemantic-searchsentence-embeddingstransformerstxtaivector-databasevector-search
Merge aggregate columns written in uppercase across shards (#1352)
Raashish Aggarwal9c718f787670
diff --git a/src/python/txtai/database/sql/aggregate.py b/src/python/txtai/database/sql/aggregate.pyindex e7bb043d..dee362dd 100644--- a/src/python/txtai/database/sql/aggregate.py+++ b/src/python/txtai/database/sql/aggregate.py@@ -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.avgreturn aggregatesdiff --git a/test/python/testdatabase/testsql.py b/test/python/testdatabase/testsql.pyindex e0ed4d15..1b141101 100644--- a/test/python/testdatabase/testsql.py+++ b/test/python/testdatabase/testsql.py@@ -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