import { DataTypeConfig, ReadonlyDataTypeConfig, Maybe, xLuceneVariables } from '@terascope/types'; import { Node as xLuceneNode } from 'xlucene-parser'; import { DataEntity } from '@terascope/core-utils'; import { Column } from '../column/index.js'; import { AggregationFrame } from '../aggregation-frame/index.js'; import { Builder } from '../builder/index.js'; import { FieldArg } from '../core/index.js'; import { SerializeOptions } from '../vector/index.js'; /** * An immutable columnar table with APIs for data pipelines. * * @note null/undefined values are treated the same */ export declare class DataFrame = Record> { #private; /** * Create a DataFrame from an array of JSON objects */ static fromJSON = Record>(config: DataTypeConfig | ReadonlyDataTypeConfig, records?: R[], options?: DataFrameOptions): DataFrame; /** * Create an empty DataFrame */ static empty = Record>(config: DataTypeConfig | ReadonlyDataTypeConfig, options?: DataFrameOptions): DataFrame; /** * Create a DataFrame from a serialized format, * the first row is data frame metadata, * all of the subsequent rows are serialized columns. * * When using this method, the input should be split by a new line. */ static deserializeIterator = Record>(data: Iterable | AsyncIterable): Promise>; /** * Create a DataFrame from a serialized format, * the first row is data frame metadata, * all of the subsequent rows are serialized columns. * The rows should be joined with a newline. * * When using this method, the whole serialized file should be * passed in. * * For a more advanced steam like processing, see {@see DataFrame.deserializeIterator} * Using that method may be required for deserializing a buffer or string * greater than 1GB. */ static deserialize = Record>(data: Buffer | string): Promise>; /** * The name of the Frame */ name?: string; /** * The list of columns */ readonly columns: readonly Column[]; /** * An array of the column names */ readonly fields: readonly (keyof T)[]; /** * Metadata about the Frame */ readonly metadata: Record; /** * Size of the DataFrame */ readonly size: number; /** * Use this to cache the the column index needed, this * should speed things up */ protected _fieldToColumnIndexCache?: Map<(keyof T), number>; constructor(columns: Column[] | readonly Column[], options?: DataFrameOptions); /** * Iterate over each row, this returns the JSON compatible values. */ [Symbol.iterator](): IterableIterator>; /** * Iterate over each index and row, this returns the internal stored values. */ entries(json: true, options?: SerializeOptions): IterableIterator<[index: number, row: DataEntity]>; entries(json?: false | undefined, options?: SerializeOptions): IterableIterator<[index: number, row: T]>; /** * Iterate each row */ rows(json: true, options?: SerializeOptions): IterableIterator>; rows(json?: false | undefined, options?: SerializeOptions): IterableIterator; /** * This is more expensive and little more complicated. * In the future we pass in json=false to each column and * the call toJSONCompatibleValue after each generating the hash * to be consistent with hash */ rowsWithoutDuplicates(json: true, options?: SerializeOptions): IterableIterator>; rowsWithoutDuplicates(json?: false | undefined, options?: SerializeOptions): IterableIterator; /** * A Unique ID for the DataFrame * The ID will only change if the columns or data change */ get id(): string; /** * Create a new DataFrame with the same metadata but with different data */ fork = T>(columns: Column[] | readonly Column[]): DataFrame; /** * Generate the DataType config from the columns. */ get config(): DataTypeConfig; /** * Get a column, or columns by name, returns a new DataFrame */ select(...fieldArg: FieldArg[]): DataFrame>; /** * Select fields in a data frame, this will work with nested object * fields. * * Fields that don't exist in the data frame are safely ignored to make * this function handle more suitable for production environments */ deepSelect(fieldSelectors: string[] | readonly string[]): DataFrame; /** * Get a column, or columns by index, returns a new DataFrame */ selectAt = T>(...indices: number[]): DataFrame; /** * Create a AggregationFrame instance which can be used to run aggregations */ aggregate(): AggregationFrame; /** * Order the rows by fields, format of is `field:asc` or `field:desc`. * Defaults to `asc` if none specified */ orderBy(...fieldArgs: FieldArg[]): DataFrame; orderBy(...fieldArgs: FieldArg[]): DataFrame; /** * Sort the records by a field, an alias of orderBy. * * @see orderBy */ sort(...fieldArgs: FieldArg[]): DataFrame; sort(...fieldArgs: FieldArg[]): DataFrame; /** * Search the DataFrame using an xLucene query */ search(query: string, variables?: xLuceneVariables, overrideParsedQuery?: xLuceneNode, stopAtMatch?: number): DataFrame; /** * Require specific columns to exist on every row */ require(...fieldArg: FieldArg[]): DataFrame; /** * Filter the DataFrame by fields, all fields must return true * for a given row to returned in the filtered DataType * * @example * * dataFrame.filter({ * name(val) { * return val != null; * }, * age(val) { * return val != null && val >= 20; * } * }); */ filterBy(filters: FilterByFields | FilterByFn, json?: boolean): DataFrame; private _filterByFields; /** * This is pretty in-efficent since it has to iterate over * all the records + fields once and then again for every * match */ private _filterByFn; /** * This allows you to filter each row more efficiently by * since the rows aren't pulled from the data frame unless they match. * * This was designed to be used in @see DataFrame.search */ filterDataFrameRows(fn: FilterByRowsFn, stopAtMatch?: number): DataFrame; /** * Remove the empty rows from the data frame, * this is optimization that won't require moving * around as much memory */ removeEmptyRows(): DataFrame; /** * Count the number of empty rows */ countEmptyRows(): number; /** * Check if there are any empty rows at all */ hasEmptyRows(): boolean; /** * Check if there are any columns with nil values */ hasNilValues(): boolean; /** * Remove duplicate rows with the same value for select fields */ unique(...fieldArg: FieldArg[]): DataFrame; /** * Alias for unique */ distinct(...fieldArg: FieldArg[]): DataFrame; /** * Like unique but will allow passing serialization options */ private _unique; /** * Create a new data frame from the builders */ forkWithBuilders(builders: Iterable<[ name: keyof T, builder: Builder ]>, limit?: number): DataFrame; /** * Reduce amount of noise in a DataFrame by * removing the amount of duplicates, including * duplicate objects in array values */ compact(): DataFrame; /** * Assign new columns to a new DataFrame. If given a column already exists, * the column will replace the existing one. */ assign = Record>(columns: readonly Column[]): DataFrame; /** * Concat rows, or columns, to the end of the existing Columns */ concat(arg: (Partial[] | Column[]) | (readonly Partial[] | readonly Column[])): DataFrame; /** * Append one to the end of this DataFrame. This is does less than * appendAll so it is faster. * * Useful for incremental building an DataFrame since the cost of * this is relatively low. * * This is more efficient than using DataFrame.concat but comes with less * data type checking and may less safe so use with caution */ appendOne(frame: DataFrame): DataFrame; /** * Append one or more data frames to the end of this DataFrame. * Useful for incremental building an DataFrame since the cost of * this is relatively low. * * This is more efficient than using DataFrame.concat but comes with less * data type checking and may less safe so use with caution */ appendAll(frames: DataFrame[] | (readonly DataFrame[]), limit?: number): DataFrame; /** * Rename an existing column */ rename(name: K, renameTo: R): DataFrame & Record>; /** * Rename the data frame */ renameDataFrame(renameTo: string): DataFrame; /** * Merge two or more columns into a Tuple */ createTupleFrom(fields: readonly (keyof T)[], as: R): DataFrame>; /** * Get a column by name */ getColumn

(field: P): Column | undefined; /** * This returns -1 if not found. The column index will * be cached. In the case with duplicate named columned, * the first one found wins */ getColumnIndex(field: keyof T): number; /** * Get a column by name or throw if not found */ getColumnOrThrow

(field: P): Column; /** * Get a column by index */ getColumnAt

(index: number): Column | undefined; /** * Get a row by index, if the row has only null values, returns undefined */ getRow(index: number, json?: true, options?: SerializeOptions): DataEntity | undefined; getRow(index: number, json?: false | undefined, options?: SerializeOptions): T | undefined; private _getRowOptimized; /** * This is used json is false, we do this because this slightly faster * and it easier since we don't have to switch being DataEntities and * plain objects */ private _getRawRow; /** * Returns a DataFrame with a limited number of rows * * A negative value will select from the ending indices */ limit(num: number): DataFrame; /** * Returns a DataFrame with a a specific set of rows */ slice(start?: number, end?: number): DataFrame; /** * Convert the DataFrame an array of objects (the output is JSON compatible) */ toJSON(options?: SerializeOptions): DataEntity[]; /** * Convert the DataFrame an array of objects (the output may not be JSON compatible) */ toArray(): T[]; /** * Converts the DataFrame into an optimized serialized format, * including the metadata. This returns an iterator and requires * external code to join yield chunks with a new line. * * There is 1GB limit per column using this method */ serializeIterator(): Iterable; /** * Converts the DataFrame into an optimized serialized format, * including the metadata. This returns a string that includes * the data frame header and all of columns joined with a new line. * * There is 1GB limit for the whole data frame using this method, * to achieve a 1GB limit per column, use {@see serializeIterator} */ serialize(): string; } /** * DataFrame options */ export interface DataFrameOptions { name?: string; metadata?: Record; } export type FilterByFields = Partial<{ [P in keyof T]: (value: Maybe) => boolean; }>; export type FilterByFn = (row: T, index: number) => boolean; export type FilterByRowsFn = (index: number) => boolean; //# sourceMappingURL=DataFrame.d.ts.map