Struct questdb::ingress::Buffer

source ·
pub struct Buffer { /* private fields */ }
Expand description

A reusable buffer to prepare ILP messages.

Example

use questdb::ingress::Buffer;
use std::time::SystemTime;
 
let mut buffer = Buffer::new();
 
// first row
buffer
    .table("table1")?
    .symbol("bar", "baz")?
    .column_bool("a", false)?
    .column_i64("b", 42)?
    .column_f64("c", 3.14)?
    .column_str("d", "hello")?
    .column_ts("e", SystemTime::now())?
    .at(SystemTime::now())?;
 
// second row
buffer
    .table("table2")?
    .symbol("foo", "bar")?
    .at_now()?;

The buffer can then be sent with the Sender’s flush method.

Sequential Coupling

The Buffer API is sequentially coupled:

This diagram might help:

Buffer method calls, Serialized ILP types and QuestDB types

Buffer MethodSerialized as ILP type (Click on link to see possible casts)
symbolSYMBOL
column_boolBOOLEAN
column_i64INTEGER
column_f64FLOAT
column_strSTRING
column_tsTIMESTAMP

QuestDB supports both STRING columns and SYMBOL column types.

To understand the difference refer to the QuestDB documentation, but in short symbols are interned strings that are most suitable for identifiers that you expect to be repeated throughout the column.

Inserting NULL values

To insert a NULL value, skip the symbol or column for that row.

Recovering from validation errors

If you want to recover from potential validation errors, you can use the set_marker method to track a last known good state, append as many rows or parts of rows as you like and then call clear_marker on success.

If there was an error in one of the table names or other, you can use the rewind_to_marker method to go back to the marked last known good state.

Implementations§

Construct an instance with a max_name_len of 127, which is the same as the QuestDB default.

Construct with a custom maximum length for table and column names.

This should match the cairo.max.file.name.length setting of the QuestDB instance you’re connecting to.

If the server does not configure it the default is 127 and you might as well call new.

Pre-allocate to ensure the buffer has enough capacity for at least the specified additional byte count. This may be rounded up. This does not allocate if such additional capacity is already satisfied. See: capacity.

Number of bytes accumulated in the buffer.

Number of bytes that can be written to the buffer before it needs to resize.

Inspect the contents of the buffer.

Mark a rewind point. This allows undoing accumulated changes to the buffer for one or more rows by calling rewind_to_marker. Any previous marker will be discarded. Once the marker is no longer needed, call clear_marker.

Undo all changes since the last set_marker call.

As a side-effect, this also clears the marker.

Discard any marker as may have been set by set_marker.

Idempodent.

Reset the buffer and clear contents whilst retaining capacity.

Begin recording a row for a given table.

buffer.table("table_name")?;

or

use questdb::ingress::TableName;
 
let table_name = TableName::new("table_name")?;
buffer.table(table_name)?;

Record a symbol for a given column.

buffer.symbol("col_name", "value")?;

or

let value: String = "value".to_owned();
buffer.symbol("col_name", value)?;

or

use questdb::ingress::ColumnName;
 
let col_name = ColumnName::new("col_name")?;
buffer.symbol(col_name, "value")?;

Record a boolean value for a column.

buffer.column_bool("col_name", true)?;

or

use questdb::ingress::ColumnName;
 
let col_name = ColumnName::new("col_name")?;
buffer.column_bool(col_name, true)?;

Record an integer value for a column.

buffer.column_i64("col_name", 42)?;

or

use questdb::ingress::ColumnName;
 
let col_name = ColumnName::new("col_name")?;
buffer.column_i64(col_name, 42);

Record a floating point value for a column.

buffer.column_f64("col_name", 3.14)?;

or

use questdb::ingress::ColumnName;
 
let col_name = ColumnName::new("col_name")?;
buffer.column_f64(col_name, 3.14)?;

Record a string value for a column.

buffer.column_str("col_name", "value")?;

or

let value: String = "value".to_owned();
buffer.column_str("col_name", value)?;

or

use questdb::ingress::ColumnName;
 
let col_name = ColumnName::new("col_name")?;
buffer.column_str(col_name, "value")?;

Record a timestamp for a column.

buffer.column_ts("col_name", std::time::SystemTime::now())?;

or

use questdb::ingress::TimestampMicros;
 
buffer.column_ts("col_name", TimestampMicros::new(1659548204354448)?)?;

or

use questdb::ingress::ColumnName;
 
let col_name = ColumnName::new("col_name")?;
buffer.column_ts(col_name, std::time::SystemTime::now())?;

The timestamp should be in UTC.

Terminate the row with a specified timestamp.

buffer.at(std::time::SystemTime::now())?;

or

use questdb::ingress::TimestampNanos;
 
buffer.at(TimestampNanos::new(1659548315647406592)?)?;

The timestamp should be in UTC.

Terminate the row with a server-specified timestamp.

buffer.at_now()?;

The QuestDB instance will set the timestamp once it receives the row. If you’re flushing infrequently, the timestamp assigned by the server may drift significantly from when the data was recorded in the buffer.

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.