Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 18 additions & 25 deletions libs/executors/garf_executors/entrypoints/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,6 @@ def main():
raise exceptions.GarfExecutorError(
f'No execution context found for source {args.source} in {config_file}'
)
query_executor = garf_executors.setup_executor(
source=args.source,
fetcher_parameters=context.fetcher_parameters,
enable_cache=args.enable_cache,
cache_ttl_seconds=args.cache_ttl_seconds,
)
batch = {query: reader_client.read(query) for query in args.query}
query_executor.execute_batch(batch, context, args.parallel_threshold)
else:
param_types = ['source', 'macro', 'template']
outputs = args.output.split(',')
Expand All @@ -116,23 +108,24 @@ def main():
writer_parameters=writer_parameters,
fetcher_parameters=source_parameters,
)
query_executor = garf_executors.setup_executor(
source=args.source,
fetcher_parameters=context.fetcher_parameters,
enable_cache=args.enable_cache,
cache_ttl_seconds=args.cache_ttl_seconds,
)
if args.parallel_queries and len(args.query) > 1:
logger.info('Running queries in parallel')
batch = {query: reader_client.read(query) for query in args.query}
query_executor.execute_batch(batch, context, args.parallel_threshold)
else:
if len(args.query) > 1:
logger.info('Running queries sequentially')
for query in args.query:
query_executor.execute(
query=reader_client.read(query), title=query, context=context
)
query_executor = garf_executors.setup_executor(
source=args.source,
fetcher_parameters=context.fetcher_parameters,
enable_cache=args.enable_cache,
cache_ttl_seconds=args.cache_ttl_seconds,
)
batch = {query: reader_client.read(query) for query in args.query}
if args.parallel_queries and len(args.query) > 1:
logger.info('Running queries in parallel')
batch = {query: reader_client.read(query) for query in args.query}
query_executor.execute_batch(batch, context, args.parallel_threshold)
else:
if len(args.query) > 1:
logger.info('Running queries sequentially')
for query in args.query:
query_executor.execute(
query=reader_client.read(query), title=query, context=context
)
logging.shutdown()


Expand Down
5 changes: 5 additions & 0 deletions libs/executors/tests/end-to-end/query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SELECT
resource,
dimension.name AS name,
metric.clicks AS clics
FROM resource
34 changes: 34 additions & 0 deletions libs/executors/tests/end-to-end/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import pathlib
import subprocess

import yaml

_SCRIPT_PATH = pathlib.Path(__file__).parent


Expand Down Expand Up @@ -89,3 +91,35 @@ def test_fake_source_from_file(self, tmp_path):

assert result.returncode == 0
assert json.loads(result.stdout) == self.expected_output

def test_fake_source_from_config(self, tmp_path):
query_path = tmp_path / 'query.sql'
with pathlib.Path.open(query_path, 'w', encoding='utf-8') as f:
f.write(self.query)
test_config = _SCRIPT_PATH / 'test_config.yaml'
with open(test_config, 'r', encoding='utf-8') as f:
config_data = yaml.safe_load(f)
original_data_location = config_data['fake']['fetcher_parameters'][
'data_location'
]
config_data['fake']['fetcher_parameters']['data_location'] = str(
_SCRIPT_PATH / original_data_location
)
tmp_config = tmp_path / 'config.yaml'
with open(tmp_config, 'w', encoding='utf-8') as f:
yaml.dump(config_data, f, encoding='utf-8')
command = (
f'garf {str(query_path)} --source fake '
f'-c {str(tmp_config)} '
'--loglevel ERROR'
)
result = subprocess.run(
command,
shell=True,
check=False,
capture_output=True,
text=True,
)

assert result.returncode == 0
assert json.loads(result.stdout) == self.expected_output
4 changes: 3 additions & 1 deletion libs/executors/tests/end-to-end/test_config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
fake:
writer: console
writer_parameters:
format: json
fetcher_parameters:
data_location: ./test.json
data_location: test.json