Types¶
YadsType
¶
Bases: ABC
Abstract base class for all yads data types.
All type definitions in yads inherit from this base class, providing a consistent interface for type representation and conversion across different target systems.
Source code in src/yads/types.py
68 69 70 71 72 73 74 75 76 77 | |
String
dataclass
¶
Bases: YadsType
Variable-length string type with optional maximum length constraint.
Represents text data. The length parameter specifies the maximum number
of characters when applicable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
length
|
int | None
|
Maximum number of characters. If None, represents unlimited length. |
None
|
Raises:
| Type | Description |
|---|---|
TypeDefinitionError
|
If length is not a positive integer. |
Source code in src/yads/types.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | |
Integer
dataclass
¶
Bases: YadsType
Integer type with optional bit-width and signedness specification.
Represents whole numbers. Bit-width controls representable range; signed
controls whether the integer is signed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bits
|
int | None
|
Number of bits for the integer. Must be 8, 16, 32, or 64. If None, uses the default integer type for the target system. |
None
|
signed
|
bool
|
Whether the integer is signed. Defaults to True. |
True
|
Raises:
| Type | Description |
|---|---|
TypeDefinitionError
|
If |
Source code in src/yads/types.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |
Float
dataclass
¶
Bases: YadsType
IEEE floating-point number type with optional precision specification.
Represents approximate numeric values with fractional components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bits
|
int | None
|
Number of bits for the float. Must be 16, 32, or 64. 16-bit corresponds to half precision, 32-bit to single precision, and 64-bit to double precision. If None, uses the default float type for the target system. |
None
|
Raises:
| Type | Description |
|---|---|
TypeDefinitionError
|
If bits is not 16, 32, or 64. |
Source code in src/yads/types.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | |
Decimal
dataclass
¶
Bases: YadsType
Fixed-precision decimal type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
precision
|
int | None
|
Total number of digits (before and after decimal point). |
None
|
scale
|
int | None
|
Number of digits after the decimal point. Can be negative to indicate rounding to the left of the decimal point. |
None
|
bits
|
int | None
|
Decimal arithmetic/storage width. One of |
None
|
Both precision and scale must be specified together, or both omitted for a default decimal type.
Raises:
| Type | Description |
|---|---|
TypeDefinitionError
|
If only one of precision/scale is specified, or if values are invalid. |
Source code in src/yads/types.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | |
Boolean
dataclass
¶
Bases: YadsType
Boolean type representing true/false values.
Source code in src/yads/types.py
230 231 232 | |
Binary
dataclass
¶
Bases: YadsType
Binary data type for storing byte sequences.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
length
|
int | None
|
Optional maximum number of bytes. If None, represents variable-length binary. |
None
|
Raises:
| Type | Description |
|---|---|
TypeDefinitionError
|
If |
Source code in src/yads/types.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
Date
dataclass
¶
Bases: YadsType
Calendar date type representing year, month, and day.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bits
|
int | None
|
Storage width for logical date. One of |
None
|
Source code in src/yads/types.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | |
TimeUnit
¶
Bases: str, Enum
Granularity for logical time and timestamps.
Order reflects increasing coarseness: ns < us < ms < s.
Source code in src/yads/types.py
281 282 283 284 285 286 287 288 289 290 | |
Time
dataclass
¶
Bases: YadsType
Time-of-day type with fractional precision.
Represents a wall-clock time without a date component. Precision is expressed via a time unit granularity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
TimeUnit | None
|
Smallest time unit for values. One of |
MS
|
bits
|
int | None
|
Storage width for logical time. One of |
None
|
Raises:
| Type | Description |
|---|---|
TypeDefinitionError
|
If |
Source code in src/yads/types.py
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 | |
Timestamp
dataclass
¶
Bases: YadsType
Timestamp type with implicit timezone awareness.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
TimeUnit | None
|
Smallest time unit for values. One of |
NS
|
Source code in src/yads/types.py
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 | |
TimestampTZ
dataclass
¶
Bases: YadsType
Timezone-aware timestamp type with explicit timezone information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
TimeUnit | None
|
Smallest time unit for values. One of |
NS
|
tz
|
str
|
IANA timezone name to interpret values, for example |
'UTC'
|
Source code in src/yads/types.py
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 | |
TimestampLTZ
dataclass
¶
Bases: YadsType
Timezone-aware timestamp type with session-local timezone semantics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
TimeUnit | None
|
Smallest time unit for values. One of |
NS
|
Source code in src/yads/types.py
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 | |
TimestampNTZ
dataclass
¶
Bases: YadsType
Timestamp type with explicit timezone unawareness.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
TimeUnit | None
|
Smallest time unit for values. One of |
NS
|
Source code in src/yads/types.py
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 | |
Duration
dataclass
¶
Bases: YadsType
Logical duration type with fractional precision.
Represents an elapsed amount of time. Precision is expressed via a unit granularity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
TimeUnit | None
|
Smallest time unit for values. One of |
NS
|
Raises:
| Type | Description |
|---|---|
TypeDefinitionError
|
If |
Source code in src/yads/types.py
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 | |
IntervalTimeUnit
¶
Bases: str, Enum
Time unit enumeration for interval types.
Defines the valid time units that can be used in interval type definitions. Units are categorized into Year-Month and Day-Time groups for SQL compatibility.
Source code in src/yads/types.py
485 486 487 488 489 490 491 492 493 494 495 496 497 498 | |
Interval
dataclass
¶
Bases: YadsType
Time interval type representing a duration between two time points. The interval is defined by start and optional end time units.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interval_start
|
IntervalTimeUnit
|
The starting (most significant) time unit. |
required |
interval_end
|
IntervalTimeUnit | None
|
The ending (least significant) time unit. If None, represents a single-unit interval. |
None
|
The start and end units must belong to the same category
- Year-Month:
YEAR,MONTH - Day-Time:
DAY,HOUR,MINUTE,SECOND
Raises:
| Type | Description |
|---|---|
TypeDefinitionError
|
If start and end units are from different categories, or if start is less significant than end. |
Source code in src/yads/types.py
501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 | |
Array
dataclass
¶
Bases: YadsType
Array type containing elements of a homogeneous type.
Represents ordered collections where all elements share the same type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
element
|
YadsType
|
The type of elements contained in the array. |
required |
size
|
int | None
|
Optional maximum size for fixed-size arrays. If None, the array is variable-length. |
None
|
Example
# Array of strings
Array(element=String())
# Fixed-size array of integers
Array(element=Integer(bits=32), size=10)
# Nested array (array of arrays)
Array(element=Array(element=String()))
Source code in src/yads/types.py
582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 | |
Struct
dataclass
¶
Bases: YadsType
Structured type containing named fields of potentially different types.
Represents complex objects with named fields.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fields
|
list[Field]
|
List of Field objects defining the structure's schema. |
required |
Example
from yads.spec import Field
# Address structure
address_type = Struct(fields=[
Field(name="street", type=String()),
Field(name="city", type=String()),
Field(name="postal_code", type=String(length=10))
])
# Nested structures
person_type = Struct(fields=[
Field(name="name", type=String()),
Field(name="age", type=Integer()),
Field(name="address", type=address_type)
])
Source code in src/yads/types.py
615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 | |
Map
dataclass
¶
Bases: YadsType
Key-value mapping type with homogeneous key and value types.
Represents associative arrays or dictionaries where all keys share one type and all values share another type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
YadsType
|
The type of all keys in the map. |
required |
value
|
YadsType
|
The type of all values in the map. |
required |
keys_sorted
|
bool
|
Whether the map has sorted keys. Defaults to False. |
False
|
Example
# String-to-string mapping
Map(key=String(), value=String())
# String-to-integer mapping
Map(key=String(), value=Integer())
# Complex value types
Map(key=String(), value=Array(element=String()))
Source code in src/yads/types.py
652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 | |
JSON
dataclass
¶
Bases: YadsType
JSON document type for semi-structured data.
Source code in src/yads/types.py
687 688 689 | |
Geometry
dataclass
¶
Bases: YadsType
Geometric object type with optional SRID.
Represents planar geometry values such as points, linestrings, and polygons.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
srid
|
int | str | None
|
Spatial reference identifier, for example an integer code or
the string |
None
|
Source code in src/yads/types.py
692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 | |
Geography
dataclass
¶
Bases: YadsType
Geographic object type with optional SRID.
Represents geographic values in a spherical coordinate system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
srid
|
int | str | None
|
Spatial reference identifier, e.g., integer code or the string
|
None
|
Source code in src/yads/types.py
711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 | |
UUID
dataclass
¶
Bases: YadsType
Universally Unique Identifier type. Represents 128-bit UUID values.
Source code in src/yads/types.py
730 731 732 | |
Void
dataclass
¶
Bases: YadsType
Represents a NULL or VOID type.
Source code in src/yads/types.py
735 736 737 | |
Variant
dataclass
¶
Bases: YadsType
Variant type representing a union of potentially different types.
Source code in src/yads/types.py
740 741 742 | |
Tensor
dataclass
¶
Bases: YadsType
Multi-dimensional tensors with fixed shape and a canonical element base type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
element
|
YadsType
|
The type of elements in the tensor. |
required |
shape
|
tuple[int, ...]
|
Tuple of positive integers defining tensor dimensions. |
required |
Raises:
| Type | Description |
|---|---|
TypeDefinitionError
|
If shape is empty or contains non-positive integers. |
Example
# 2D tensor of integers
Tensor(element=Integer(), shape=[10, 20])
# 3D tensor of floats
Tensor(element=Float(bits=32), shape=[5, 10, 15])
# Use in field definition
Field(name="image_data", type=Tensor(element=Float(bits=32), shape=[224, 224, 3]))
Source code in src/yads/types.py
745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 | |