snapshot
ExpireSnapshots
¶
Bases: UpdateTableMetadata['ExpireSnapshots']
Expire snapshots by ID.
Use table.expire_snapshots().
Source code in pyiceberg/table/update/snapshot.py
1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 | |
by_id(snapshot_id)
¶
Expire a snapshot by its ID.
This will mark the snapshot for expiration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
snapshot_id
|
int
|
The ID of the snapshot to expire. |
required |
Returns: This for method chaining.
Source code in pyiceberg/table/update/snapshot.py
by_ids(snapshot_ids)
¶
Expire multiple snapshots by their IDs.
This will mark the snapshots for expiration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
snapshot_ids
|
List[int]
|
List of snapshot IDs to expire. |
required |
Returns: This for method chaining.
Source code in pyiceberg/table/update/snapshot.py
older_than(dt)
¶
Expire all unprotected snapshots with a timestamp older than a given value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dt
|
datetime
|
Only snapshots with datetime < this value will be expired. |
required |
Returns:
| Type | Description |
|---|---|
ExpireSnapshots
|
This for method chaining. |
Source code in pyiceberg/table/update/snapshot.py
ManageSnapshots
¶
Bases: UpdateTableMetadata['ManageSnapshots']
Run snapshot management operations using APIs.
APIs include create branch, create tag, etc.
Use table.manage_snapshots().
We can also use context managers to make more changes. For example,
with table.manage_snapshots() as ms: ms.create_tag(snapshot_id1, "Tag_A").create_tag(snapshot_id2, "Tag_B")
Source code in pyiceberg/table/update/snapshot.py
810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 | |
create_branch(snapshot_id, branch_name, max_ref_age_ms=None, max_snapshot_age_ms=None, min_snapshots_to_keep=None)
¶
Create a new branch pointing to the given snapshot id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
snapshot_id
|
int
|
snapshot id of existing snapshot at which the branch is created. |
required |
branch_name
|
str
|
name of the new branch |
required |
max_ref_age_ms
|
Optional[int]
|
max ref age in milliseconds |
None
|
max_snapshot_age_ms
|
Optional[int]
|
max age of snapshots to keep in milliseconds |
None
|
min_snapshots_to_keep
|
Optional[int]
|
min number of snapshots to keep for the branch |
None
|
Returns: This for method chaining
Source code in pyiceberg/table/update/snapshot.py
create_tag(snapshot_id, tag_name, max_ref_age_ms=None)
¶
Create a new tag pointing to the given snapshot id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
snapshot_id
|
int
|
snapshot id of the existing snapshot to tag |
required |
tag_name
|
str
|
name of the tag |
required |
max_ref_age_ms
|
Optional[int]
|
max ref age in milliseconds |
None
|
Returns:
| Type | Description |
|---|---|
ManageSnapshots
|
This for method chaining |
Source code in pyiceberg/table/update/snapshot.py
remove_branch(branch_name)
¶
Remove a branch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
branch_name
|
str
|
name of branch to remove |
required |
Returns: This for method chaining
Source code in pyiceberg/table/update/snapshot.py
remove_tag(tag_name)
¶
Remove a tag.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tag_name
|
str
|
name of tag to remove |
required |
Returns: This for method chaining
rollback_to_snapshot(snapshot_id)
¶
Rollback the table to the given snapshot id.
The snapshot needs to be an ancestor of the current table state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
snapshot_id
|
int
|
rollback to this snapshot_id that used to be current. |
required |
Returns:
| Type | Description |
|---|---|
ManageSnapshots
|
This for method chaining |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the snapshot does not exist or is not an ancestor of the current table state. |
Source code in pyiceberg/table/update/snapshot.py
rollback_to_timestamp(timestamp_ms)
¶
Rollback the table to the latest snapshot before the given timestamp.
Finds the latest ancestor snapshot whose timestamp is before the given timestamp and rolls back to it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timestamp_ms
|
int
|
Rollback to the latest snapshot before this timestamp in milliseconds. |
required |
Returns:
| Type | Description |
|---|---|
ManageSnapshots
|
This for method chaining |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no valid snapshot exists older than the given timestamp. |
Source code in pyiceberg/table/update/snapshot.py
set_current_snapshot(snapshot_id=None, ref_name=None)
¶
Set the current snapshot to a specific snapshot ID or ref.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
snapshot_id
|
int | None
|
The ID of the snapshot to set as current. |
None
|
ref_name
|
str | None
|
The snapshot reference (branch or tag) to set as current. |
None
|
Returns:
| Type | Description |
|---|---|
ManageSnapshots
|
This for method chaining. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If neither or both arguments are provided, or if the snapshot/ref does not exist. |