-
Notifications
You must be signed in to change notification settings - Fork 14
Allow user specified Adaptor and MiniIO Interfaces #537
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
gordonwatts
wants to merge
1
commit into
master
Choose a base branch
from
feat/injecting-adaptors
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ | |
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
import logging | ||
from typing import Optional, List, TypeVar, Any, Mapping, Union, cast | ||
from typing import Optional, List, Type, TypeVar, Any, Mapping, Union, cast | ||
from pathlib import Path | ||
|
||
from servicex.configuration import Configuration | ||
|
@@ -114,7 +114,7 @@ def _load_ServiceXSpec( | |
file_path = config | ||
|
||
import sys | ||
from ccorp.ruamel.yaml.include import YAML | ||
from ccorp.ruamel.yaml.include import YAML # type: ignore | ||
yaml = YAML() | ||
|
||
if sys.version_info < (3, 10): | ||
|
@@ -137,7 +137,14 @@ def _load_ServiceXSpec( | |
return config | ||
|
||
|
||
def _build_datasets(config, config_path, servicex_name, fail_if_incomplete): | ||
def _build_datasets( | ||
config, | ||
config_path, | ||
servicex_name, | ||
fail_if_incomplete, | ||
servicex_adaptor, | ||
minio_adaptor_class, | ||
): | ||
def get_codegen(_sample: Sample, _general: General): | ||
if _sample.Codegen is not None: | ||
return _sample.Codegen | ||
|
@@ -148,7 +155,7 @@ def get_codegen(_sample: Sample, _general: General): | |
elif isinstance(_sample.Query, Query): | ||
return _sample.Query.codegen | ||
|
||
sx = ServiceXClient(backend=servicex_name, config_path=config_path) | ||
sx = ServiceXClient(backend=servicex_name, config_path=config_path, servicex_adaptor=servicex_adaptor) | ||
datasets = [] | ||
for sample in config.Sample: | ||
query = sx.generic_query( | ||
|
@@ -158,7 +165,8 @@ def get_codegen(_sample: Sample, _general: General): | |
result_format=config.General.OutputFormat.to_ResultFormat(), | ||
ignore_cache=sample.IgnoreLocalCache, | ||
query=sample.Query, | ||
fail_if_incomplete=fail_if_incomplete | ||
fail_if_incomplete=fail_if_incomplete, | ||
minio_adaptor_class=minio_adaptor_class | ||
) | ||
logger.debug(f"Query string: {query.generate_selection_string()}") | ||
query.ignore_cache = sample.IgnoreLocalCache | ||
|
@@ -199,11 +207,13 @@ def deliver( | |
config_path: Optional[str] = None, | ||
servicex_name: Optional[str] = None, | ||
return_exceptions: bool = True, | ||
fail_if_incomplete: bool = True | ||
fail_if_incomplete: bool = True, | ||
servicex_adaptor: Optional[ServiceXAdapter] = None, | ||
minio_adaptor_class: Optional[Type] = None, | ||
): | ||
config = _load_ServiceXSpec(config) | ||
|
||
datasets = _build_datasets(config, config_path, servicex_name, fail_if_incomplete) | ||
datasets = _build_datasets(config, config_path, servicex_name, fail_if_incomplete, servicex_adaptor, minio_adaptor_class=minio_adaptor_class) | ||
|
||
group = DatasetGroup(datasets) | ||
|
||
|
@@ -223,7 +233,7 @@ class ServiceXClient: | |
Instances of this class are factories for `Datasets`` | ||
""" | ||
|
||
def __init__(self, backend=None, url=None, config_path=None): | ||
def __init__(self, backend=None, url=None, config_path=None, servicex_adaptor=None): | ||
r""" | ||
If both `backend` and `url` are unspecified then it will attempt to pick up | ||
the default backend from `.servicex` | ||
|
@@ -248,15 +258,18 @@ def __init__(self, backend=None, url=None, config_path=None): | |
if bool(url) == bool(backend): | ||
raise ValueError("Only specify backend or url... not both") | ||
|
||
if url: | ||
self.servicex = ServiceXAdapter(url) | ||
elif backend: | ||
if backend not in self.endpoints: | ||
raise ValueError(f"Backend {backend} not defined in .servicex file") | ||
self.servicex = ServiceXAdapter( | ||
self.endpoints[backend].endpoint, | ||
refresh_token=self.endpoints[backend].token, | ||
) | ||
if servicex_adaptor is None: | ||
if url: | ||
self.servicex = ServiceXAdapter(url) | ||
elif backend: | ||
if backend not in self.endpoints: | ||
raise ValueError(f"Backend {backend} not defined in .servicex file") | ||
self.servicex = ServiceXAdapter( | ||
self.endpoints[backend].endpoint, | ||
refresh_token=self.endpoints[backend].token, | ||
) | ||
else: | ||
self.servicex = servicex_adaptor | ||
|
||
self.query_cache = QueryCache(self.config) | ||
self.code_generators = set(self.get_code_generators(backend).keys()) | ||
|
@@ -308,7 +321,7 @@ def delete_transform(self, transform_id): | |
""" | ||
return self.servicex.delete_transform(transform_id) | ||
|
||
def get_code_generators(self, backend=None): | ||
def get_code_generators(self, backend: Optional[str]=None): | ||
r""" | ||
Retrieve the code generators deployed with the serviceX instance | ||
:return: The list of code generators as json dictionary | ||
|
@@ -321,6 +334,7 @@ def get_code_generators(self, backend=None): | |
return cached_backends["codegens"] | ||
else: | ||
code_generators = self.servicex.get_code_generators() | ||
assert backend is not None, "Backend must be specified to cache code generators" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this code that we can ever hit? |
||
self.query_cache.update_codegen_by_backend(backend, code_generators) | ||
return code_generators | ||
|
||
|
@@ -333,6 +347,7 @@ def generic_query( | |
result_format: ResultFormat = ResultFormat.parquet, | ||
ignore_cache: bool = False, | ||
fail_if_incomplete: bool = True, | ||
minio_adaptor_class: Optional[Type] = None, | ||
) -> Query: | ||
r""" | ||
Generate a Query object for a generic codegen specification | ||
|
@@ -377,6 +392,7 @@ def generic_query( | |
result_format=result_format, | ||
ignore_cache=ignore_cache, | ||
query_string_generator=query, | ||
fail_if_incomplete=fail_if_incomplete | ||
fail_if_incomplete=fail_if_incomplete, | ||
minio_adaptor_class=minio_adaptor_class, | ||
) | ||
return qobj |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel this change is a bit independent of the rest of the PR, should it be included here?