16from datetime
import date, datetime, time
17from decimal
import Decimal
18from typing
import Any, List, Optional, Type, TypeVar, Union, overload
20from nebulagraph_python.decoder.data_types
import ColumnType
33logger = logging.getLogger(__name__)
36T = TypeVar(
"T", bound=TargetType)
40 __slots__ = (
"value",
"data_type")
42 def __init__(self, value: Any, data_type: ColumnType):
47 """If the value is null
51 bool: true if value is null
54 return self.
value is None
57 """Check if the Value is Boolean type
61 bool: true if Value's type is COLUMN_TYPE_BOOL
67 """Check if the Value is Long type
71 bool: true if Value's type is COLUMN_TYPE_UINT64 or COLUMN_TYPE_INT64
74 return self.
data_type in [ColumnType.UINT64, ColumnType.INT64]
77 """Check if the Value is Int type
81 bool: true if Value's type is COLUMN_TYPE_UINT8 or COLUMN_TYPE_INT8 or COLUMN_TYPE_UINT16
82 or COLUMN_TYPE_INT16 or COLUMN_TYPE_UINT32 or COLUMN_TYPE_INT32
95 """Check if the Value is Float type
99 bool: true if Value's type is COLUMN_TYPE_FLOAT32
102 return self.
data_type == ColumnType.FLOAT32
105 """Check if the Value is Double type
109 bool: true if Value's type is COLUMN_TYPE_FLOAT64
112 return self.
data_type == ColumnType.FLOAT64
115 """Check if the Value is String type.
119 bool: true if Value's type is COLUMN_TYPE_STRING
122 return self.
data_type == ColumnType.STRING
125 """Check if the Value is List type.
129 bool: true if Value's type is COLUMN_TYPE_LIST
135 """Check if the Value is Node type
139 bool: true if Value's type is COLUMN_TYPE_NODE
145 """Check if the Value is Edge type
149 bool: true if Value's type is COLUMN_TYPE_EDGE
155 """Check if the Value is Local Time type.
159 bool: true if Value's type is COLUMN_TYPE_LOCALTIME
162 return self.
data_type == ColumnType.LOCALTIME
165 """Check if the Value is Zoned Time type
169 bool: true if Value's type is COLUMN_TYPE_ZONEDTIME
172 return self.
data_type == ColumnType.ZONEDTIME
175 """Check if the Value is Local Datetime type
179 bool: true if Value's type is COLUMN_TYPE_LOCALDATETIME
182 return self.
data_type == ColumnType.LOCALDATETIME
185 """Check if the Value is Zoned Datetime type
189 bool: true if Value's type is COLUMN_TYPE_ZONEDDATETIME
192 return self.
data_type == ColumnType.ZONEDDATETIME
195 """Check if the Value is Date type
199 bool: true if Value's type is COLUMN_TYPE_DATE
205 """Check if the Value is Record type
209 bool: true if Value's type is COLUMN_TYPE_RECORD
212 return self.
data_type == ColumnType.RECORD
215 """Check if the Value is Duration type
219 bool: true if Value's type is COLUMN_TYPE_DURATION
222 return self.
data_type == ColumnType.DURATION
225 """Check if the Value is Path type
229 bool: true if Value's type is COLUMN_TYPE_PATH
235 """Check if the Value is Decimal type
239 bool: true if Value's type is COLUMN_TYPE_DECIMAL
242 return self.
data_type == ColumnType.DECIMAL
271 def as_local_time(self):
274 def as_zoned_time(self):
280 def as_local_datetime(self):
283 def as_zoned_datetime(self):
286 def as_duration(self):
295 def as_decimal(self):
298 def as_embedding_vector(self):
307 def cast(self, target_type: Type[T]) -> T:
308 """Get self.value, with target_type check"""
313 target_type: Optional[Type[T]] =
None,
314 ) -> Union[T, TargetType]:
315 if self.
value is None and target_type
is None:
317 target_type = ColumnToPy[self.
data_type]
if target_type
is None else target_type
319 if target_type
is not None:
320 if isinstance(self.
value, target_type):
324 f
"Cannot cast {type(self.value)} to {target_type}. ColumnType and value:",
330 """Convert the wrapped value to primitive Python types recursively.
332 For basic types, uses cast()
333 For composite types (Path, Node, Edge), calls cast_primitive()
334 For containers (Map, List, Record), recursively calls cast_primitive() on elements
339 if isinstance(outer, CompositeDataObject):
340 return outer.cast_primitive()
343 if isinstance(outer, list):
345 for i, v
in enumerate(outer):
346 if isinstance(v, ValueWrapper):
347 ans.append(v.cast_primitive())
350 f
"Cannot cast list, where list[{i}] have type {type(v)}, not ValueWrapper. list[{i}]: ",
357 def __eq__(self, other):
358 if not isinstance(other, ValueWrapper):
360 return self.
value == other.value
and self.
data_type == other.data_type
362 def __hash__(self) -> int:
367 __slots__ = (
"values",)
369 def __init__(self, values: Optional[List[ValueWrapper]] =
None):
370 self.
values = values
if values
is not None else []
373 """Append one value into row.
377 value (ValueWrapper): one value of the row
383 """Get the values of this row.
387 List[ValueWrapper]: list of values in this row
list[ValueWrapper] get_values(self)
add_value(self, ValueWrapper value)
T cast(self, Type[T] target_type)
bool is_local_datetime(self)
Union[T, TargetType] cast(self, Optional[Type[T]] target_type=None)
bool is_zoned_datetime(self)