feat: port create_table to the async python API and the remote rust API (#1031)

I've also started `ASYNC_MIGRATION.MD` to keep track of the breaking
changes from sync to async python.
This commit is contained in:
Weston Pace
2024-02-29 13:29:29 -08:00
parent accf31fa92
commit 4299f719ec
29 changed files with 1406 additions and 53 deletions

View File

@@ -17,6 +17,24 @@ import { Connection as _NativeConnection } from "./native";
import { Table } from "./table";
import { Table as ArrowTable } from "apache-arrow";
export interface CreateTableOptions {
/**
* The mode to use when creating the table.
*
* If this is set to "create" and the table already exists then either
* an error will be thrown or, if existOk is true, then nothing will
* happen. Any provided data will be ignored.
*
* If this is set to "overwrite" then any existing table will be replaced.
*/
mode: "create" | "overwrite";
/**
* If this is true and the table already exists and the mode is "create"
* then no error will be raised.
*/
existOk: boolean;
}
/**
* A LanceDB Connection that allows you to open tables and create new ones.
*
@@ -53,10 +71,18 @@ export class Connection {
*/
async createTable(
name: string,
data: Record<string, unknown>[] | ArrowTable
data: Record<string, unknown>[] | ArrowTable,
options?: Partial<CreateTableOptions>
): Promise<Table> {
let mode: string = options?.mode ?? "create";
const existOk = options?.existOk ?? false;
if (mode === "create" && existOk) {
mode = "exist_ok";
}
const buf = toBuffer(data);
const innerTable = await this.inner.createTable(name, buf);
const innerTable = await this.inner.createTable(name, buf, mode);
return new Table(innerTable);
}

View File

@@ -85,7 +85,7 @@ export class Connection {
* - buf: The buffer containing the IPC file.
*
*/
createTable(name: string, buf: Buffer): Promise<Table>
createTable(name: string, buf: Buffer, mode: string): Promise<Table>
openTable(name: string): Promise<Table>
/** Drop table with the name. Or raise an error if the table does not exist. */
dropTable(name: string): Promise<void>
@@ -117,7 +117,7 @@ export class Table {
/** Return Schema as empty Arrow IPC file. */
schema(): Promise<Buffer>
add(buf: Buffer): Promise<void>
countRows(filter?: string | undefined | null): Promise<bigint>
countRows(filter?: string | undefined | null): Promise<number>
delete(predicate: string): Promise<void>
createIndex(): IndexBuilder
query(): Query

View File

@@ -50,7 +50,7 @@ export class Table {
}
/** Count the total number of rows in the dataset. */
async countRows(filter?: string): Promise<bigint> {
async countRows(filter?: string): Promise<number> {
return await this.inner.countRows(filter);
}