def __init__(self, constant_value): j_type = constant_value[0] serializer = PickleSerializer() pickled_data = serializer.loads(constant_value[1:]) # the type set contains # TINYINT,SMALLINT,INTEGER,BIGINT,FLOAT,DOUBLE,DECIMAL,CHAR,VARCHAR,NULL,BOOLEAN # the pickled_data doesn't need to transfer to anther python object if j_type == 0: self._constant_value = pickled_data # the type is DATE elif j_type == 1: self._constant_value = \ datetime.date(year=1970, month=1, day=1) + datetime.timedelta(days=pickled_data) # the type is TIME elif j_type == 2: seconds, milliseconds = divmod(pickled_data, 1000) minutes, seconds = divmod(seconds, 60) hours, minutes = divmod(minutes, 60) self._constant_value = datetime.time(hours, minutes, seconds, milliseconds * 1000) # the type is TIMESTAMP elif j_type == 3: self._constant_value = \ datetime.datetime(year=1970, month=1, day=1, hour=0, minute=0, second=0) \ + datetime.timedelta(milliseconds=pickled_data) else: raise Exception("Unknown type %s, should never happen" % str(j_type))
def _parse_constant_value(constant_value) -> Tuple[str, Any]: j_type = constant_value[0] serializer = PickleSerializer() pickled_data = serializer.loads(constant_value[1:]) # the type set contains # TINYINT,SMALLINT,INTEGER,BIGINT,FLOAT,DOUBLE,DECIMAL,CHAR,VARCHAR,NULL,BOOLEAN # the pickled_data doesn't need to transfer to anther python object if j_type == 0: parsed_constant_value = pickled_data # the type is DATE elif j_type == 1: parsed_constant_value = \ datetime.date(year=1970, month=1, day=1) + datetime.timedelta(days=pickled_data) # the type is TIME elif j_type == 2: seconds, milliseconds = divmod(pickled_data, 1000) minutes, seconds = divmod(seconds, 60) hours, minutes = divmod(minutes, 60) parsed_constant_value = datetime.time(hours, minutes, seconds, milliseconds * 1000) # the type is TIMESTAMP elif j_type == 3: parsed_constant_value = \ datetime.datetime(year=1970, month=1, day=1, hour=0, minute=0, second=0) \ + datetime.timedelta(milliseconds=pickled_data) else: raise Exception("Unknown type %s, should never happen" % str(j_type)) def _next_constant_num(): global _constant_num _constant_num = _constant_num + 1 return _constant_num constant_value_name = 'c%s' % _next_constant_num() return constant_value_name, parsed_constant_value
def test_java_pickle_deserializer(self): temp_file = tempfile.NamedTemporaryFile(delete=False, dir=tempfile.mkdtemp()) serializer = PickleSerializer() data = [(1, 2), (3, 4), (5, 6), (7, 8)] try: serializer.dump_to_stream(data, temp_file) finally: temp_file.close() gateway = get_gateway() result = [tuple(int_pair) for int_pair in list(gateway.jvm.PythonBridgeUtils.readPythonObjects(temp_file.name, False))] self.assertEqual(result, [(1, 2), (3, 4), (5, 6), (7, 8)])
def __init__(self, j_stream_execution_environment, serializer=PickleSerializer()): self._j_stream_execution_environment = j_stream_execution_environment self.serializer = serializer
def __init__(self, j_tenv, serializer=PickleSerializer()): self._j_tenv = j_tenv self._serializer = serializer
def __init__(self, j_tenv, is_blink_planner, serializer=PickleSerializer()): self._j_tenv = j_tenv self._is_blink_planner = is_blink_planner self._serializer = serializer