コード例 #1
0
    def __init__(self, use_spark=False):
        self._stdout = StringIO()
        self._is_exception = self.NO_EXCEPTION
        self._init_executer()

        import brightics.brightics_data_api as data_api
        import brightics.common.data.utils as data_util
        from brightics.common.utils import check_required_parameters

        self._globals = {
            'make_data_path_from_key': data_util.make_data_path_from_key,
            'get_data_info': data_api.get_data_info,
            'get_data_status': data_api.get_data_status,
            'get_data': data_api.get_data,
            'list_status': data_api.list_status,
            'view_data': data_api.view_data,
            'view_schema': data_api.view_schema,
            'write_data': data_api.write_data,
            'delete_data': data_api.delete_data,
            'put_data': data_api.put_data,
            'read_parquet': data_api.read_parquet,
            'read_redis': data_api.read_redis,
            'check_required_parameters': check_required_parameters
        }

        if use_spark:
            sc, sparkSession, sqlContext = brtc_java_gateway.init_spark_context(
            )

            self._globals['sc'] = sc
            self._globals['spark'] = sparkSession
            self._globals['sqlContext'] = sqlContext

        signal.signal(signal.SIGINT, self._interrupt_handler)
コード例 #2
0
if __name__ == '__main__':
    """
    argv[1] : use spark context
    argv[2] : gateway server port
    """

    use_spark_context = True if sys.argv[1] == 'true' else False
    gateway_port = int(sys.argv[2]) if len(sys.argv) > 2 else None
    try:
        brtc_java_gateway.start(gateway_port)

        brtc_java_gateway.logger.info(
            "[Python] Start to initialize BrighticsPythonRunner")
        if use_spark_context:
            sc, spark, sqlContext = brtc_java_gateway.init_spark_context()

        runner = BrighticsPythonRunner()

        runner.run("from brightics.common import *")
        runner.run("from brightics.function import *")

        brtc_java_gateway.logger.info(
            "[Python] Finished to initialize BrighticsPythonRunner")

        brtc_java_gateway.notify_python_process_started()
    except Exception as err:
        try:
            brtc_java_gateway.logger.error("[Python] {0}".format(err))
        finally:
            sys.exit(1)