fdolce commented on code in PR #29088:
URL: https://github.com/apache/flink/pull/29088#discussion_r3958521326


##########
flink-python/pyflink/dataframe/context.py:
##########
@@ -95,9 +105,14 @@ def get_or_create_table_environment() -> TableEnvironment:
     global _global_table_environment
 
     if _global_table_environment is None:
+        from pyflink.dataframe._config import config
         from pyflink.datastream import StreamExecutionEnvironment
 
-        stream_environment = 
StreamExecutionEnvironment.get_execution_environment()
-        _global_table_environment = 
StreamTableEnvironment.create(stream_environment)
+        stream_environment = 
StreamExecutionEnvironment.get_execution_environment(
+            config._to_configuration()
+        )
+        t_env = StreamTableEnvironment.create(stream_environment)

Review Comment:
   Oh, nice, this looks way better. Still getting learning the pyflink api, so 
sometimes I miss things. Fixing this, and yes, we shouldn't need the apply_to 
at this point



##########
flink-python/pyflink/dataframe/_config.py:
##########
@@ -0,0 +1,151 @@
+################################################################################
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+# limitations under the License.
+################################################################################
+
+from typing import Dict, Optional
+
+from pyflink.common import Configuration
+from pyflink.table import TableEnvironment
+from pyflink.util.api_stability_decorators import PublicEvolving
+
+__all__ = [
+    "DataFrameConfig",
+    "config",
+]
+
+
+@PublicEvolving()
+class DataFrameConfig:
+    """
+    A unified entry point for Flink configuration in the DataFrame API.
+
+    Accepts any Flink configuration key and buffers the value, so 
configuration can be set
+    at any time -- even before an environment exists. Buffered values are used 
when
+    :func:`get_or_create_table_environment` creates the underlying
+    :class:`~pyflink.table.TableEnvironment`, so options that can only be 
chosen at creation
+    time, such as ``execution.runtime-mode``, take effect. An environment 
injected via
+    :func:`set_table_environment` receives the buffered values for every key 
it does not
+    already set explicitly. While an environment is active, values are also 
written through
+    to its configuration immediately.
+
+    Use the module-level singleton :data:`config` instead of instantiating 
this class.
+
+    Example::
+
+        >>> import pyflink.dataframe as pf
+        >>> _ = pf.config.set("parallelism.default", "4")
+        >>> pf.config.get("parallelism.default")
+        '4'
+
+    .. versionadded:: 2.4.0
+    """
+
+    def __init__(self: "DataFrameConfig"):
+        self._buffered: Dict[str, str] = {}
+
+    def set(self, key: str, value: str) -> "DataFrameConfig":
+        """
+        Sets a string-based value for the given string-based key.
+
+        The value is buffered and applied to the underlying environment once 
it is created
+        or injected; when an environment is already active, the value is 
applied to its
+        configuration immediately as well. A value the active environment 
rejects is not
+        buffered.
+
+        :param key: The configuration key.
+        :param value: The configuration value. It will be parsed by the 
framework on access.
+        :return: This object, to allow chaining of calls.
+        :raises TypeError: If ``key`` or ``value`` is not a string.
+
+        Example::
+
+            >>> import pyflink.dataframe as pf
+            >>> _ = pf.config.set("parallelism.default", "4") \\
+            ...              .set("execution.runtime-mode", "batch")
+
+        .. versionadded:: 2.4.0
+        """
+        if not isinstance(key, str):
+            raise TypeError("key must be a string")
+        if not isinstance(value, str):
+            raise TypeError("value must be a string")
+
+        from pyflink.dataframe.context import get_table_environment
+
+        t_env = get_table_environment()
+        if t_env is not None:

Review Comment:
   Yes, this was one of my main doubts about the design. Making the 
DataFrameConfig incompatible with a global environment and failing fast sounds 
a lot better to me, and also requiring the config to be set before the 
environment is created makes things easier, so yep, I'm going to change this.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to