Skip to content

Commit 6465650

Browse files
authored
fix: update the existing file (#58)
1 parent 7b37329 commit 6465650

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

meerkat-dbm/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devrev/meerkat-dbm",
3-
"version": "0.0.15",
3+
"version": "0.0.151",
44
"dependencies": {
55
"tslib": "^2.3.0",
66
"@duckdb/duckdb-wasm": "^1.28.0",

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

+1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ export interface FileManagerType {
130130
export type BaseFileStore = {
131131
tableName: string;
132132
fileName: string;
133+
partitions?: string[];
133134
staleTime?: number;
134135
cacheTime?: number;
135136
metadata?: object;

meerkat-dbm/src/utils/__tests__/merge-file-buffer-store-into-table.spec.ts

+20
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,24 @@ describe('mergeFileBufferStoreIntoTable', () => {
8181
files: [{ fileName: 'taxi1.parquet' }],
8282
});
8383
});
84+
85+
it('should update the file if already exists', () => {
86+
const currentTableState = [
87+
{
88+
tableName: fileBufferStore.tableName,
89+
files: [{ fileName: fileBufferStore.fileName }],
90+
},
91+
];
92+
93+
const updatedTableMap = mergeFileBufferStoreIntoTable(
94+
[{ ...fileBufferStore, partitions: ['dev_oid=DEV-787'] }],
95+
currentTableState
96+
);
97+
98+
// Verify that the taxi1 table still has one file (taxi1.parquet)
99+
expect(updatedTableMap.get('taxi1')).toEqual({
100+
tableName: 'taxi1',
101+
files: [{ fileName: 'taxi1.parquet', partitions: ['dev_oid=DEV-787'] }],
102+
});
103+
});
84104
});

meerkat-dbm/src/utils/merge-file-buffer-store-into-table.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,18 @@ export const mergeFileBufferStoreIntoTable = (
3636
* Check if the table already exists in the map if it does, then update the existing table entry
3737
*/
3838
if (existingTable) {
39-
const fileExists = existingTable.files.some(
39+
const existingFileIndex = existingTable.files.findIndex(
4040
(file) => file.fileName === fileBuffer.fileName
4141
);
4242

43-
if (!fileExists) {
43+
if (existingFileIndex !== -1) {
44+
// If file exists, update the fileData
45+
existingTable.files[existingFileIndex] = {
46+
...existingTable.files[existingFileIndex],
47+
...fileData,
48+
};
49+
} else {
50+
// If file does not exist, add it to the files array
4451
existingTable.files.push(fileData);
4552
}
4653
} else {

0 commit comments

Comments
 (0)