> For the complete documentation index, see [llms.txt](https://docs.redivis.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.redivis.com/api/client-libraries/redivis-js/examples/reading-tabular-data.md).

# Reading tabular data

### Read table data into JavaScript

```javascript
import redivis from 'redivis';

// Specify the table's container, either a dataset or workflow
const dataset = redivis.organization('demo').dataset('iris_species');
const table = dataset.table('iris');

// An array of row objects
const rows = await table.toRowsArray();
// [
//   { Id: 33, SepalLengthCm: 5.2, SepalWidthCm: 4.1, PetalLengthCm: 1.5, PetalWidthCm: 0.1, Species: 'Iris-setosa' },
//   ...
// ]

// Only read certain variables, and a maximum number of rows
const someRows = await table.toRowsArray(10, { variables: ['Species', 'SepalLengthCm'] });

// An Apache Arrow table
const arrowTable = await table.toArrowTable();

// Other methods to read data:
// table.toArrowBatchIterator()
// await table.toReadStreams()
```

### Stream data

For tables that are too large to fit in memory, stream the data one arrow [RecordBatch](https://arrow.apache.org/docs/js/classes/Arrow_dom.RecordBatch.html) at a time:

```javascript
import redivis from 'redivis';

const table = redivis.table('demo.us_forest_service_fires:5k9t:v1_1.us_fire_perimeters:9r58');

let rowCount = 0;
for await (const batch of table.toArrowBatchIterator({
  variables: ['FIREYEAR', 'GISACRES'],
  onProgress: ({ rowsRead, totalRows }) => console.log(`Read ${rowsRead} of ${totalRows} rows`),
})) {
  rowCount += batch.numRows;
}
```

### Using other libraries

[Apache Arrow](https://arrow.apache.org/docs/js/) is widely supported, so an arrow Table can be handed directly to many other JavaScript data tools:

```javascript
const arrowTable = await table.toArrowTable();

// Arquero
import * as aq from 'arquero';
const frame = aq.fromArrow(arrowTable);

// Observable Plot
import * as Plot from '@observablehq/plot';
Plot.dot(arrowTable, { x: 'FIREYEAR', y: 'GISACRES' }).plot();

// DuckDB-Wasm
await connection.insertArrowTable(arrowTable, { name: 'fires' });

// nodejs-polars
import pl from 'nodejs-polars';
import { tableToIPC } from 'apache-arrow';
const df = pl.readIPC(Buffer.from(tableToIPC(arrowTable)));
```

### Work with dates and large integers

By default, [`toRowsArray()`](https://docs.redivis.com/api/client-libraries/redivis-js/reference/table/table.torowsarray.md) returns dates and times as [`Temporal`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal) values, and integers as numbers. See [Data types](https://docs.redivis.com/api/client-libraries/redivis-js/reference.md#data-types) for details.

```javascript
// E.g., for a table with an `observed_at` dateTime variable
const rows = await table.toRowsArray();
rows[0].observed_at; // Temporal.PlainDateTime
rows[0].observed_at.year; // e.g., 2004
rows[0].observed_at.toString(); // e.g., '2004-06-01T12:30:00.123456'

// Return Date objects (in UTC) instead
const rowsWithDates = await table.toRowsArray({ temporal: false });

// Return integers as BigInts, to avoid losing precision beyond 2^53
const rowsWithBigInts = await table.toRowsArray({ bigInt: true });
```

### Read table metadata

```javascript
import redivis from 'redivis';

const table = redivis.organization('demo').dataset('iris_species').table('iris');

await table.get();
console.log(table.properties.numRows);

const variable = table.variable('SepalLengthCm');
await variable.get();

console.log(variable.properties);
// { kind: 'variable', ... (see the variable resource definition) }

console.log(await variable.getStatistics());
// {
//   kind: 'variableStatistics',
//   status: 'completed',
//   count: 150,
//   numDistinct: 35,
//   min: 4.3,
//   max: 7.9,
//   ...
// }
```

### Read data in parallel

```javascript
import redivis from 'redivis';

const table = redivis.table('demo.us_forest_service_fires:5k9t:v1_1.us_fire_perimeters:9r58');

// Split the table into (up to) 4 streams, which can each be read independently
const streams = await table.toReadStreams(4);
const arrowTables = await Promise.all(streams.map((stream) => stream.toArrowTable()));
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.redivis.com/api/client-libraries/redivis-js/examples/reading-tabular-data.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
