Example #1
0
    def get_default() -> Optional[MLEnvironment]:
        """
        Get the MLEnvironment use the default MLEnvironmentId.

        :return: the default MLEnvironment.
        """
        with MLEnvironmentFactory._lock:
            if MLEnvironmentFactory._map[
                    MLEnvironmentFactory._default_ml_environment_id] is None:
                j_ml_env = get_gateway().\
                    jvm.org.apache.flink.ml.common.MLEnvironmentFactory.getDefault()
                ml_env = MLEnvironment(
                    ExecutionEnvironment(j_ml_env.getExecutionEnvironment()),
                    StreamExecutionEnvironment(
                        j_ml_env.getStreamExecutionEnvironment()),
                    BatchTableEnvironment(j_ml_env.getBatchTableEnvironment()),
                    StreamTableEnvironment(
                        j_ml_env.getStreamTableEnvironment()))
                MLEnvironmentFactory._map[
                    MLEnvironmentFactory._default_ml_environment_id] = ml_env

            return MLEnvironmentFactory._map[
                MLEnvironmentFactory._default_ml_environment_id]
Example #2
0
File: env.py Project: alibaba/Alink
def setup_pyflink_env(gateway: JavaGateway, j_benv: JavaObject, j_senv: JavaObject) \
        -> Tuple[ExecutionEnvironment, BatchTableEnvironment, StreamExecutionEnvironment, StreamTableEnvironment]:
    """
    Setup Py4J for PyFlink, and create Python instances environments.
    """
    from pyflink.dataset import ExecutionEnvironment
    from pyflink.datastream import StreamExecutionEnvironment
    from pyflink.table import BatchTableEnvironment, StreamTableEnvironment
    import pyflink

    # noinspection PyUnresolvedReferences
    pyflink.java_gateway._gateway = gateway
    # noinspection PyUnresolvedReferences
    pyflink.java_gateway.import_flink_view(gateway)

    benv = ExecutionEnvironment(j_benv)
    senv = StreamExecutionEnvironment(j_senv)
    # noinspection PyDeprecation
    btenv = BatchTableEnvironment.create(benv)

    # noinspection PyDeprecation
    stenv_settings = EnvironmentSettings.new_instance().use_old_planner().in_streaming_mode().build()
    stenv = StreamTableEnvironment.create(senv, environment_settings=stenv_settings)
    return benv, btenv, senv, stenv
Example #3
0
 def exec_env(self):
     """
     :return: The stream execution environment of this table environment.
     """
     return ExecutionEnvironment(self._j_tenv.execEnv())