💡 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
Parse true and false as boolean literals in SQL queries (#1316)
Yash Raj Pandey00622f2cf145
diff --git a/src/python/txtai/database/sql/token.py b/src/python/txtai/database/sql/token.pyindex f073430c..5213dcc5 100644--- a/src/python/txtai/database/sql/token.py+++ b/src/python/txtai/database/sql/token.py@@ -26,6 +26,9 @@ class Token:# Default list of sort order operatorsSORT_ORDER = ["asc", "desc"]+ # Default list of boolean literals+ BOOLEANS = ["true", "false"]+@staticmethoddef get(tokens, x):"""@@ -197,8 +200,8 @@ class Token:True if this token is a literal, False otherwise"""- # Literals are wrapped in quotes, parens, wildcards or numeric.- return token and (token.startswith(("'", '"', ",", "(", ")", "*")) or token.replace(".", "", 1).isdigit())+ # Literals are wrapped in quotes, parens, wildcards, numeric or boolean.+ return token and (token.startswith(("'", '"', ",", "(", ")", "*")) or token.replace(".", "", 1).isdigit() or token.lower() in Token.BOOLEANS)@staticmethoddef islogicseparator(token):diff --git a/test/python/testdatabase/testsql.py b/test/python/testdatabase/testsql.pyindex a8bcf4d8..e8eebf82 100644--- a/test/python/testdatabase/testsql.py+++ b/test/python/testdatabase/testsql.py@@ -128,6 +128,7 @@ class TestSQL(unittest.TestCase):self.assertSql("where", "select * from txtai where [a b] < 1 or a > 1", "json_extract(data, '$.a b') < 1 or json_extract(data, '$.a') > 1")self.assertSql("where", "select [a[0].c[0]] a from txtai where a < 1", "a < 1")+ self.assertSql("where", "select * from txtai where [true] = 1", "json_extract(data, '$.true') = 1")self.assertSql("groupby", "select * from txtai group by [a]", "json_extract(data, '$.a')")self.assertSql("orderby", "select * from txtai where order by [a]", "json_extract(data, '$.a')")@@ -338,6 +339,8 @@ class TestSQL(unittest.TestCase):self.assertSql("where", prefix + "WHERE a NOT LIKE 'abc'", "json_extract(data, '$.a') NOT LIKE 'abc'")self.assertSql("where", prefix + "WHERE a IN (1, 2, 3, b)", "json_extract(data, '$.a') IN (1, 2, 3, json_extract(data, '$.b'))")self.assertSql("where", prefix + "WHERE a is not null", "json_extract(data, '$.a') is not null")+ self.assertSql("where", prefix + "where a = true", "json_extract(data, '$.a') = true")+ self.assertSql("where", prefix + "WHERE a is not FALSE", "json_extract(data, '$.a') is not FALSE")self.assertSql("where", prefix + "WHERE score >= 0.15", "score >= 0.15")def testWhereCompound(self):