Skip to content

Commit e8cc49f

Browse files
(WIP) Add TILEDB_BLOB type
1 parent 60e80e3 commit e8cc49f

10 files changed

+30
-4
lines changed

src/TileDBQuery/TileDBQuery.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ export class TileDBQuery {
215215
* Get the query response in capnp, we set responseType to arraybuffer instead of JSON
216216
* in order to deserialize the query capnp object.
217217
*/
218+
218219
const queryResponse = await this.queryAPI.submitQuery(
219220
namespace,
220221
arrayName,
@@ -247,8 +248,9 @@ export class TileDBQuery {
247248
* Deserialize buffer to a Query object
248249
*/
249250
const queryObject = capnpQueryDeSerializer(bufferWithoutFirstEightBytes);
250-
251251
const attributeHeaders = queryObject.attributeBufferHeaders;
252+
console.log(JSON.stringify(attributeHeaders));
253+
console.log('=================================');
252254

253255
// Case it's incomplete query
254256
if (queryObject.status === Querystatus.Incomplete) {

src/utils/bufferToData.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ const bufferToData = (arrayBuffer: ArrayBuffer, type: Datatype) => {
8686
return bufferToUTF32(arrayBuffer);
8787
} else if (int64Types.includes(type)) {
8888
return typedArrayToArray(bufferToInt64(arrayBuffer));
89+
} else if (type === Datatype.Blob) {
90+
return arrayBuffer;
8991
}
9092

9193
return arrayBuffer;

src/utils/convertToArray.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
function convertToArray(arrayLike: any): any[] {
2+
if (arrayLike.byteLength) {
3+
const uint8Array = new Uint8Array(arrayLike);
4+
const arrayOfUint8 = Array.from(uint8Array);
5+
return arrayOfUint8;
6+
}
27
if (Array.isArray(arrayLike)) {
38
return arrayLike;
49
}

src/utils/dataToArrayBuffer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ const dataToArrayBuffer = (data: any = [], type: Datatype): ArrayBuffer => {
3636
// If it's an array of CHARs join them together to a single string
3737
const str = Array.isArray(data) ? data.join('') : data;
3838
return utf32StrToArrayBuffer(str);
39+
} else if (type === Datatype.Blob) {
40+
return data;
3941
}
4042
};
4143

src/utils/getAttributeSchema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Attribute, Dimension } from '../v1';
1+
import { Attribute, Dimension } from '../v2';
22

33
/**
44
* Get attribute data from attribute name, attribute data contains the type of the attribute (e.g. INT32, StringUTF8 etc)

src/utils/getByteLengthOfData.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ const getByteLengthOfData = (data: number[] | string[], type: Datatype) => {
4343
return accum + encodedString.byteLength;
4444
}, 0);
4545
}
46+
47+
if (type === Datatype.Blob) {
48+
return (data as any).byteLength;
49+
}
4650
};
4751

4852
export default getByteLengthOfData;

src/utils/getByteLengthOfDatatype.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const getByteLengthOfDatatype = (type: Datatype) => {
1212
} else if (
1313
type === Datatype.StringAscii ||
1414
type === Datatype.Char ||
15+
type === Datatype.Blob ||
1516
type === Datatype.StringUtf8
1617
) {
1718
return 1;

src/utils/getResultsFromArrayBuffer.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { Attribute, Dimension } from '../v1';
2-
import { AttributeBufferHeader } from '../v2';
1+
import { AttributeBufferHeader, Attribute, Dimension, Datatype } from '../v2';
32
import getAttributeSizeInBytes from './getAttributeSizeInBytes';
43
import getAttributeSchema from './getAttributeSchema';
54
import getAttributeResult, { bufferToInt8 } from './bufferToData';
@@ -128,10 +127,19 @@ export const getResultsFromArrayBuffer = async (
128127
convertToArray(result),
129128
offsets
130129
);
130+
131131
// If it's a string we concat all the characters to create array of strings
132132
result = isString
133133
? concatChars(groupedValues as string[][])
134134
: (groupedValues as number[][] | bigint[][]);
135+
136+
// Fix: Type
137+
if (selectedAttributeSchema.type === Datatype.Blob) {
138+
const arrayBuffers: any = groupedValues.map(
139+
ints => Uint8Array.from(ints).buffer
140+
);
141+
result = arrayBuffers;
142+
}
135143
}
136144

137145
if (isNullable && !options.ignoreNullables) {

src/utils/groupValuesByOffsetBytes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const groupValuesByOffsetBytes = <T>(
2020
off,
2121
offsetIndex[i]
2222
]);
23+
2324
const offsetsP = new Parallel(offsetIndexTuple, {
2425
env: {
2526
values,

src/v2/api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,7 @@ export enum Datatype {
782782
Uint32 = 'UINT32',
783783
Uint64 = 'UINT64',
784784
StringAscii = 'STRING_ASCII',
785+
Blob = 'BLOB',
785786
StringUtf8 = 'STRING_UTF8',
786787
StringUtf16 = 'STRING_UTF16',
787788
StringUtf32 = 'STRING_UTF32',

0 commit comments

Comments
 (0)