def pickled_bytes_to_python_converter(data, field_type: DataType): if isinstance(field_type, RowType): row_kind = RowKind( int.from_bytes(data[0], byteorder='big', signed=False)) data = zip(list(data[1:]), field_type.field_types()) fields = [] for d, d_type in data: fields.append(pickled_bytes_to_python_converter(d, d_type)) result_row = Row(fields) result_row.set_row_kind(row_kind) return result_row else: data = pickle.loads(data) if isinstance(field_type, TimeType): seconds, microseconds = divmod(data, 10**6) minutes, seconds = divmod(seconds, 60) hours, minutes = divmod(minutes, 60) return datetime.time(hours, minutes, seconds, microseconds) elif isinstance(field_type, DateType): return field_type.from_sql_type(data) elif isinstance(field_type, TimestampType): return field_type.from_sql_type(int(data.timestamp() * 10**6)) elif isinstance(field_type, MapType): key_type = field_type.key_type value_type = field_type.value_type zip_kv = zip(data[0], data[1]) return dict((pickled_bytes_to_python_converter(k, key_type), pickled_bytes_to_python_converter(v, value_type)) for k, v in zip_kv) elif isinstance(field_type, FloatType): return field_type.from_sql_type(ast.literal_eval(data)) elif isinstance(field_type, ArrayType): element_type = field_type.element_type elements = [] for element_bytes in data: elements.append( pickled_bytes_to_python_converter(element_bytes, element_type)) return elements else: return field_type.from_sql_type(data)
def test_not_null(self): t = DataType(nullable=True) self.assertEqual(t._nullable, True) t_notnull = t.not_null() self.assertEqual(t_notnull._nullable, False)
def test_nullable(self): t = DataType(nullable=False) self.assertEqual(t._nullable, False) t_nullable = t.nullable() self.assertEqual(t_nullable._nullable, True)