2525# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2626# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2727# 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
2929
3030from servicex .configuration import Configuration
3131from servicex .func_adl .func_adl_dataset import FuncADLQuery
3232from servicex .models import ResultFormat , TransformStatus
3333from servicex .query_cache import QueryCache
3434from servicex .servicex_adapter import ServiceXAdapter
35+ from servicex .query import Query , GenericQuery , QueryStringGenerator , GenericQueryStringGenerator
3536from servicex .types import DID
3637from servicex .python_dataset import PythonQuery
3738from servicex .dataset_group import DatasetGroup
@@ -57,21 +58,26 @@ def get_codegen(_sample: Sample, _general: General):
5758 datasets = []
5859 for sample in config .Sample :
5960 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
6380
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
7581 sample .Query .ignore_cache = sample .IgnoreLocalCache
7682
7783 datasets .append (sample .Query )
@@ -258,3 +264,49 @@ def python_dataset(
258264 result_format = result_format ,
259265 ignore_cache = ignore_cache
260266 )
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