garf-executors 0.0.6__py3-none-any.whl → 0.0.7__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of garf-executors might be problematic. Click here for more details.

@@ -11,11 +11,7 @@
11
11
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
- """Defines simplified import of executors.
15
-
16
- Instead of importing `garf_executors.api_executor.ApiQueryExecutor`
17
- import like this `garf_executors.ApiQueryExecutor`
18
- """
14
+ """Executors to fetch data from various APIS and postprocess them."""
19
15
 
20
16
  from __future__ import annotations
21
17
 
@@ -27,4 +23,4 @@ __all__ = [
27
23
  'ApiQueryExecutor',
28
24
  ]
29
25
 
30
- __version__ = '0.0.6'
26
+ __version__ = '0.0.7'
@@ -80,21 +80,21 @@ class ApiQueryExecutor:
80
80
 
81
81
  async def aexecute(
82
82
  self, query: str, context: ApiExecutionContext, **kwargs: str
83
- ) -> None:
83
+ ) -> str:
84
84
  """Reads query, extract results and stores them in a specified location.
85
85
 
86
86
  Args:
87
87
  query: Location of the query.
88
88
  context: Query execution context.
89
89
  """
90
- self.execute(query, context, **kwargs)
90
+ await self.execute(query, context, **kwargs)
91
91
 
92
92
  def execute(
93
93
  self,
94
94
  query: str,
95
95
  title: str,
96
96
  context: ApiExecutionContext,
97
- ) -> None:
97
+ ) -> str:
98
98
  """Reads query, extract results and stores them in a specified location.
99
99
 
100
100
  Args:
@@ -102,6 +102,9 @@ class ApiQueryExecutor:
102
102
  title: Name of the query.
103
103
  context: Query execution context.
104
104
 
105
+ Returns:
106
+ Result of writing the report.
107
+
105
108
  Raises:
106
109
  GarfExecutorError: When failed to execute query.
107
110
  """
@@ -118,13 +121,14 @@ class ApiQueryExecutor:
118
121
  title,
119
122
  type(writer_client),
120
123
  )
121
- writer_client.write(results, title)
124
+ result = writer_client.write(results, title)
122
125
  logger.debug(
123
126
  'Finish writing data for query %s via %s writer',
124
127
  title,
125
128
  type(writer_client),
126
129
  )
127
130
  logger.info('%s executed successfully', title)
131
+ return result
128
132
  except Exception as e:
129
133
  logger.error('%s generated an exception: %s', title, str(e))
