Skip to content

Commit 5139d5e

Browse files
committed
Add special handling of vector sub-type
1 parent ebe95ba commit 5139d5e

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

packages/compass-components/src/components/bson-value.tsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,37 @@ const BinaryValue: React.FunctionComponent<PropsByValueType<'Binary'>> = ({
157157

158158
return { stringifiedValue: `UUID('${uuid}')` };
159159
}
160+
if (value.sub_type === Binary.SUBTYPE_VECTOR) {
161+
const vectorType = value.buffer[0];
162+
if (vectorType === Binary.VECTOR_TYPE.Int8) {
163+
const truncatedSerializedBuffer = truncate(
164+
value.toInt8Array().slice(0, 100).toString(),
165+
100
166+
);
167+
return {
168+
stringifiedValue: `Binary.fromInt8Array(new Int8Array([${truncatedSerializedBuffer}]))`,
169+
};
170+
} else if (vectorType === Binary.VECTOR_TYPE.Float32) {
171+
const truncatedSerializedBuffer = truncate(
172+
[...value.toFloat32Array().slice(0, 100)]
173+
// Using a limited precision and removing trailing zeros for better displaying
174+
.map((num) => num.toPrecision(8).replace(/\.?0+$/, ''))
175+
.toString(),
176+
100
177+
);
178+
return {
179+
stringifiedValue: `Binary.fromFloat32Array(new Float32Array([${truncatedSerializedBuffer}]))`,
180+
};
181+
} else if (vectorType === Binary.VECTOR_TYPE.PackedBit) {
182+
const truncatedSerializedBuffer = truncate(
183+
value.toPackedBits().slice(0, 100).toString(),
184+
100
185+
);
186+
return {
187+
stringifiedValue: `Binary.fromPackedBits(new Uint8Array([${truncatedSerializedBuffer}]))`,
188+
};
189+
}
190+
}
160191
return {
161192
stringifiedValue: `Binary.createFromBase64('${truncate(
162193
value.toString('base64'),

0 commit comments

Comments
 (0)