Arrow Flight Client Node.js

上传表

启动本地 Flight 服务器。使用 tableFromArrays() 创建表,再调用 doPut(),用描述符 demo/uploaded 上传表。服务器会在应用元数据中返回写入的行数。

upload-table.ts
import { FlightClient, pathDescriptor } from 'arrow-flight-client';
import { tableFromArrays } from 'apache-arrow';

async function main() {
  const client = new FlightClient('127.0.0.1:8815');

  const table = tableFromArrays({
    id: [4, 5, 6],
    name: ['Dave', 'Eve', 'Frank']
  });

  try {
    for await (const result of client.doPut(
      pathDescriptor('demo', 'uploaded'),
      table
    )) {
      if (result.appMetadata) {
        console.log('Rows written:', Buffer.from(result.appMetadata).toString('utf8'));
      }
    }

    console.log('Table uploaded');
  }
  finally {
    await client.close();
  }
}

await main();

表 demo/uploaded 会出现在资源列表中。若要发送多个批次,将一系列 RecordBatch 对象传给 doPut()。每个批次的大小由调用方决定。