Repository: jina-ai/serve
Pull request: refactor: move queryset from drivers to types
**Changes introduced**
Move QuerySet logic to `types` so that it can be made a regular way of accessing Documents and other primitive types `attributes`.

Plan to use this change in #1718.



Problem statement:
dunderkey logic should be moved to Types
#**Describe the bug**
Right now we use dunder_key heavily in our QueryLanguage but we also profit from its features and syntax from the Types module.

This opens the door to potential cyclic dependencies and should be addressed. Types should not depend on other modules except .proto and Drivers can indeed see Types.

Hints from issue discussion:
This issue is stale because it has been open 20 days with no activity. Remove stale label or comment or this will be closed in 4 days

Commit message: refactor: move queryset from drivers to types

Patch to review:
diff --git a/jina/drivers/control.py b/jina/drivers/control.py
index 1c32aa4b467f4..6201c08451623 100644
--- a/jina/drivers/control.py
+++ b/jina/drivers/control.py
@@ -6,7 +6,7 @@
 from google.protobuf.json_format import MessageToJson
 
 from . import BaseDriver
-from .querylang.queryset.dunderkey import dunder_get
+from jina.types.querylang.queryset.dunderkey import dunder_get
 from ..excepts import UnknownControlCommand, RuntimeTerminated, NoExplicitMessage
 from ..proto import jina_pb2
 
diff --git a/jina/drivers/evaluate.py b/jina/drivers/evaluate.py
index f1ecd24d06733..d0d40f520437b 100644
--- a/jina/drivers/evaluate.py
+++ b/jina/drivers/evaluate.py
@@ -6,7 +6,7 @@
 import numpy
 
 from . import BaseExecutableDriver
-from .querylang.queryset.dunderkey import dunder_get
+from jina.types.querylang.queryset.dunderkey import dunder_get
 from .search import KVSearchDriver
 from ..types.document import Document
 from ..types.document.helper import DocGroundtruthPair
diff --git a/jina/drivers/querylang/filter.py b/jina/drivers/querylang/filter.py
index e434b8de3e7f4..faca6ba48a320 100644
--- a/jina/drivers/querylang/filter.py
+++ b/jina/drivers/querylang/filter.py
@@ -3,7 +3,7 @@
 
 from typing import Dict, Any
 
-from .queryset.lookup import Q
+from jina.types.querylang.queryset.lookup import Q
 from .. import QuerySetReader, BaseRecursiveDriver
 
 if False:
diff --git a/jina/drivers/querylang/sort.py b/jina/drivers/querylang/sort.py
index ea193bc25978d..fb2205c7a61b7 100644
--- a/jina/drivers/querylang/sort.py
+++ b/jina/drivers/querylang/sort.py
@@ -3,7 +3,7 @@
 
 from typing import Tuple
 
-from .queryset.dunderkey import dunder_get
+from jina.types.querylang.queryset.dunderkey import dunder_get
 from .. import QuerySetReader, BaseRecursiveDriver
 
 if False:
diff --git a/jina/types/ndarray/generic.py b/jina/types/ndarray/generic.py
index 9aaa776efcbe9..57f1a203896c9 100644
--- a/jina/types/ndarray/generic.py
+++ b/jina/types/ndarray/generic.py
@@ -114,4 +114,4 @@ def value(self, value):
 
     def _build_content_dict(self):
         return {'value': self.value,
-                'is_sparse': self.is_sparse}
\ No newline at end of file
+                'is_sparse': self.is_sparse}
diff --git a/jina/drivers/querylang/queryset/__init__.py b/jina/types/querylang/queryset/__init__.py
similarity index 100%
rename from jina/drivers/querylang/queryset/__init__.py
rename to jina/types/querylang/queryset/__init__.py
diff --git a/jina/drivers/querylang/queryset/dunderkey.py b/jina/types/querylang/queryset/dunderkey.py
similarity index 100%
rename from jina/drivers/querylang/queryset/dunderkey.py
rename to jina/types/querylang/queryset/dunderkey.py
diff --git a/jina/drivers/querylang/queryset/helper.py b/jina/types/querylang/queryset/helper.py
similarity index 96%
rename from jina/drivers/querylang/queryset/helper.py
rename to jina/types/querylang/queryset/helper.py
index 3c0962c35736c..7f55a69500e6a 100644
--- a/jina/drivers/querylang/queryset/helper.py
+++ b/jina/types/querylang/queryset/helper.py
@@ -1,7 +1,7 @@
 from functools import partial
 from typing import Callable, List, Type, Union, Iterable
 
