Exemplo n.º 1
0
 def test_csv_value_import(self):
     text = u"""
         10, 7
         7, 1
     """
     reader = csv_field_value_reader(StringIO(text),
                                     formatfunc=csv_column_id_value)
     client = self.get_client()
     field = self.index.field("import-value-field", int_max=100)
     field2 = self.index.field("import-value-field-set")
     client.sync_schema(self.schema)
     bq = self.index.batch_query(field2.set(1, 10), field2.set(1, 7))
     client.import_field(field, reader)
     client.query(bq)
     response = client.query(field.sum(field2.row(1)))
     self.assertEqual(8, response.result.value)
Exemplo n.º 2
0
    def test_csv_field_value_reader_column_id(self):
        reader = csv_field_value_reader(
            StringIO(u"""
            1,10
            5,20
            3,41
            10,10485760
        """))
        shard_bit_groups = list(batch_columns(reader, 2))
        self.assertEqual(2, len(shard_bit_groups))

        shard1, batch1 = shard_bit_groups[0]
        self.assertEqual(shard1, 0)
        self.assertEqual(2, len(list(batch1)))

        shard2, batch2 = shard_bit_groups[1]
        self.assertEqual(shard2, 0)
        self.assertEqual(2, len(list(batch2)))
Exemplo n.º 3
0
    def test_invalid_input(self):
        invalid_inputs = [
            # less than 2 columns
            u"155",
            # invalid row ID
            u"a5,155",
            # invalid column ID
            u"155,a5",
            # invalid timestamp
            u"155,255,a5",
        ]

        for text in invalid_inputs:
            reader = csv_column_reader(StringIO(text))
            self.assertRaises(PilosaError, list, reader)

        for test in invalid_inputs:
            reader = csv_field_value_reader(StringIO(text))
            self.assertRaises(PilosaError, list, reader)
Exemplo n.º 4
0
    def test_csv_field_value_reader_column_id(self):
        reader = csv_field_value_reader(
            StringIO(u"""
            1,10
            5,20
            3,41
            10,10485760
        """))
        from pilosa.client import DEFAULT_SHARD_WIDTH
        shard_bit_groups = list(batch_columns(reader, 2, DEFAULT_SHARD_WIDTH))
        self.assertEqual(2, len(shard_bit_groups))

        shard1, batch1 = shard_bit_groups[0]
        self.assertEqual(shard1, 0)
        self.assertEqual(2, len(list(batch1)))

        shard2, batch2 = shard_bit_groups[1]
        self.assertEqual(shard2, 0)
        self.assertEqual(2, len(list(batch2)))