cassandra.util
- Utilities¶
-
cassandra.util.
datetime_from_timestamp
(timestamp)[source]¶ Creates a timezone-agnostic datetime from timestamp (in seconds) in a consistent manner. Works around a Windows issue with large negative timestamps (PYTHON-119), and rounding differences in Python 3.4 (PYTHON-340).
Parameters: timestamp – a unix timestamp, in seconds
-
cassandra.util.
unix_time_from_uuid1
(uuid_arg)[source]¶ Converts a version 1
uuid.UUID
to a timestamp with the same precision astime.time()
returns. This is useful for examining the results of queries returning a v1UUID
.Parameters: uuid_arg – a version 1 UUID
-
cassandra.util.
datetime_from_uuid1
(uuid_arg)[source]¶ Creates a timezone-agnostic datetime from the timestamp in the specified type-1 UUID.
Parameters: uuid_arg – a version 1 UUID
-
cassandra.util.
min_uuid_from_time
(timestamp)[source]¶ Generates the minimum TimeUUID (type 1) for a given timestamp, as compared by Cassandra.
See
uuid_from_time()
for argument and return types.
-
cassandra.util.
max_uuid_from_time
(timestamp)[source]¶ Generates the maximum TimeUUID (type 1) for a given timestamp, as compared by Cassandra.
See
uuid_from_time()
for argument and return types.
-
cassandra.util.
uuid_from_time
(time_arg, node=None, clock_seq=None)[source]¶ Converts a datetime or timestamp to a type 1
uuid.UUID
.Parameters: - time_arg – The time to use for the timestamp portion of the UUID.
This can either be a
datetime
object or a timestamp in seconds (as returned fromtime.time()
). - node (long) – None integer for the UUID (up to 48 bits). If not specified, this field is randomized.
- clock_seq (int) – Clock sequence field for the UUID (up to 14 bits). If not specified, a random sequence is generated.
Return type: uuid.UUID
- time_arg – The time to use for the timestamp portion of the UUID.
This can either be a
-
cassandra.util.
LOWEST_TIME_UUID
= UUID('00000000-0000-1000-8080-808080808080')¶ The lowest possible TimeUUID, as sorted by Cassandra.
-
cassandra.util.
HIGHEST_TIME_UUID
= UUID('ffffffff-ffff-1fff-bf7f-7f7f7f7f7f7f')¶ The highest possible TimeUUID, as sorted by Cassandra.
-
class
cassandra.util.
SortedSet
(iterable=())[source]¶ A sorted set based on sorted list
A sorted set implementation is used in this case because it does not require its elements to be immutable/hashable.
#Not implemented: update functions, inplace operators
-
class
cassandra.util.
OrderedMap
(*args, **kwargs)[source]¶ An ordered map that accepts non-hashable types for keys. It also maintains the insertion order of items, behaving as OrderedDict in that regard. These maps are constructed and read just as normal mapping types, exept that they may contain arbitrary collections and other non-hashable items as keys:
>>> od = OrderedMap([({'one': 1, 'two': 2}, 'value'), ... ({'three': 3, 'four': 4}, 'value2')]) >>> list(od.keys()) [{'two': 2, 'one': 1}, {'three': 3, 'four': 4}] >>> list(od.values()) ['value', 'value2']
These constructs are needed to support nested collections in Cassandra 2.1.3+, where frozen collections can be specified as parameters to others*:
CREATE TABLE example ( ... value map<frozen<map<int, int>>, double> ... )
This class dervies from the (immutable) Mapping API. Objects in these maps are not intended be modified.
* Note: Because of the way Cassandra encodes nested types, when using the driver with nested collections,
protocol_version
must be 3 or higher.
-
class
cassandra.util.
Time
(value)[source]¶ Idealized time, independent of day.
Up to nanosecond resolution
Initializer value can be:
- integer_type: absolute nanoseconds in the day
- datetime.time: built-in time
- string_type: a string time of the form “HH:MM:SS[.mmmuuunnn]”
-
hour
¶ The hour component of this time (0-23)
-
minute
¶ The minute component of this time (0-59)
-
second
¶ The second component of this time (0-59)
-
nanosecond
¶ The fractional seconds component of the time, in nanoseconds
-
class
cassandra.util.
Date
(value)[source]¶ Idealized date: year, month, day
Offers wider year range than datetime.date. For Dates that cannot be represented as a datetime.date (because datetime.MINYEAR, datetime.MAXYEAR), this type falls back to printing days_from_epoch offset.
Initializer value can be:
- integer_type: absolute days from epoch (1970, 1, 1). Can be negative.
- datetime.date: built-in date
- string_type: a string time of the form “yyyy-mm-dd”
-
seconds
¶ Absolute seconds from epoch (can be negative)