コード例 #1
0
    def setUpClass(cls):
        super(TimeseriesTests, cls).setUpClass()
        cls.now = datetime.datetime.utcfromtimestamp(144379690.987000)
        fiveMinsAgo = cls.now - fiveMins
        tenMinsAgo = fiveMinsAgo - fiveMins
        fifteenMinsAgo = tenMinsAgo - fiveMins
        twentyMinsAgo = fifteenMinsAgo - fiveMins
        twentyFiveMinsAgo = twentyMinsAgo - fiveMins

        client = cls.create_client()
        table = client.table(table_name)
        rows = [
            ['hash1', 'user2', twentyFiveMinsAgo, 'typhoon', 90.3],
            ['hash1', 'user2', twentyMinsAgo, 'hurricane', 82.3],
            ['hash1', 'user2', fifteenMinsAgo, 'rain', 79.0],
            ['hash1', 'user2', fiveMinsAgo, 'wind', None],
            ['hash1', 'user2', cls.now, 'snow', 20.1]
        ]
        ts_obj = table.new(rows)
        result = ts_obj.store()
        if result is not True:
            raise AssertionError("expected success")
        client.close()

        codec = RiakPbcCodec()
        cls.nowMsec = codec._unix_time_millis(cls.now)
        cls.fiveMinsAgo = fiveMinsAgo
        cls.twentyMinsAgo = twentyMinsAgo
        cls.twentyFiveMinsAgo = twentyFiveMinsAgo
        cls.tenMinsAgoMsec = codec._unix_time_millis(tenMinsAgo)
        cls.twentyMinsAgoMsec = codec._unix_time_millis(twentyMinsAgo)
        cls.numCols = len(rows[0])
        cls.rows = rows
コード例 #2
0
    def setUpClass(cls):
        cls.c = RiakPbcCodec()

        cls.ts0ms = cls.c._unix_time_millis(ts0)
        if cls.ts0ms != ex0ms:
            raise AssertionError(
                'expected {:d} to equal {:d}'.format(cls.ts0ms, ex0ms))

        cls.ts1ms = cls.c._unix_time_millis(ts1)
        if cls.ts1ms != ex1ms:
            raise AssertionError(
                'expected {:d} to equal {:d}'.format(cls.ts1ms, ex1ms))

        cls.rows = [
            [bd0, 0, 1.2, ts0, True],
            [bd1, 3, 4.5, ts1, False]
        ]
        cls.test_key = ['hash1', 'user2', ts0]
        cls.table = Table(None, 'test-table')
コード例 #3
0
    def test_decode_data_from_query(self):
        tqr = riak.pb.riak_ts_pb2.TsQueryResp()

        c0 = tqr.columns.add()
        c0.name = str_to_bytes('col_varchar')
        c0.type = TsColumnType.Value('VARCHAR')
        c1 = tqr.columns.add()
        c1.name = str_to_bytes('col_integer')
        c1.type = TsColumnType.Value('SINT64')
        c2 = tqr.columns.add()
        c2.name = str_to_bytes('col_double')
        c2.type = TsColumnType.Value('DOUBLE')
        c3 = tqr.columns.add()
        c3.name = str_to_bytes('col_timestamp')
        c3.type = TsColumnType.Value('TIMESTAMP')
        c4 = tqr.columns.add()
        c4.name = str_to_bytes('col_boolean')
        c4.type = TsColumnType.Value('BOOLEAN')

        r0 = tqr.rows.add()
        r0c0 = r0.cells.add()
        r0c0.varchar_value = str_to_bytes(self.rows[0][0])
        r0c1 = r0.cells.add()
        r0c1.sint64_value = self.rows[0][1]
        r0c2 = r0.cells.add()
        r0c2.double_value = self.rows[0][2]
        r0c3 = r0.cells.add()
        r0c3.timestamp_value = self.ts0ms
        r0c4 = r0.cells.add()
        r0c4.boolean_value = self.rows[0][4]

        r1 = tqr.rows.add()
        r1c0 = r1.cells.add()
        r1c0.varchar_value = str_to_bytes(self.rows[1][0])
        r1c1 = r1.cells.add()
        r1c1.sint64_value = self.rows[1][1]
        r1c2 = r1.cells.add()
        r1c2.double_value = self.rows[1][2]
        r1c3 = r1.cells.add()
        r1c3.timestamp_value = self.ts1ms
        r1c4 = r1.cells.add()
        r1c4.boolean_value = self.rows[1][4]

        tsobj = TsObject(None, self.table, [], [])
        c = RiakPbcCodec()
        c._decode_timeseries(tqr, tsobj)

        self.assertEqual(len(self.rows), len(tsobj.rows))
        self.assertEqual(len(tqr.columns), len(tsobj.columns))

        c = tsobj.columns
        self.assertEqual(c[0][0], 'col_varchar')
        self.assertEqual(c[0][1], TsColumnType.Value('VARCHAR'))
        self.assertEqual(c[1][0], 'col_integer')
        self.assertEqual(c[1][1], TsColumnType.Value('SINT64'))
        self.assertEqual(c[2][0], 'col_double')
        self.assertEqual(c[2][1], TsColumnType.Value('DOUBLE'))
        self.assertEqual(c[3][0], 'col_timestamp')
        self.assertEqual(c[3][1], TsColumnType.Value('TIMESTAMP'))
        self.assertEqual(c[4][0], 'col_boolean')
        self.assertEqual(c[4][1], TsColumnType.Value('BOOLEAN'))

        r0 = tsobj.rows[0]
        self.assertEqual(r0[0], self.rows[0][0])
        self.assertEqual(r0[1], self.rows[0][1])
        self.assertEqual(r0[2], self.rows[0][2])
        self.assertEqual(r0[3], ts0)
        self.assertEqual(r0[4], self.rows[0][4])

        r1 = tsobj.rows[1]
        self.assertEqual(r1[0], self.rows[1][0])
        self.assertEqual(r1[1], self.rows[1][1])
        self.assertEqual(r1[2], self.rows[1][2])
        self.assertEqual(r1[3], ts1)
        self.assertEqual(r1[4], self.rows[1][4])