diff --git a/extensions/positron-duckdb/src/extension.ts b/extensions/positron-duckdb/src/extension.ts index 7eb9d1ed2ef..d6fb2118a44 100644 --- a/extensions/positron-duckdb/src/extension.ts +++ b/extensions/positron-duckdb/src/extension.ts @@ -1221,7 +1221,7 @@ export class DataExplorerRpcHandler { fs.watchFile(filePath, { interval: 1000 }, async () => { const newTableName = `positron_${this._tableIndex++}`; - await this.createTableFromFilePath(filePath, newTableName, true); + await this.createTableFromFilePath(filePath, newTableName); const newSchema = (await this.db.runQuery(`DESCRIBE ${newTableName};`)).toArray(); await tableView.onFileUpdated(newTableName, newSchema); @@ -1241,11 +1241,8 @@ export class DataExplorerRpcHandler { * Import data file into DuckDB by creating table or view * @param filePath The file path on disk. * @param catalogName The table name to use in the DuckDB catalog. - * @param forceRefresh If true, force an uncached read from disk to circumvent DuckDB's - * file handle caching. */ - async createTableFromFilePath(filePath: string, catalogName: string, - forceRefresh: boolean = false) { + async createTableFromFilePath(filePath: string, catalogName: string) { const getCsvImportQuery = (_filePath: string, options: Array) => { return `CREATE OR REPLACE TABLE ${catalogName} AS @@ -1278,24 +1275,22 @@ export class DataExplorerRpcHandler { const fileExt = path.extname(filePath); - if (fileExt === '.parquet' || fileExt === '.parq') { - // Always create a view for Parquet files - const query = `CREATE VIEW ${catalogName} AS - SELECT * FROM parquet_scan('${filePath}');`; - await this.db.runQuery(query); - } else if (forceRefresh) { - // For smaller text files, read the entire contents and register it as a temp file - // to avoid caching in duckdb-wasm - const fileContents = fs.readFileSync(filePath, { encoding: null }); - const virtualPath = path.basename(filePath); - await this.db.db.registerFileBuffer(virtualPath, fileContents); - try { + // Read the entire contents and register it as a temp file + // to avoid file handle caching in duckdb-wasm + const fileContents = fs.readFileSync(filePath, { encoding: null }); + const virtualPath = path.basename(filePath); + await this.db.db.registerFileBuffer(virtualPath, fileContents); + try { + if (fileExt === '.parquet' || fileExt === '.parq') { + // Always create a view for Parquet files + const query = `CREATE OR REPLACE TABLE ${catalogName} AS + SELECT * FROM parquet_scan('${virtualPath}');`; + await this.db.runQuery(query); + } else { await importDelimited(virtualPath); - } finally { - await this.db.db.dropFile(virtualPath); } - } else { - await importDelimited(filePath); + } finally { + await this.db.db.dropFile(virtualPath); } }