Repository: mathesar-foundation/mathesar

Issue:
Implement JSON filtering



Discussion:

Resolving patch:
diff --git a/db/functions/hints.py b/db/functions/hints.py
--- a/db/functions/hints.py
+++ b/db/functions/hints.py
@@ -125,10 +125,10 @@ def _is_hint_applicable_to_types(hint):
 json = _make_hint("json")
 
 
-json_array = _make_hint("json_array")
+json_array = _make_hint("jsonlist")
 
 
-json_object = _make_hint("json_object")
+json_object = _make_hint("map")
 
 
 # Meant to mark a DBFunction for the filtering API to use.
diff --git a/db/types/custom/json_array.py b/db/types/custom/json_array.py
--- a/db/types/custom/json_array.py
+++ b/db/types/custom/json_array.py
@@ -7,8 +7,8 @@
 from sqlalchemy.ext.compiler import compiles
 
 from db.functions import hints
-from db.functions.base import DBFunction, Equal
-from db.functions.packed import DBFunctionPacked
+from db.functions.base import DBFunction, Equal, Greater, Lesser
+from db.functions.packed import DBFunctionPacked, GreaterOrEqual, LesserOrEqual
 
 DB_TYPE = MathesarCustomType.MATHESAR_JSON_ARRAY.id
 
@@ -83,3 +83,83 @@ def unpack(self):
             ArrayLength([param0]),
             param1,
         ])
+
+
+class LengthGreaterThan(DBFunctionPacked):
+    id = 'json_array_length_greater_than'
+    name = 'Number of elements is greater than'
+    hints = tuple([
+        hints.returns(hints.boolean),
+        hints.parameter_count(2),
+        hints.parameter(0, hints.json_array),
+        hints.parameter(1, hints.string_like),
+        hints.mathesar_filter,
+    ])
+
+    def unpack(self):
+        param0 = self.parameters[0]
+        param1 = self.parameters[1]
+        return Greater([
+            ArrayLength([param0]),
+            param1,
+        ])
+
+
+class LengthGreaterorEqual(DBFunctionPacked):
+    id = 'json_array_length_greater_or_equal'
+    name = 'Number of elements is greater than or equal to'
+    hints = tuple([
+        hints.returns(hints.boolean),
+        hints.parameter_count(2),
+        hints.parameter(0, hints.json_array),
+        hints.parameter(1, hints.string_like),
+        hints.mathesar_filter,
+    ])
+
+    def unpack(self):
+        param0 = self.parameters[0]
+        param1 = self.parameters[1]
+        return GreaterOrEqual([
+            ArrayLength([param0]),
+            param1,
+        ])
+
+
+class LengthLessThan(DBFunctionPacked):
+    id = 'json_array_length_less_than'
+    name = 'Number of elements is less than'
+    hints = tuple([
+        hints.returns(hints.boolean),
+        hints.parameter_count(2),
+        hints.parameter(0, hints.json_array),
+        hints.parameter(1, hints.string_like),
+        hints.mathesar_filter,
+    ])
+
+    def unpack(self):
+        param0 = self.parameters[0]
+        param1 = self.parameters[1]
+        return Lesser([
+            ArrayLength([param0]),
+            param1,
+        ])
+
+
+class LengthLessorEqual(DBFunctionPacked):
+    id = 'json_array_length_less_or_equal'
+    name = 'Number of elements is less than or equal to'
+    hints = tuple([
+        hints.returns(hints.boolean),
+        hints.parameter_count(2),
+        hints.parameter(0, hints.json_array),
+        hints.parameter(1, hints.string_like),
+        hints.mathesar_filter,
+    ])
+
+    def unpack(self):
+        param0 = self.parameters[0]
+        param1 = self.parameters[1]
+        return LesserOrEqual([
+            ArrayLength([param0]),
+            param1,
+        ])


Test patch:
diff --git a/db/tests/types/test_json.py b/db/tests/types/test_json.py
--- a/db/tests/types/test_json.py
+++ b/db/tests/types/test_json.py
@@ -10,6 +10,11 @@
     (json_array.LengthEquals, 3, 11),
     (json_array.LengthEquals, 4, 1),
     (json_array.LengthEquals, 6, 1),
+    (json_array.LengthGreaterThan, 3, 2),
+    (json_array.LengthGreaterorEqual, 3, 13),
+    (json_array.LengthLessThan, 4, 12),
+    (json_array.LengthLessorEqual, 4, 13),
+    (json_array.LengthGreaterorEqual, 4, 2),
 ])
 def test_json_array_filter_functions(json_table_obj, main_db_function, literal_param, expected_count):
     table, engine = json_table_obj