-from ....excepts import LookupyError
+from jina.excepts import LookupyError
 
 
 def iff(precond: Callable, val: Union[int, str], f: Callable) -> bool:
diff --git a/jina/drivers/querylang/queryset/lookup.py b/jina/types/querylang/queryset/lookup.py
similarity index 100%
rename from jina/drivers/querylang/queryset/lookup.py
rename to jina/types/querylang/queryset/lookup.py
diff --git a/tests/unit/test_helper.py b/tests/unit/test_helper.py
index c1806273a3e5b..1cda72dc346d4 100644
--- a/tests/unit/test_helper.py
+++ b/tests/unit/test_helper.py
@@ -6,7 +6,7 @@
 from cli import _is_latest_version
 from jina import NdArray, Request
 from jina.clients.helper import _safe_callback, pprint_routes
-from jina.drivers.querylang.queryset.dunderkey import dunder_get
+from jina.types.querylang.queryset.dunderkey import dunder_get
 from jina.excepts import BadClientCallback, NotSupportedError
 from jina.helper import cached_property, convert_tuple_to_list, deprecated_alias, is_yaml_filepath
 from jina.jaml.helper import complete_path
diff --git a/tests/unit/drivers/querylang/queryset/__init__.py b/tests/unit/types/querylang/queryset/__init__.py
similarity index 100%
rename from tests/unit/drivers/querylang/queryset/__init__.py
rename to tests/unit/types/querylang/queryset/__init__.py
diff --git a/tests/unit/drivers/querylang/queryset/test_dunderkeys.py b/tests/unit/types/querylang/queryset/test_dunderkeys.py
similarity index 97%
rename from tests/unit/drivers/querylang/queryset/test_dunderkeys.py
rename to tests/unit/types/querylang/queryset/test_dunderkeys.py
index 4cc4243e6f836..08899f5aaea83 100644
--- a/tests/unit/drivers/querylang/queryset/test_dunderkeys.py
+++ b/tests/unit/types/querylang/queryset/test_dunderkeys.py
@@ -1,7 +1,7 @@
 import pytest
 
 from jina import Document
-from jina.drivers.querylang.queryset.dunderkey import (
+from jina.types.querylang.queryset.dunderkey import (
     dunderkey,
     dunder_init,
     dunder_get,
@@ -14,9 +14,11 @@
 def test_dunderkey():
     assert dunderkey('a', 'b', 'c') == 'a__b__c'
 
+
 def test_dunder_init():
     assert dunder_init('a__b__c') == 'a__b'
 
+
 def test_dunder_get():
     assert dunder_get({'a': {'b': 5}}, 'a__b') == 5
     assert dunder_get({'a': {'b': 8, 'c': {'d': 8}}}, 'a__c__d') == 8
diff --git a/tests/unit/drivers/querylang/queryset/test_lookup.py b/tests/unit/types/querylang/queryset/test_lookup.py
similarity index 98%
rename from tests/unit/drivers/querylang/queryset/test_lookup.py
rename to tests/unit/types/querylang/queryset/test_lookup.py
index 3f4577e1c2b3a..9c6fa2fa6c7a6 100644
--- a/tests/unit/drivers/querylang/queryset/test_lookup.py
+++ b/tests/unit/types/querylang/queryset/test_lookup.py
@@ -1,6 +1,6 @@
 import pytest
 
-from jina.drivers.querylang.queryset.lookup import LookupNode, LookupLeaf, Q, QuerySet
+from jina.types.querylang.queryset.lookup import LookupNode, LookupLeaf, Q, QuerySet
 from jina.types.document import Document
 from tests import random_docs
 


Code review comments:
diff_hunk: @@ -6,7 +6,7 @@
 from google.protobuf.json_format import MessageToJson
 
 from . import BaseDriver
-from .querylang.queryset.dunderkey import dunder_get
+from jina.types.querylang.queryset.dunderkey import dunder_get
path: jina/drivers/control.py
text: @user1:
it should still be a relative import, e.g. `from ..types...`

@author:
oh yes, pycharm auto refactor