Skip to content

Commit 73e61db

Browse files
authored
Merge pull request #765 from no23reason/dho-cq-577-context
feat: add classes to parse executionRequest in Flight RPC
2 parents 3e440e0 + 724cbba commit 73e61db

16 files changed

Lines changed: 145 additions & 19 deletions

File tree

.github/workflows/rw-collect-changes.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,4 @@ jobs:
4646
- 'Makefile'
4747
- 'gooddata-api-client/**'
4848
- 'gooddata-dbt/**'
49+
- 'gooddata-flight-server/**'

.github/workflows/rw-python-tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
if: ${{ matrix.python_version == 'py312' }}
2525
uses: codecov/codecov-action@v3
2626
with:
27-
files: ./gooddata-sdk/coverage.xml,./gooddata-pandas/coverage.xml,./gooddata-fdw/coverage.xml
27+
files: ./gooddata-sdk/coverage.xml,./gooddata-pandas/coverage.xml,./gooddata-fdw/coverage.xml,./gooddata-flight-server/coverage.xml
2828
lint-and-format-check:
2929
runs-on: ubuntu-latest
3030
if: ${{inputs.changed-python-modules == 'true'}}

Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
ARG PY_TAG
33
FROM python:${PY_TAG}
44

5+
ARG PY_TAG
56
ARG ENV_TAG
67
# tox defines all python targets, makefile recognizes TEST_ENVS and forces
78
# tox to execute only tests for installed python
89
ENV TEST_ENVS=${ENV_TAG}
910

1011
# install make and gosu
11-
ENV GOSU_VERSION 1.14
12+
ENV GOSU_VERSION=1.14
1213
RUN set -x \
1314
&& apt-get update \
1415
&& apt-get install -y --no-install-recommends make curl gnupg \
@@ -26,8 +27,8 @@ RUN set -x \
2627
&& true
2728

2829
# install tox
29-
ENV PYTHON_TOX_VERSION 4.14.0
30-
ENV PYTHON_TOX_UV_VERSION 1.5.1
30+
ENV PYTHON_TOX_VERSION=4.14.1
31+
ENV PYTHON_TOX_UV_VERSION=1.7.0
3132
RUN set -x \
3233
&& pip3 install tox==${PYTHON_TOX_VERSION} tox-uv==${PYTHON_TOX_UV_VERSION}\
3334
&& true

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ dev:
2323
.venv/bin/pip3 install -r dev-requirements.txt
2424
.venv/bin/pre-commit install
2525

26+
.PHONY: lint
27+
lint:
28+
.venv/bin/ruff check .
29+
30+
.PHONY: lint-fix
31+
lint-fix:
32+
.venv/bin/ruff check . --fix
33+
2634
.PHONY: format
2735
format:
2836
.venv/bin/ruff format --check .

