|
1 | 1 | import abc |
| 2 | +import enum |
2 | 3 | import typing |
3 | 4 |
|
4 | | -from .common_utils import IToProto |
| 5 | +from .common_utils import IFromProto, IToProto |
5 | 6 |
|
6 | 7 | # Workaround for good IDE and universal for runtime |
7 | 8 | if typing.TYPE_CHECKING: |
8 | | - from ..v4.protos import ydb_query_pb2 |
| 9 | + from ..v4.protos import ydb_query_pb2, ydb_formats_pb2 |
9 | 10 | else: |
10 | | - from ..common.protos import ydb_query_pb2 |
| 11 | + from ..common.protos import ydb_query_pb2, ydb_formats_pb2 |
11 | 12 |
|
12 | 13 |
|
13 | 14 | class BaseQueryTxMode(IToProto): |
@@ -93,3 +94,51 @@ def name(self): |
93 | 94 |
|
94 | 95 | def to_proto(self) -> ydb_query_pb2.StaleModeSettings: |
95 | 96 | return ydb_query_pb2.StaleModeSettings() |
| 97 | + |
| 98 | + |
| 99 | +class ArrowCompressionCodecType(enum.IntEnum): |
| 100 | + UNSPECIFIED = 0 |
| 101 | + NONE = 1 |
| 102 | + ZSTD = 2 |
| 103 | + LZ4_FRAME = 3 |
| 104 | + |
| 105 | + |
| 106 | +class ArrowCompressionCodec(IToProto): |
| 107 | + """Compression codec for Arrow format result sets.""" |
| 108 | + |
| 109 | + def __init__( |
| 110 | + self, codec_type: typing.Optional[ArrowCompressionCodecType] = None, level: typing.Optional[int] = None |
| 111 | + ): |
| 112 | + self.type = codec_type if codec_type is not None else ArrowCompressionCodecType.UNSPECIFIED |
| 113 | + self.level = level |
| 114 | + |
| 115 | + def to_proto(self): |
| 116 | + return ydb_formats_pb2.ArrowFormatSettings.CompressionCodec(type=self.type, level=self.level) |
| 117 | + |
| 118 | + |
| 119 | +class ArrowFormatSettings(IToProto): |
| 120 | + """Settings for Arrow format result sets.""" |
| 121 | + |
| 122 | + def __init__(self, compression_codec: typing.Optional[ArrowCompressionCodec] = None): |
| 123 | + self.compression_codec = compression_codec |
| 124 | + |
| 125 | + def to_proto(self): |
| 126 | + settings = ydb_formats_pb2.ArrowFormatSettings() |
| 127 | + if self.compression_codec is not None: |
| 128 | + codec_proto = self.compression_codec.to_proto() |
| 129 | + settings.compression_codec.CopyFrom(codec_proto) |
| 130 | + return settings |
| 131 | + |
| 132 | + |
| 133 | +class ArrowFormatMeta(IFromProto): |
| 134 | + """Metadata for Arrow format result sets containing the schema.""" |
| 135 | + |
| 136 | + def __init__(self, schema: bytes): |
| 137 | + self.schema = schema |
| 138 | + |
| 139 | + @classmethod |
| 140 | + def from_proto(cls, proto_message): |
| 141 | + return cls(schema=proto_message.schema) |
| 142 | + |
| 143 | + def __repr__(self): |
| 144 | + return f"ArrowFormatMeta(schema_size={len(self.schema)} bytes)" |
0 commit comments