Merge "Cast Int64 values to float"

This commit is contained in:
Jenkins 2015-08-07 17:20:03 +00:00 committed by Gerrit Code Review
commit 4793854931
4 changed files with 13 additions and 2 deletions

View File

@ -310,6 +310,8 @@ class Connection(hbase_base.Connection, base.Connection):
limit=limit, columns=columns)
for ignored, meter in gen:
d_meter = hbase_utils.deserialize_entry(meter)[0]
d_meter['message']['counter_volume'] = (
float(d_meter['message']['counter_volume']))
d_meter['message']['recorded_at'] = d_meter['recorded_at']
yield models.Sample(**d_meter['message'])

View File

@ -48,7 +48,7 @@ OP_SIGN = {'lt': '$lt', 'le': '$lte', 'ne': '$ne', 'gt': '$gt', 'ge': '$gte'}
MINIMUM_COMPATIBLE_MONGODB_VERSION = [2, 4]
COMPLETE_AGGREGATE_COMPATIBLE_VERSION = [2, 6]
TRIVIAL_LAMBDA = lambda result, param=None: result
FINALIZE_AGGREGATION_LAMBDA = lambda result, param=None: float(result)
CARDINALITY_VALIDATION = (lambda name, param: param in ['resource_id',
'user_id',
'project_id',
@ -519,7 +519,7 @@ class AggregationFields(object):
finalize=None,
parametrized=False,
validate=None):
self._finalize = finalize or TRIVIAL_LAMBDA
self._finalize = finalize or FINALIZE_AGGREGATION_LAMBDA
self.group = lambda *args: group(*args) if parametrized else group
self.project = (lambda *args: project(*args)
if parametrized else project)

View File

@ -139,6 +139,8 @@ class Connection(base.Connection):
del s['_id']
# Backward compatibility for samples without units
s['counter_unit'] = s.get('counter_unit', '')
# Compatibility with MongoDB 3.+
s['counter_volume'] = float(s.get('counter_volume'))
# Tolerate absence of recorded_at in older datapoints
s['recorded_at'] = s.get('recorded_at')
# Check samples for metadata and "unquote" key if initially it

View File

@ -406,6 +406,13 @@ class RawSampleTest(DBTestBase,
source='test-4'
))
def test_get_sample_counter_volume(self):
# NOTE(idegtiarov) Because wsme expected a float type of data this test
# checks type of counter_volume received from database.
f = storage.SampleFilter()
result = next(self.conn.get_samples(f, limit=1))
self.assertIsInstance(result.counter_volume, float)
def test_get_samples_limit_zero(self):
f = storage.SampleFilter()
results = list(self.conn.get_samples(f, limit=0))