gooddata-flight-server/gooddata_flight_server/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
from gooddata_flight_server.errors.error_code import ErrorCode
1010
from gooddata_flight_server.errors.error_info import ErrorInfo, RetryInfo
1111
from gooddata_flight_server.flexfun.flex_fun import FlexFun
12+
from gooddata_flight_server.flexfun.flex_fun_execution_context import (
13+
ExecutionContext,
14+
ExecutionRequest,
15+
)
1216
from gooddata_flight_server.health.server_health_monitor import ModuleHealthStatus, ServerHealthMonitor
1317
from gooddata_flight_server.server.auth.auth_middleware import TokenAuthMiddleware
1418
from gooddata_flight_server.server.auth.token_verifier import TokenVerificationStrategy
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# (C) 2024 GoodData Corporation
2+
from dataclasses import dataclass
3+
from typing import Optional
4+
5+
from gooddata_sdk import Attribute, ComputeToSdkConverter, Filter, Metric
6+
7+
8+
@dataclass
9+
class ExecutionRequest:
10+
"""
11+
Information about the execution request that is sent to the FlexFun.
12+
"""
13+
14+
attributes: list[Attribute]
15+
"""
16+
All the attributes that are part of the execution request.
17+
"""
18+
19+
metrics: list[Metric]
20+
"""
21+
All the metrics that are part of the execution request.
22+
"""
23+
24+
filters: list[Filter]
25+
"""
26+
All the filters that are part of the execution request.
27+
"""
28+
29+
@staticmethod
30+
def from_dict(d: dict) -> "ExecutionRequest":
31+
"""
32+
Create ExecutionRequest from a dictionary.
33+
:param d: the dictionary to parse
34+
"""
35+
return ExecutionRequest(
36+
attributes=[ComputeToSdkConverter.convert_attribute(a) for a in d.get("attributes", [])],
37+
metrics=[ComputeToSdkConverter.convert_metric(m) for m in d.get("measures", [])],
38+
filters=[ComputeToSdkConverter.convert_filter(f) for f in d.get("filters", [])],
39+
)
40+
41+
42+
@dataclass
43+
class ExecutionContext:
44+
"""
45+
Execution context of the FlexFun
46+
"""
47+
48+
organization_id: str
49+
"""
50+
The ID of the organization that the FlexFun is executed in.
51+
"""
52+
53+
workspace_id: str
54+
"""
55+
The ID of the workspace that the FlexFun is executed in.
56+
"""
57+
58+
user_id: str
59+
"""
60+
The ID of the user that invoked the FlexFun.
61+
"""
62+
63+
timestamp: Optional[str]
64+
"""
65+
The timestamp of the execution used as "now" in date filters.
66+
For example 2020-06-03T10:15:30+01:00.
67+
"""
68+
69+
timezone: Optional[str]
70+
"""
71+
The timezone of the execution.
72+
"""
73+
74+
execution_request: ExecutionRequest
75+
"""
76+
The execution request that the FlexFun should process.
77+
"""
78+
79+
@staticmethod
80+
def from_dict(d: dict) -> Optional["ExecutionContext"]:
81+
"""
82+
Create ExecutionContext from a dictionary.
83+
:param d: the dictionary to parse
84+
"""
85+
if not d:
86+
return None
87+
return ExecutionContext(
88+
organization_id=d["organization_id"],
89+
workspace_id=d["workspace_id"],
90+
user_id=d["user_id"],
91+
timestamp=d.get("timestamp"),
92+
timezone=d.get("timezone"),
93+
execution_request=ExecutionRequest.from_dict(d["execution_request"]),
94+
)
95+
96+
@staticmethod
97+
def from_parameters(parameters: dict) -> Optional["ExecutionContext"]:
98+
"""
99+
Create ExecutionContext from FlexFun parameters.
100+
:param parameters: the parameters dictionary of the FlexFun invocation
101+
:return: None if the parameters do not contain the execution context, otherwise the execution context
102+
"""
103+
return (
104+
ExecutionContext.from_dict(parameters["execution_context"]) if "execution_context" in parameters else None
105+
)

gooddata-flight-server/setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
REQUIRES = [
1010
"dynaconf>=3.1.11,<4.0.0",
11+
"gooddata-sdk~=1.24.0",
1112
"opentelemetry-api>=1.24.0,<=2.0.0",
1213
"opentelemetry-sdk>=1.24.0,<=2.0.0",
1314
"orjson>=3.8.5,<4.0.0",

gooddata-flight-server/tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package = wheel
77
wheel_build_env = .pkg
88
deps =
99
-r{toxinidir}/test-requirements.txt
10+
-e../gooddata-sdk
1011
-e../tests-support
1112
setenv=
1213
PYTHONDONTWRITEBYTECODE=1

gooddata-sdk/gooddata_sdk/catalog/data_source/service.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ def generate_logical_model(
326326
def scan_pdm_and_generate_logical_model(
327327
self,
328328
data_source_id: str,
329-
generate_ldm_request: CatalogGenerateLdmRequest = CatalogGenerateLdmRequest(separator="__", wdf_prefix="wdf"),
329+
generate_ldm_request: Optional[CatalogGenerateLdmRequest] = None,
330330
scan_request: CatalogScanModelRequest = CatalogScanModelRequest(),
331331
report_warnings: bool = False,
332332
) -> tuple[CatalogDeclarativeModel, CatalogScanResultPdm]:
@@ -351,6 +351,9 @@ def scan_pdm_and_generate_logical_model(
351351
An instance of CatalogScanResultPdm.
352352
Containing pdm itself and a list of warnings that occurred during scanning.
353353
"""
354+
if not generate_ldm_request:
355+
generate_ldm_request = CatalogGenerateLdmRequest(separator="__", wdf_prefix="wdf")
356+
354357
scan_result = self.scan_data_source(data_source_id, scan_request, report_warnings)
355358
if generate_ldm_request.pdm and generate_ldm_request.pdm.tables:
356359
generate_ldm_request.pdm.tables.extend(scan_result.pdm.tables)

gooddata-sdk/gooddata_sdk/catalog/export/request.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def __attrs_post_init__(self) -> None:
7575
supported_formats = ["CSV", "XLSX", "HTML", "PDF"]
7676
if self.format not in supported_formats:
7777
raise ValueError(
78-
f"format '{self.format}' is not presented " f"in supported formats {','.join(supported_formats)}"
78+
f"format '{self.format}' is not presented in supported formats {','.join(supported_formats)}"
7979
)
8080

8181
@staticmethod

0 commit comments

Comments
 (0)