Skip to content

Commit cdc4d12

Browse files
authored
chore: indexeddbm table metadata (#43)
* add: table metadata * update: tests * update: const * bump: version * cleanup * update: changes * fix: build * fix: test * update: test name
1 parent e7a1a33 commit cdc4d12

File tree

6 files changed

+58
-15
lines changed

6 files changed

+58
-15
lines changed

meerkat-dbm/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devrev/meerkat-dbm",
3-
"version": "0.0.135",
3+
"version": "0.0.136",
44
"dependencies": {
55
"tslib": "^2.3.0",
66
"@duckdb/duckdb-wasm": "^1.28.0",

meerkat-dbm/src/dbm/dbm.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,29 @@ import {
44
FileBufferStore,
55
FileData,
66
FileManagerType,
7+
Table,
78
} from '../file-manager/file-manager-type';
89
import { DBM, DBMConstructorOptions } from './dbm';
910
import { InstanceManagerType } from './instance-manager';
1011

1112
export class MockFileManager implements FileManagerType {
1213
private fileBufferStore: Record<string, FileBufferStore> = {};
14+
private tables: Record<string, Table> = {};
1315

1416
async bulkRegisterFileBuffer(props: FileBufferStore[]): Promise<void> {
1517
for (const prop of props) {
1618
this.fileBufferStore[prop.fileName] = prop;
19+
this.tables[prop.tableName] = this.tables[prop.tableName] || {
20+
files: [],
21+
};
22+
this.tables[prop.tableName].files.push(...props);
1723
}
1824
}
1925

2026
async registerFileBuffer(prop: FileBufferStore): Promise<void> {
2127
this.fileBufferStore[prop.fileName] = prop;
28+
this.tables[prop.tableName] = this.tables[prop.tableName] || { files: [] };
29+
this.tables[prop.tableName].files.push(prop);
2230
}
2331

2432
async getFileBuffer(name: string): Promise<Uint8Array> {
@@ -101,6 +109,14 @@ export class MockFileManager implements FileManagerType {
101109
return data;
102110
}
103111

112+
async getTableData(tableName: string): Promise<Table | undefined> {
113+
return this.tables[tableName];
114+
}
115+
116+
async setTableMetadata(table: string, metadata: object): Promise<void> {
117+
this.tables[table].metadata = metadata;
118+
}
119+
104120
onDBShutdownHandler = jest.fn(async () => {
105121
// do nothing
106122
});

meerkat-dbm/src/file-manager/file-manager-type.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ export interface FileManagerType {
1414
registerFileBuffer: (props: FileBufferStore) => Promise<void>;
1515
getFileBuffer: (name: string) => Promise<Uint8Array | undefined>;
1616
mountFileBufferByTableNames: (tableName: string[]) => Promise<void>;
17-
getFilesByTableName(tableName: string): Promise<FileData[]>;
17+
getTableData(tableName: string): Promise<Table | undefined>;
18+
setTableMetadata(tableName: string, metadata: object): Promise<void>;
1819
dropFilesByTableName(tableName: string, fileNames: string[]): Promise<void>;
1920
getFilesNameForTables(tableNames: string[]): Promise<
2021
{

meerkat-dbm/src/file-manager/indexed-db/indexed-db-file-manager.spec.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,16 @@ describe('IndexedDBFileManager', () => {
154154
expect(fileBufferData2[0].buffer).toEqual(new Uint8Array([1]));
155155
});
156156

157-
it('should return the files for a table stored', async () => {
158-
const fileData = await fileManager.getFilesByTableName('taxi1');
157+
it('should return the table data', async () => {
158+
const fileData = await fileManager.getTableData('taxi1');
159159

160-
expect(fileData).toEqual([
161-
{ fileName: 'taxi1.parquet', fileType: 'parquet' },
162-
{ fileName: 'taxi2.parquet', fileType: 'parquet' },
163-
]);
160+
expect(fileData).toEqual({
161+
files: [
162+
{ fileName: 'taxi1.parquet', fileType: 'parquet' },
163+
{ fileName: 'taxi2.parquet', fileType: 'parquet' },
164+
],
165+
tableName: 'taxi1',
166+
});
164167
});
165168

166169
it('should drop the file buffers for a table', async () => {
@@ -201,4 +204,14 @@ describe('IndexedDBFileManager', () => {
201204
fileBufferData2.some((file) => file.fileName !== 'taxi2.parquet')
202205
).toBe(true);
203206
});
207+
208+
it('should set the metadata for a table', async () => {
209+
await fileManager.setTableMetadata('taxi1', { test: 'test' });
210+
211+
const tableData = await indexedDB.tablesKey.toArray();
212+
213+
expect(tableData[0].metadata).toEqual({ test: 'test' });
214+
});
204215
});
216+
217+

meerkat-dbm/src/file-manager/indexed-db/indexed-db-file-manager.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { InstanceManagerType } from '../../dbm/instance-manager';
22
import { mergeFileBufferStoreIntoTable } from '../../utils/merge-file-buffer-store-into-table';
33
import {
44
FileBufferStore,
5-
FileData,
65
FileManagerConstructorOptions,
76
FileManagerType,
87
Table,
@@ -199,12 +198,21 @@ export class IndexedDBFileManager implements FileManagerType {
199198
}
200199

201200
/**
202-
* Get the list of files for the specified table name
201+
* Get the table data from the IndexedDB
203202
*/
204-
async getFilesByTableName(tableName: string): Promise<FileData[]> {
203+
async getTableData(tableName: string): Promise<Table | undefined> {
205204
const tableData = await this.indexedDB.tablesKey.get(tableName);
206205

207-
return tableData?.files ?? [];
206+
return tableData;
207+
}
208+
209+
/**
210+
* Set the metadata for the table
211+
*/
212+
async setTableMetadata(tableName: string, metadata: object): Promise<void> {
213+
await this.indexedDB.tablesKey.update(tableName, {
214+
metadata,
215+
});
208216
}
209217

210218
/**

meerkat-dbm/src/file-manager/memory-file-manager.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { InstanceManagerType } from '../dbm/instance-manager';
22
import {
33
FileBufferStore,
4-
FileData,
54
FileManagerConstructorOptions,
65
FileManagerType,
6+
Table,
77
} from './file-manager-type';
88

99
export class MemoryDBFileManager implements FileManagerType {
@@ -56,10 +56,15 @@ export class MemoryDBFileManager implements FileManagerType {
5656
return [];
5757
}
5858

59-
async getFilesByTableName(tableName: string): Promise<FileData[]> {
59+
async getTableData(tableName: string): Promise<Table | undefined> {
6060
// not needed for memory file manager
61-
return [];
61+
return;
6262
}
63+
64+
async setTableMetadata(table: string, metadata: object): Promise<void> {
65+
// not needed for memory file manager
66+
}
67+
6368
async dropFilesByTableName(
6469
tableName: string,
6570
fileNames: string[]

0 commit comments

Comments
 (0)