FlareDbIO connects Apache Beam pipelines to FlareDB over Arrow Flight SQL. Use FlareDbIO.read() to run a query and read the result as Beam Rows, and FlareDbIO.write() to stream Rows into a FlareDB table.
Prerequisites
- A running FlareDB instance. See the Quickstart.
- The FlareDB I/O artifact in your project:
- Gradle
- Maven
build.gradle
Read from FlareDB
FlareDbIO.read() executes a SQL query on FlareDB and returns the results as a PCollection<Row>. The output schema is read from the query result.
ReadPipeline.java
Write to FlareDB
FlareDbIO.write() takes a PCollection<Row> and streams it into a FlareDB table.
Schema is fixed per table, so every row written to a table must share the same Beam schema.
If the destination table does not exist, FlareDbIO.write() creates it automatically using the Beam Row schema.
WritePipeline.java
Rows are buffered within each Beam bundle and sent to FlareDB as Arrow record batches. Use
withBatchSize() to control the maximum number of rows in each batch.
Table names
FlareDB addresses tables by fully qualified name:<catalog>.<database>.<table>. The catalog is flare and the database is default, so a scores table is flare.default.scores.
Complete example
WritePipeline.java
Example pipelines
The repo includes runnable examples under flare-db/example:flare-io-write— loads a CSV file into a FlareDB tableflare-io-read— reads that table back into a Beam pipeline asRows
Write example
flare-db/example/flare-io-write reads test-data/scores.csv with TextIO, parses each line into a Row using the schema id, name, city, age, score, and writes it to flare.default.scores with FlareDbIO.write().
127.0.0.1:8099, and writes into flare.default.scores.
Read example
Onceflare.default.scores has data, you can read it two ways.
1. Query it directly with flare-sql
FlareDbIO.read()
flare-db/example/flare-io-read runs the same query through FlareDbIO.read(), gets the result back as Beam Rows, and logs each row with a ParDo.
flare sql for interactive analytics, and FlareDbIO.read() when you need to use the data as input to another Beam pipeline.