25
25
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26
26
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
27
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
- from typing import Optional , List , TypeVar , Any , Type
28
+ from typing import Optional , List , TypeVar , Any , Type , Union
29
29
30
30
from servicex .configuration import Configuration
31
31
from servicex .func_adl .func_adl_dataset import FuncADLQuery
32
32
from servicex .models import ResultFormat , TransformStatus
33
33
from servicex .query_cache import QueryCache
34
34
from servicex .servicex_adapter import ServiceXAdapter
35
+ from servicex .query import Query , GenericQuery , QueryStringGenerator , GenericQueryStringGenerator
35
36
from servicex .types import DID
36
37
from servicex .python_dataset import PythonQuery
37
38
from servicex .dataset_group import DatasetGroup
@@ -57,21 +58,26 @@ def get_codegen(_sample: Sample, _general: General):
57
58
datasets = []
58
59
for sample in config .Sample :
59
60
if sample .Query :
60
- if type (sample .Query ) is str :
61
- qastle_query = qastle .python_ast_to_text_ast (ast .parse (sample .Query )) # NOQA E501
62
- sample .Query = FuncADLQuery ()
61
+ # if string or QueryStringGenerator, turn into a Query
62
+ if isinstance (sample .Query , str ) or isinstance (sample .Query , QueryStringGenerator ):
63
+ sample .Query = sx .generic_query (dataset_identifier = sample .dataset_identifier ,
64
+ title = sample .Name ,
65
+ codegen = get_codegen (sample , config .General ),
66
+ result_format = config .General .OutputFormat ,
67
+ ignore_cache = sample .IgnoreLocalCache ,
68
+ query = sample .Query )
69
+ # query._q_ast = sample.Query._q_ast
70
+ # query._item_type = sample.Query._item_type
71
+ if isinstance (sample .Query , FuncADLQuery ):
72
+ query = sx .func_adl_dataset (sample .dataset_identifier , sample .Name ,
73
+ get_codegen (sample , config .General ),
74
+ config .General .OutputFormat )
75
+ query ._q_ast = sample .Query ._q_ast
76
+ query ._item_type = sample .Query ._item_type
77
+ if sample .Tree :
78
+ query = query .set_tree (sample .Tree )
79
+ sample .Query = query
63
80
64
- sample .Query .set_provided_qastle (qastle_query )
65
-
66
- query = sx .func_adl_dataset (sample .dataset_identifier , sample .Name ,
67
- get_codegen (sample , config .General ),
68
- config .General .OutputFormat )
69
- query ._q_ast = sample .Query ._q_ast
70
- query ._item_type = sample .Query ._item_type
71
- if sample .Tree :
72
- query = query .set_tree (sample .Tree )
73
-
74
- sample .Query = query
75
81
sample .Query .ignore_cache = sample .IgnoreLocalCache
76
82
77
83
datasets .append (sample .Query )
@@ -258,3 +264,49 @@ def python_dataset(
258
264
result_format = result_format ,
259
265
ignore_cache = ignore_cache
260
266
)
267
+
268
+ def generic_query (
269
+ self ,
270
+ dataset_identifier : DID ,
271
+ codegen : str ,
272
+ query : Union [str , QueryStringGenerator ],
273
+ title : str = "ServiceX Client" ,
274
+ result_format : ResultFormat = ResultFormat .parquet ,
275
+ ignore_cache : bool = False
276
+ ) -> Query :
277
+ r"""
278
+ Generate a Query object for a generic codegen specification
279
+
280
+ :param dataset_identifier: The dataset identifier or filelist to be the source of files
281
+ :param title: Title to be applied to the transform. This is also useful for
282
+ relating transform results.
283
+ :param codegen: Name of the code generator to use with this transform
284
+ :param result_format: Do you want Paqrquet or Root? This can be set later with
285
+ the set_result_format method
286
+ :param ignore_cache: Ignore the query cache and always run the query
287
+ :return: A Query object
288
+
289
+ """
290
+
291
+ if codegen not in self .code_generators :
292
+ raise NameError (
293
+ f"{ codegen } code generator not supported by serviceX "
294
+ f"deployment at { self .servicex .url } "
295
+ )
296
+
297
+ if isinstance (query , str ):
298
+ query = GenericQueryStringGenerator (query )
299
+ if not isinstance (query , QueryStringGenerator ):
300
+ raise ValueError ("query argument must be string or QueryStringGenerator" )
301
+
302
+ qobj = GenericQuery (dataset_identifier = dataset_identifier ,
303
+ sx_adapter = self .servicex ,
304
+ title = title ,
305
+ codegen = codegen ,
306
+ config = self .config ,
307
+ query_cache = self .query_cache ,
308
+ result_format = result_format ,
309
+ ignore_cache = ignore_cache
310
+ )
311
+ qobj .query_string_generator = query
312
+ return qobj
0 commit comments