130
134
  raise exceptions.GarfExecutorError(
@@ -20,6 +20,7 @@ import uvicorn
20
20
 
21
21
  import garf_executors
22
22
  from garf_executors import exceptions
23
+ from garf_io import reader
23
24
 
24
25
 
25
26
  class ApiExecutorRequest(pydantic.BaseModel):
@@ -27,16 +28,32 @@ class ApiExecutorRequest(pydantic.BaseModel):
27
28
 
28
29
  Attributes:
29
30
  source: Type of API to interact with.
30
- query: Query to execute.
31
31
  title: Name of the query used as an output for writing.
32
+ query: Query to execute.
33
+ query_path: Local or remote path to query.
32
34
  context: Execution context.
33
35
  """
34
36
 
35
37
  source: str
36
- query: str
37
- title: str
38
+ title: str | None = None
39
+ query: str | None = None
40
+ query_path: str | None = None
38
41
  context: garf_executors.api_executor.ApiExecutionContext
39
42
 
43
+ @pydantic.model_validator(mode='after')
44
+ def check_query_specified(self):
45
+ if not self.query_path and not self.query:
46
+ raise exceptions.GarfExecutorError(
47
+ 'Missing one of required parameters: query, query_path'
48
+ )
49
+ return self
50
+
51
+ def model_post_init(self, __context__) -> None:
52
+ if self.query_path:
53
+ self.query = reader.FileReader().read(self.query_path)
54
+ if not self.title:
55
+ self.title = str(self.query_path)
56
+
40
57
 
41
58
  router = fastapi.APIRouter(prefix='/api')
42
59
 
@@ -52,10 +69,10 @@ async def execute(request: ApiExecutorRequest) -> dict[str, str]:
52
69
  concrete_api_fetcher(**request.context.fetcher_parameters)
53
70
  )
54
71
 
55
- query_executor.execute(request.query, request.title, request.context)
72
+ result = query_executor.execute(request.query, request.title, request.context)
56
73
 
57
74
  return fastapi.responses.JSONResponse(
58
- content=fastapi.encoders.jsonable_encoder({'result': 'success'})
75
+ content=fastapi.encoders.jsonable_encoder({'result': result})
59
76
  )
60
77
 
61
78
 
@@ -298,6 +298,8 @@ class ParamsParser:
298
298
  if not identifier or identifier not in key:
299
299
  return None
300
300
  provided_identifier, *keys = key.split('.')
301
+ if not keys:
302
+ return None
301
303
  if len(keys) > 1:
302
304
  raise GarfParamsException(
303
305
  f'{key} is invalid format,'
@@ -306,9 +308,10 @@ class ParamsParser:
306
308
  )
307
309
  provided_identifier = provided_identifier.replace('--', '')
308
310
  if provided_identifier not in self.identifiers:
311
+ supported_arguments = ', '.join(self.identifiers)
309
312
  raise GarfParamsException(
310
313
  f'CLI argument {provided_identifier} is not supported'
311
- f', supported arguments {", ".join(self.identifiers)}'
314
+ f', supported arguments {supported_arguments}'
312
315
  )
313
316
  if provided_identifier != identifier:
314
317
  return None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: garf-executors
3
- Version: 0.0.6
3
+ Version: 0.0.7
4
4
  Summary: Executes queries against API and writes data to local/remote storage.
5
5
  Author-email: "Google Inc. (gTech gPS CSE team)" <no-reply@google.com>, Andrei Markin <andrey.markin.ppc@gmail.com>
6
6
  License: Apache 2.0
@@ -0,0 +1,15 @@
1
+ garf_executors/__init__.py,sha256=PK4dnVynkPmJi8EGUYwbv4lwQ2ELO_cTO8FQaZV3VXA,858
2
+ garf_executors/api_executor.py,sha256=HOIBg-bILtLNHqtiklZio5h5xXNwVAuZMIRJTL7_5_U,4104
3
+ garf_executors/bq_executor.py,sha256=JBPxbDRYgUgpJv6SqYiFPypTFjZGIZ-SOOb6dS2sZQY,3822
4
+ garf_executors/exceptions.py,sha256=U_7Q2ZMOUf89gzZd2pw7y3g7i1NeByPPKfpZ3q7p3ZU,662
5
+ garf_executors/fetchers.py,sha256=gkAKHsDPzJySg4wYLZeCmNINtk6f17-jFzOP7tE82r8,1226
6
+ garf_executors/sql_executor.py,sha256=6tpsd1Ive5igAlQuhCSkli-tZHp58uWAU86JWGvdVpE,2722
7
+ garf_executors/entrypoints/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
+ garf_executors/entrypoints/cli.py,sha256=mWvPQkaqarDj5byHRvNAweVbUQiHZLXrC-35zY7l4fs,4043
9
+ garf_executors/entrypoints/server.py,sha256=CALlrRaKiKFOvsE1uQyjtz2UxqEeh_QqR5nBMQgMjCs,2430
10
+ garf_executors/entrypoints/utils.py,sha256=p483h5RY_kfwOhNq2RqwMnunOoTGXGA59nCyHY_Lvgg,15057
11
+ garf_executors-0.0.7.dist-info/METADATA,sha256=NBFu6iIeYifvVVMCJOr_o9GpMAEp5aMBdnK4cW5FlEs,2648
12
+ garf_executors-0.0.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
13
+ garf_executors-0.0.7.dist-info/entry_points.txt,sha256=LskWNFIw8j0WJuI18-32OZrlASXAMg1XtrRYwsKBz2E,61
14
+ garf_executors-0.0.7.dist-info/top_level.txt,sha256=sP4dCXOENPn1hDFAunjMV8Js4NND_KGeO_gQWuaT0EY,15
15
+ garf_executors-0.0.7.dist-info/RECORD,,
@@ -1,15 +0,0 @@
1
- garf_executors/__init__.py,sha256=bcb29OEvsx2XNTpbUW0LvKxoYJt5BSX3S2gqQLdRIqU,955
2
- garf_executors/api_executor.py,sha256=udrlMiYUmKh5NsIuJkNowqCenvtf5O925FPFawXSXbM,4021
3
- garf_executors/bq_executor.py,sha256=JBPxbDRYgUgpJv6SqYiFPypTFjZGIZ-SOOb6dS2sZQY,3822
4
- garf_executors/exceptions.py,sha256=U_7Q2ZMOUf89gzZd2pw7y3g7i1NeByPPKfpZ3q7p3ZU,662
5
- garf_executors/fetchers.py,sha256=gkAKHsDPzJySg4wYLZeCmNINtk6f17-jFzOP7tE82r8,1226
6
- garf_executors/sql_executor.py,sha256=6tpsd1Ive5igAlQuhCSkli-tZHp58uWAU86JWGvdVpE,2722
7
- garf_executors/entrypoints/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
- garf_executors/entrypoints/cli.py,sha256=mWvPQkaqarDj5byHRvNAweVbUQiHZLXrC-35zY7l4fs,4043
9
- garf_executors/entrypoints/server.py,sha256=rJ29VKWKaYJci1BLxZx-0LSILmUMf5BK8G1RRjRS2ts,1836
10
- garf_executors/entrypoints/utils.py,sha256=ZZJFe2N4KwgzPRvak9gW_B25qESnzOyuF-qYZ2wW2_M,14974
11
- garf_executors-0.0.6.dist-info/METADATA,sha256=35dBABJ8cVH2nI0NonZ5VGO6W4IF0gtiiw-ZFZqZhgs,2648
12
- garf_executors-0.0.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
13
- garf_executors-0.0.6.dist-info/entry_points.txt,sha256=LskWNFIw8j0WJuI18-32OZrlASXAMg1XtrRYwsKBz2E,61
14
- garf_executors-0.0.6.dist-info/top_level.txt,sha256=sP4dCXOENPn1hDFAunjMV8Js4NND_KGeO_gQWuaT0EY,15
15
- garf_executors-0.0.6.dist-info/RECORD,,