UNPKG

@tableau/taco-toolkit

Version:
51 lines (50 loc) 2.22 kB
import { Database } from 'duckdb-async'; import { TempDataManager } from '../../../modules/temp-data-manager'; import { TacoFileParser } from './base-taco-file-parser'; import { ColumnHeader } from '../../../types/column-header'; import { DataRow } from '../../../../shared/types/data-row'; export type CsvDuckdbTacoParserType = typeof CsvDuckdbTacoParser; export declare class CsvDuckdbTacoParser extends TacoFileParser { private tempDataManager; private extractorId; private filename; private filepath; private columnHeaderMap; private headersFromFile; private db; constructor(tempDataManager: TempDataManager, extractorId: string, filename: string); /** * Set columns metadata info to the parser. When columnHeaders are set, getColumnHeaders will * respect the given info. Otherwise, all fields are assumed as string type. * * To prevent the method from being misused, this method can be called once, otherwise, * it throws an error. */ setColumnHeaders(columnHeaders: ColumnHeader[]): void; /** * Get ColumnHeaders for a CSV file. * * By default, it returns all column header fields and all columns are typed as string. * If columns metadata is set by setColumnHeaders, it will filter the columns with the given columnHeaders, * while the column order from the file is still preserved. */ getColumnHeaders(): Promise<ColumnHeader[]>; getRowCount(): Promise<number>; /** * Get the set of data rows from the CSV file with the specified limit and offset. */ getDataRows(limit: number, offset: number): Promise<{ data: DataRow[]; hasMoreRows: boolean; }>; getDb(): Promise<Database>; /** * Retrieves the column names from the first row of a csv file located at the given file path. * * @param {Database} db - The duckdb database instance to execute the query against. * @param {string} filepath - The file path of the csv file to read from. * * @returns {Promise<string[]>} - A Promise that resolves with an array of string column names, or an empty array if no column names were found. */ private getColumnNamesFromFile; }