Arrow Flight Client Node.js

Procesar lotes RecordBatch en streaming

Con el servidor Flight local en ejecución, llama a doGet() para leer los datos conforme llegan. El ejemplo muestra el tamaño del primer lote. Si sales del bucle for await con break, se liberan los recursos del flujo.

stream-batches.ts
import { FlightClient } from 'arrow-flight-client';

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

  try {
    for await (const flight of client.listFlights()) {
      const ticket = flight.endpoints.find(endpoint => endpoint.ticket)?.ticket;

      if (!ticket) {
        continue;
      }

      const reader = await client.doGet(ticket);

      for await (const chunk of reader) {
        if (chunk.data) {
          console.log('Batch rows:', chunk.data.numRows);
          break;
        }
      }

      return;
    }

    throw new Error('No Flight endpoint with a ticket was found');
  }
  finally {
    await client.close();
  }
}

await main();

Consume un FlightStreamReader con un solo bucle for await o una sola llamada a readAll(). Cada elemento del flujo conserva la asociación entre un RecordBatch y sus metadatos de aplicación. El servidor también puede enviar mensajes que solo contienen metadatos.

Para volver a leer los datos, inicia una llamada a doGet() con un ticket válido. Si el servidor indica expirationTime, puedes repetir la solicitud antes de ese momento. En los demás casos se aplican las reglas del servidor. Contrato de Flight

Si solo necesitas el esquema, abre el flujo y llama a cancel() después de leerlo.

inspect-schema.ts
import type { FlightClient, FlightTicket } from 'arrow-flight-client';

export async function inspectSchema(client: FlightClient, ticket: FlightTicket) {
  const reader = await client.doGet(ticket);

  try {
    console.log(reader.schema);
  }
  finally {
    await reader.cancel();
  }
}

cancel() interrumpe la lectura activa con AbortError y se resuelve tras liberar los recursos del flujo. Cuando terminen todas las llamadas, cierra el cliente con client.close().