feldera 0.69.0__py3-none-any.whl → 0.189.0__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 feldera might be problematic. Click here for more details.

@@ -1,23 +1,28 @@
1
- from feldera.rest.feldera_client import FelderaClient
2
- from feldera.rest.pipeline import Pipeline as InnerPipeline
1
+ import os
2
+ from typing import Optional
3
+
4
+ from feldera.enums import CompilationProfile, PipelineFieldSelector
3
5
  from feldera.pipeline import Pipeline
4
- from feldera.enums import CompilationProfile
5
- from feldera.runtime_config import RuntimeConfig, Resources
6
6
  from feldera.rest.errors import FelderaAPIError
7
+ from feldera.rest.feldera_client import FelderaClient
8
+ from feldera.rest.pipeline import Pipeline as InnerPipeline
9
+ from feldera.runtime_config import RuntimeConfig
7
10
 
8
11
 
9
12
  class PipelineBuilder:
10
13
  """
11
14
  A builder for creating a Feldera Pipeline.
12
15
 
13
- :param client: The `.FelderaClient` instance
16
+ :param client: The :class:`.FelderaClient` instance
14
17
  :param name: The name of the pipeline
15
18
  :param description: The description of the pipeline
16
19
  :param sql: The SQL code of the pipeline
17
20
  :param udf_rust: Rust code for UDFs
18
21
  :param udf_toml: Rust dependencies required by UDFs (in the TOML format)
19
- :param compilation_profile: The compilation profile to use
20
- :param runtime_config: The runtime config to use
22
+ :param compilation_profile: The :class:`.CompilationProfile` to use
23
+ :param runtime_config: The :class:`.RuntimeConfig` to use. Enables
24
+ configuring the runtime behavior of the pipeline such as:
25
+ fault tolerance, storage and :class:`.Resources`
21
26
  """
22
27
 
23
28
  def __init__(
@@ -29,7 +34,8 @@ class PipelineBuilder:
29
34
  udf_toml: str = "",
30
35
  description: str = "",
31
36
  compilation_profile: CompilationProfile = CompilationProfile.OPTIMIZED,
32
- runtime_config: RuntimeConfig = RuntimeConfig(resources=Resources()),
37
+ runtime_config: RuntimeConfig = RuntimeConfig.default(),
38
+ runtime_version: Optional[str] = None,
33
39
  ):
34
40
  self.client: FelderaClient = client
35
41
  self.name: str | None = name
@@ -39,19 +45,30 @@ class PipelineBuilder:
39
45
  self.udf_toml: str = udf_toml
40
46
  self.compilation_profile: CompilationProfile = compilation_profile
41
47
  self.runtime_config: RuntimeConfig = runtime_config
48
+ self.runtime_version: Optional[str] = os.environ.get(
49
+ "FELDERA_RUNTIME_VERSION", runtime_version
50
+ )
42
51
 
43
- def create(self) -> Pipeline:
52
+ def create(self, wait: bool = True) -> Pipeline:
44
53
  """
45
54
  Create the pipeline if it does not exist.
46
55
 
56
+ :param wait: Whether to wait for the pipeline to be created. True by default
47
57
  :return: The created pipeline
48
58
  """
49
59
 
50
60
  if self.name is None or self.sql is None:
51
61
  raise ValueError("Name and SQL are required to create a pipeline")
52
62
 
53
- if self.client.get_pipeline(self.name) is not None:
54
- raise RuntimeError(f"Pipeline with name {self.name} already exists")
63
+ try:
64
+ if (
65
+ self.client.get_pipeline(self.name, PipelineFieldSelector.STATUS)
66
+ is not None
67
+ ):
68
+ raise RuntimeError(f"Pipeline with name {self.name} already exists")
69
+ except FelderaAPIError as err:
70
+ if err.error_code != "UnknownPipelineName":
71
+ raise err
55
72
 
