MCPcopy Create free account
hub / github.com/alibaba/zvec / test_with_scalar_fields

Method test_with_scalar_fields

python/tests/test_convert.py:43–84  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

41 convert_to_cpp_doc(doc, collection_schema=schema)
42
43 def test_with_scalar_fields(self):
44 schema = CollectionSchema(
45 name="test_collection",
46 fields=[
47 FieldSchema("id", DataType.UINT64),
48 FieldSchema("salary", DataType.UINT32),
49 FieldSchema("age", DataType.INT32),
50 FieldSchema("create_at", DataType.INT64),
51 FieldSchema("author", DataType.STRING),
52 FieldSchema("weight", DataType.FLOAT),
53 FieldSchema("bmi", DataType.DOUBLE),
54 FieldSchema("is_male", DataType.BOOL),
55 ],
56 )
57 doc = Doc(
58 id="1",
59 fields={
60 "id": 1,
61 "salary": 1000,
62 "age": 18,
63 "create_at": 1640995200,
64 "bmi": 80.0 / 200.0,
65 "author": "Tom",
66 "weight": 80.0,
67 "is_male": True,
68 },
69 )
70 cpp_doc = convert_to_cpp_doc(doc, collection_schema=schema)
71 assert cpp_doc is not None
72 assert cpp_doc.pk() == doc.id
73 assert cpp_doc.get_any("id", DataType.UINT64) == 1
74 assert cpp_doc.get_any("salary", DataType.UINT32) == 1000
75 assert cpp_doc.get_any("age", DataType.INT32) == 18
76 assert cpp_doc.get_any("create_at", DataType.INT64) == 1640995200
77 assert cpp_doc.get_any("author", DataType.STRING) == "Tom"
78 assert math.isclose(
79 cpp_doc.get_any("weight", DataType.FLOAT), 80.0, rel_tol=1e-6
80 )
81 assert math.isclose(
82 cpp_doc.get_any("bmi", DataType.DOUBLE), 80.0 / 200.0, rel_tol=1e-6
83 )
84 assert cpp_doc.get_any("is_male", DataType.BOOL) == True
85
86 def test_with_array_fields(self):
87 schema = CollectionSchema(

Callers

nothing calls this directly

Calls 5

CollectionSchemaClass · 0.90
FieldSchemaClass · 0.90
DocClass · 0.90
convert_to_cpp_docFunction · 0.90
pkMethod · 0.80

Tested by

no test coverage detected