def test_perf(self): field_name = 'a' n = 1000000 value = 2 b = write_n_simple_objects(field_name, primitive_schemas.INT, n, value) buf = b.getvalue() start = clock() node = bamboo_cpp.convert_avro(BytesIO(buf)) end = clock() bamboo_time = end - start list_node = node.get_list() primitive_node = list_node.get_field(field_name) self.assertListEqual(primitive_node.get_values().tolist(), [value] * n) result = np.ndarray((n,)) i = 0 start = clock() for record in reader(b): result[i] = record['a'] i = i + 1 end = clock() fastavro_time = end - start self.assertListEqual(result.tolist(), [value] * n) bamboo_speedup = fastavro_time / bamboo_time self.assertGreater(bamboo_speedup, 10)
def test_list(self): list_schema = make_array_schema(primitive_schemas.INT) value = [1, 2] b = object(list_schema, value) node = bamboo_cpp.convert_avro(b) self.assertEqual(node.get_list().get_list().get_size(), 2) self.assertListEqual(node.get_list().get_list().get_values().tolist(), value)
def test_fixed(self): names = schema.Names() fixed_schema = schema.FixedSchema("test", "test", 3, names=names) value = b'abc' b = object(fixed_schema, value) node = bamboo_cpp.convert_avro(b) self.assertListEqual(node.get_list().get_values().tolist(), [value])
def assert_primitive(self, primitive_schema, primitive_value): field_name = 'a' b = simple_object(field_name, primitive_schema, primitive_value) node = bamboo_cpp.convert_avro(b) list_node = node.get_list() primitive_node = list_node.get_field(field_name) self.assertListEqual(primitive_node.get_values().tolist(), [primitive_value])
def test_null(self): union_schema = make_union_schema([primitive_schemas.INT, primitive_schemas.NULL]) value = 1 values = [value, None] b = object(union_schema, values, True) node = bamboo_cpp.convert_avro(b) list_node = node.get_list() self.assertListEqual(list_node.get_values().tolist(), [value]) self.assertListEqual(list_node.get_null_indices().tolist(), [1])
def from_avro(s, include=None, exclude=None): extension_node = bamboo_cpp.convert_avro( s, convert_clusions(include, exclude)) return convert_extension_node(extension_node)
def test_enum(self): names = schema.Names() enum_schema = schema.EnumSchema("test", "test", ['a', 'b'], names=names) b = object(enum_schema, 'b') node = bamboo_cpp.convert_avro(b) self.assertListEqual(node.get_list().get_values().tolist(), ['b'])