Permalink
Browse files

Add TimestampType alias for DateType

Cassandra 2.0 added TimestampType, which is the same as DateType except
for the sorting of pre-epoch (negative) unix timestamps.

Fixes #225
  • Loading branch information...
1 parent 7ffe498 commit e22f41164db9d74ae425b9963dc9fd898260e8bc @thobbs thobbs committed Jan 14, 2014
Showing with 7 additions and 4 deletions.
  1. +3 −3 pycassa/marshal.py
  2. +4 −1 pycassa/types.py
View
@@ -28,7 +28,7 @@ def make_packer(fmt_string):
'AsciiType', 'LexicalUUIDType', 'TimeUUIDType',
'CounterColumnType', 'FloatType', 'DoubleType',
'DateType', 'BooleanType', 'UUIDType', 'Int32Type',
- 'DecimalType')
+ 'DecimalType', 'TimestampType')
def extract_type_name(typestr):
if typestr is None:
@@ -238,7 +238,7 @@ def packer_for(typestr):
data_type = extract_type_name(typestr)
- if data_type == 'DateType':
+ if data_type in ('DateType', 'TimestampType'):
def pack_date(v, _=None):
return _long_packer.pack(_to_timestamp(v))
return pack_date
@@ -338,7 +338,7 @@ def unpacker_for(typestr):
if data_type == 'BytesType':
return lambda v: v
- elif data_type == 'DateType':
+ elif data_type in ('DateType', 'TimestampType'):
return lambda v: datetime.utcfromtimestamp(
_long_packer.unpack(v)[0] / 1e3)
View
@@ -31,7 +31,7 @@
'CounterColumnType', 'DoubleType', 'FloatType', 'DecimalType',
'BooleanType', 'DateType', 'OldPycassaDateType',
'IntermediateDateType', 'CompositeType',
- 'UUIDType', 'DynamicCompositeType')
+ 'UUIDType', 'DynamicCompositeType', 'TimestampType')
class CassandraType(object):
"""
@@ -142,6 +142,9 @@ class DateType(CassandraType):
"""
pass
+TimestampType = DateType
+
+
def _to_timestamp(v, use_micros=False):
# Expects Value to be either date or datetime
if use_micros:

0 comments on commit e22f411

Please sign in to comment.