56
73
  inner = InnerPipeline(
57
74
  self.name,
@@ -61,21 +78,25 @@ class PipelineBuilder:
61
78
  udf_toml=self.udf_toml,
62
79
  program_config={
63
80
  "profile": self.compilation_profile.value,
81
+ "runtime_version": self.runtime_version,
64
82
  },
65
- runtime_config=self.runtime_config.__dict__,
83
+ runtime_config=self.runtime_config.to_dict(),
66
84
  )
67
85
 
68
- inner = self.client.create_pipeline(inner)
86
+ inner = self.client.create_pipeline(inner, wait=wait)
69
87
  pipeline = Pipeline(self.client)
70
88
  pipeline._inner = inner
71
89
 
72
90
  return pipeline
73
91
 
74
- def create_or_replace(self) -> Pipeline:
92
+ def create_or_replace(self, wait: bool = True) -> Pipeline:
75
93
  """
76
94
  Creates a pipeline if it does not exist and replaces it if it exists.
77
95
 
78
96
  If the pipeline exists and is running, it will be stopped and replaced.
97
+
98
+ :param wait: Whether to wait for the pipeline to be created. True by default
99
+ :return: The created pipeline
79
100
  """
80
101
 
81
102
  if self.name is None or self.sql is None:
@@ -83,7 +104,10 @@ class PipelineBuilder:
83
104
 
84
105
  try:
85
106
  # shutdown the pipeline if it exists and is running
86
- self.client.shutdown_pipeline(self.name)
107
+ p = Pipeline.get(self.name, self.client)
108
+ p.stop(force=True)
109
+ p.clear_storage()
110
+
87
111
  except FelderaAPIError:
88
112
  # pipeline doesn't exist, no worries
89
113
  pass
@@ -96,13 +120,12 @@ class PipelineBuilder:
96
120
  udf_toml=self.udf_toml,
97
121
  program_config={
98
122
  "profile": self.compilation_profile.value,
123
+ "runtime_version": self.runtime_version,
99
124
  },
100
- runtime_config=dict(
101
- (k, v) for k, v in self.runtime_config.__dict__.items() if v is not None
102
- ),
125
+ runtime_config=self.runtime_config.to_dict(),
103
126
  )
104
127
 
105
- inner = self.client.create_or_update_pipeline(inner)
128
+ inner = self.client.create_or_update_pipeline(inner, wait=wait)
106
129
  pipeline = Pipeline(self.client)
107
130
  pipeline._inner = inner
108
131
 
@@ -0,0 +1,40 @@
1
+ import logging
2
+ import os
3
+
4
+
5
+ def determine_client_version() -> str:
6
+ from importlib.metadata import version, PackageNotFoundError
7
+
8
+ try:
9
+ version = version("feldera")
10
+ except PackageNotFoundError:
11
+ version = "unknown"
12
+
13
+ return version
14
+
15
+
16
+ def requests_verify_from_env() -> str | bool:
17
+ env_feldera_tls_insecure = os.environ.get("FELDERA_TLS_INSECURE")
18
+ FELDERA_HTTPS_TLS_CERT = os.environ.get("FELDERA_HTTPS_TLS_CERT")
19
+
20
+ if env_feldera_tls_insecure is not None and FELDERA_HTTPS_TLS_CERT is not None:
21
+ logging.warning(
22
+ "environment variables FELDERA_HTTPS_TLS_CERT and "
23
+ + "FELDERA_TLS_INSECURE both are set."
24
+ + "\nFELDERA_HTTPS_TLS_CERT takes priority."
25
+ )
26
+
27
+ if env_feldera_tls_insecure is None:
28
+ feldera_tls_insecure = False
29
+ else:
30
+ feldera_tls_insecure = env_feldera_tls_insecure.strip().lower() in (
31
+ "1",
32
+ "true",
33
+ "yes",
34
+ )
35
+
36
+ requests_verify = not feldera_tls_insecure
37
+ if FELDERA_HTTPS_TLS_CERT is not None:
38
+ requests_verify = FELDERA_HTTPS_TLS_CERT
39
+
40
+ return requests_verify