-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathfun2.py
More file actions
41 lines (35 loc) · 1.08 KB
/
fun2.py
File metadata and controls
41 lines (35 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# (C) 2024 GoodData Corporation
from typing import Optional
import pyarrow
from gooddata_flexconnect.function.function import FlexConnectFunction
from gooddata_flight_server import ArrowData, ServerContext
_DATA: Optional[pyarrow.Table] = None
class _SimpleFun2(FlexConnectFunction):
Name = "SimpleFun2"
Schema = pyarrow.schema(
fields=[
pyarrow.field("col1", pyarrow.int64()),
pyarrow.field("col2", pyarrow.string()),
pyarrow.field("col3", pyarrow.bool_()),
]
)
def call(
self,
parameters: dict,
columns: tuple[str, ...],
headers: dict[str, list[str]],
) -> ArrowData:
assert _DATA is not None
return _DATA
@staticmethod
def on_load(ctx: ServerContext) -> None:
# on load emulates some kid of one-off setup
global _DATA
_DATA = pyarrow.table(
data={
"col1": [1, 2, 3],
"col2": ["a", "b", "c"],
"col3": [True, False, True],
},
schema=_SimpleFun2.Schema,
)