Skip to content

API 参考 ​

Fluss Rust 客户端完整 API 参考。

Config ​

字段类型默认值说明
bootstrap_serversString"127.0.0.1:9123"Coordinator server 地址
writer_request_max_sizei3210485760 (10 MB)请求最大字节数
writer_acksString"all"确认(ack)设置("all" 表示等待所有副本确认)
writer_retriesi32i32::MAX失败时的重试次数
writer_batch_sizei322097152 (2 MB)写入的批大小(字节)。开启动态大小时为上限;关闭时为固定批大小。
writer_dynamic_batch_size_enabledbooltrue启用按表动态批大小:填充率超过 80% 时目标增长 10%,低于 50% 时缩小 5%,并限制在 [writer_dynamic_batch_size_min, writer_batch_size] 区间内
writer_dynamic_batch_size_mini32262144 (256 KB)动态批大小估算器的下限(当 writer_dynamic_batch_size_enabled 为 false 时忽略)
writer_batch_timeout_msi64100等待 writer 批填满后发送的最长时间(毫秒)
writer_bucket_no_key_assignerNoKeyAssignersticky无 bucket key 的表的 bucket 分配策略:sticky 或 round_robin
writer_dynamic_create_partition_enabledbooltrue写入时自动创建尚不存在的分区。为 false 时,此类写入以 PartitionNotExists 失败
scanner_remote_log_prefetch_numusize4预取的远程 log segment 数量
remote_file_download_thread_numusize3远程 log 下载的线程数
scanner_remote_log_read_concurrencyusize4单个远程 log 文件内的流式读取并发度
scanner_io_tmp_dirOption<String>None远程日志下载的父目录;None 表示使用操作系统临时目录加 /fluss
scanner_log_max_poll_recordsusize500单次 poll() 返回的最大记录数
scanner_log_fetch_max_bytesi3216777216 (16 MB)LogScanner 每次 fetch 响应的最大字节数
scanner_log_fetch_min_bytesi321服务端返回 fetch 响应前必须累积的最小字节数
scanner_log_fetch_wait_max_time_msi32500服务端为满足最小字节数可等待的最长时间(毫秒)
scanner_log_fetch_max_bytes_for_bucketi321048576 (1 MB)LogScanner 每个 bucket 每次 fetch 响应的最大字节数
scanner_log_check_crcbooltrue检查所拉取日志批次的 CRC,损坏的批次会导致扫描失败。服务端投影(projected)的批次不检查
lookup_queue_sizeusize25600发送队列容量;队列满时新的 lookup 会等待。每个 bucket 在等待 leader 期间也最多容纳这么多个 lookup;超出该 bucket 的 lookup 会立即因缓冲区耗尽错误而失败
lookup_max_batch_sizeusize128合并到单个请求中的 lookup 最大数量
lookup_batch_timeout_msu64100lookup 等待批次填满的最大时间(毫秒)
lookup_max_inflight_requestsusize128未确认 lookup 请求的最大数量
lookup_max_retriesi32i32::MAXlookup 因可重试错误而重发的最大次数。等待 bucket 的 leader 不算重试,因此这不是 lookup 超时
lookup_retry_backoff_msu64100因可重试错误而失败的 lookup 重发前的初始延迟(毫秒),该 lookup 每次重试都会翻倍;也是无已知 leader 的 bucket 再次刷新前的延迟,该 bucket 每次刷新都会翻倍并由其 lookup 共享。±20% 抖动;0 表示立即重发和刷新
lookup_retry_max_backoff_msu641000lookup 重试延迟与无已知 leader 的 bucket 刷新延迟的上限(毫秒),在抖动之前生效;必须 >= lookup_retry_backoff_ms
connect_timeout_msu6415000连接建立超时(毫秒),包括 TCP 连接、API 协商和 SASL 认证
connection_max_idle_time_msu64600000 (10 min)空闲的缓存连接在该毫秒数之后被关闭,仍在等待这些连接的请求会以可重试错误失败;0 表示禁用关闭空闲连接
security_protocolString"PLAINTEXT"用于 SASL 认证的 PLAINTEXT(默认)或 sasl
security_sasl_mechanismString"PLAIN"SASL 机制(仅支持 PLAIN)
security_sasl_usernameString(空)SASL 用户名(协议为 sasl 时必填)
security_sasl_passwordString(空)SASL 密码(协议为 sasl 时必填)

FlussConnection ​

方法说明
async fn new(config: Config) -> Result<Self>创建到 Fluss 集群的新连接
fn get_admin(&self) -> Result<Arc<FlussAdmin>>获取用于集群管理的 admin 接口
async fn get_table(&self, table_path: &TablePath) -> Result<FlussTable<'_>>获取用于读写的表
fn config(&self) -> &Config获取连接配置的引用

FlussAdmin ​

数据库操作 ​

方法说明
async fn create_database(&self, name: &str, descriptor: Option<&DatabaseDescriptor>, ignore_if_exists: bool) -> Result<()>创建数据库
async fn drop_database(&self, name: &str, ignore_if_not_exists: bool, cascade: bool) -> Result<()>删除数据库
async fn list_databases(&self) -> Result<Vec<String>>列出所有数据库
async fn database_exists(&self, name: &str) -> Result<bool>检查数据库是否存在
async fn get_database_info(&self, name: &str) -> Result<DatabaseInfo>获取数据库元数据

表操作 ​

方法说明
async fn create_table(&self, table_path: &TablePath, descriptor: &TableDescriptor, ignore_if_exists: bool) -> Result<()>创建表
async fn drop_table(&self, table_path: &TablePath, ignore_if_not_exists: bool) -> Result<()>删除表
async fn get_table_info(&self, table_path: &TablePath) -> Result<TableInfo>获取表元数据
async fn get_table_schema(&self, table_path: &TablePath, schema_id: Option<i32>) -> Result<SchemaInfo>按 id 获取表的 schema,当 schema_id 为 None 时获取最新 schema
async fn list_tables(&self, database_name: &str) -> Result<Vec<String>>列出数据库中的表
async fn table_exists(&self, table_path: &TablePath) -> Result<bool>检查表是否存在

分区操作 ​

方法说明
async fn list_partition_infos(&self, table_path: &TablePath) -> Result<Vec<PartitionInfo>>列出所有分区
async fn list_partition_infos_with_spec(&self, table_path: &TablePath, spec: Option<&PartitionSpec>) -> Result<Vec<PartitionInfo>>列出匹配某个 spec 的分区
async fn create_partition(&self, table_path: &TablePath, spec: &PartitionSpec, ignore_if_exists: bool) -> Result<()>创建分区
async fn drop_partition(&self, table_path: &TablePath, spec: &PartitionSpec, ignore_if_not_exists: bool) -> Result<()>删除分区

位点操作 ​

方法说明
async fn list_offsets(&self, table_path: &TablePath, bucket_ids: &[i32], offset_spec: OffsetSpec) -> Result<HashMap<i32, i64>>获取 bucket 的 offset
async fn list_partition_offsets(&self, table_path: &TablePath, partition_name: &str, bucket_ids: &[i32], offset_spec: OffsetSpec) -> Result<HashMap<i32, i64>>获取某个分区各 bucket 的 offset

Lake 操作 ​

方法说明
async fn get_latest_lake_snapshot(&self, table_path: &TablePath) -> Result<LakeSnapshot>获取最新的 lake snapshot

集群操作 ​

方法说明
async fn get_server_nodes(&self) -> Result<Vec<ServerNode>>获取所有存活的 server node(coordinator + tablets)

ServerNode ​

方法说明
fn id(&self) -> i32Server node ID
fn host(&self) -> &str服务器主机名
fn port(&self) -> u32端口号
fn server_type(&self) -> &ServerTypeServer 类型(CoordinatorServer、TabletServer 或 Unknown)
fn uid(&self) -> &str唯一标识符(如 "cs-0"、"ts-1")

当客户端尚未确定 endpoint 类型时(例如 bootstrap endpoint),会使用 ServerType::Unknown。

FlussTable<'a> ​

方法说明
fn get_table_info(&self) -> &TableInfo获取表元数据
fn new_append(&self) -> Result<TableAppend>为 log table 创建 append builder
fn new_scan(&self) -> TableScan<'_>创建 scan builder
fn new_lookup(&self) -> Result<TableLookup>为 PK table 创建 lookup builder
fn new_upsert(&self) -> Result<TableUpsert>为 PK table 创建 upsert builder
fn has_primary_key(&self) -> bool检查表是否有 primary key
fn table_path(&self) -> &TablePath获取表路径

TableAppend ​

方法说明
fn create_writer(&self) -> Result<AppendWriter>创建 append writer

AppendWriter ​

方法说明
fn append(&self, row: &impl InternalRow) -> Result<WriteResultFuture>追加一行;返回用于确认的 future
fn append_arrow_batch(&self, batch: RecordBatch) -> Result<WriteResultFuture>追加一个 Arrow RecordBatch
async fn flush(&self) -> Result<()>将所有待处理的写入 flush 到服务端

Writer 管道会发出 fluss.client.writer.* 指标(发送延迟、批次排队时间、发送的 records/字节数、重试次数、每批大小以及 buffer pool 的 gauge)。与 scanner 指标不同,这些指标是无标签的(每个进程全局一份),与 Java 中每个客户端单个 WriterMetricGroup 一致(Java 仅按 client_id 划分,而 Rust 的 metrics facade 目前还没有这一概念)。AppendWriter(log table)与 UpsertWriter(PK table)共享同一组序列。

TableScan<'a> ​

方法说明
fn project(self, indices: &[usize]) -> Result<Self>按索引投影列
fn project_by_name(self, names: &[&str]) -> Result<Self>按名称投影列
fn limit(self, n: i32) -> Result<Self>设置行数上限(启用 create_bucket_batch_scanner;会被 log scanner 拒绝)
fn create_log_scanner(self) -> Result<LogScanner>创建基于记录的 log scanner;在 primary key table 上会订阅其 CDC changelog(每条记录带 ChangeType)
fn create_record_batch_log_scanner(self) -> Result<RecordBatchLogScanner>创建基于 Arrow 批次的 log scanner(仅限 log table——不提供逐记录的 change type)
fn create_bucket_batch_scanner(self, bucket: TableBucket) -> Result<LimitBatchScanner>对单个 bucket 的有界扫描(需要先调用 limit;在首次 next_batch 时执行)

LogScanner ​

单消费者:不要在同一个 scanner 上并发调用 poll(例如在 tokio::join! 中,或由两个共享同一 Arc 的 task 调用)。这与 Java 的 LogScannerImpl.acquire() 守卫一致。Debug 构建会通过 debug_assert! 暴露重叠调用;Release 构建出于性能考虑跳过检查,若违反该约定,会产生有偏差的 poll 计时指标(fluss.client.scanner.time_between_poll_ms、fluss.client.scanner.poll_idle_ratio)。

所有 fluss.client.scanner.* 指标都带有 database 和 table 标签(与 Java 中按 TablePath 划分的 ScannerMetricGroup 一致),因此多表消费者会为每张被扫描的表得到一条时间序列。

方法说明
async fn subscribe(&self, bucket_id: i32, start_offset: i64) -> Result<()>订阅一个 bucket
async fn subscribe_buckets(&self, bucket_offsets: &HashMap<i32, i64>) -> Result<()>订阅多个 bucket
async fn subscribe_partition(&self, partition_id: i64, bucket_id: i32, start_offset: i64) -> Result<()>订阅一个 partition bucket
async fn subscribe_partition_buckets(&self, offsets: &HashMap<(i64, i32), i64>) -> Result<()>订阅多个 partition-bucket 对
async fn unsubscribe(&self, bucket_id: i32) -> Result<()>取消订阅一个 bucket(非分区表)
async fn unsubscribe_partition(&self, partition_id: i64, bucket_id: i32) -> Result<()>取消订阅一个 partition bucket(分区表)
async fn poll(&self, timeout: Duration) -> Result<ScanRecords>轮询记录

RecordBatchLogScanner ​

单消费者:不支持在共享状态的 handle 上重叠调用 poll,也不支持 poll 与 RecordBatchLogReader::next_batch 并发——对每个底层 scanner 状态,一次只应有一个活跃的轮询/消费调用。这与 Java 的 LogScannerImpl.acquire() 守卫一致。Debug 构建会通过 debug_assert! 暴露重叠调用;Release 构建出于性能考虑跳过检查,若违反该约定,会产生有偏差的 poll 计时指标(fluss.client.scanner.time_between_poll_ms、fluss.client.scanner.poll_idle_ratio)。

方法说明
async fn subscribe(&self, bucket_id: i32, start_offset: i64) -> Result<()>订阅一个 bucket
async fn subscribe_buckets(&self, bucket_offsets: &HashMap<i32, i64>) -> Result<()>订阅多个 bucket
async fn subscribe_partition(&self, partition_id: i64, bucket_id: i32, start_offset: i64) -> Result<()>订阅一个 partition bucket
async fn subscribe_partition_buckets(&self, offsets: &HashMap<(i64, i32), i64>) -> Result<()>订阅多个 partition-bucket 对
async fn unsubscribe(&self, bucket_id: i32) -> Result<()>取消订阅一个 bucket(非分区表)
async fn unsubscribe_partition(&self, partition_id: i64, bucket_id: i32) -> Result<()>取消订阅一个 partition bucket(分区表)
async fn poll(&self, timeout: Duration) -> Result<Vec<ScanBatch>>轮询 Arrow record batch
fn is_partitioned(&self) -> bool检查表是否为分区表
fn get_subscribed_buckets(&self) -> Vec<(TableBucket, i64)>以 (bucket, offset) 对的形式获取当前所有订阅
fn schema(&self) -> SchemaRef获取此 scanner 产出的批次的 Arrow schema
fn table_path(&self) -> &TablePath获取表路径
fn table_id(&self) -> TableId获取表 ID

RecordBatchLogReader ​

有界 log reader,消费数据到指定的停止 offset 后终止。与无限轮询的 RecordBatchLogScanner 不同,该 reader 会自动停止。

方法说明
async fn new_until_latest(scanner: RecordBatchLogScanner, admin: &FlussAdmin) -> Result<Self>读取到创建时刻的最新 offset 为止
fn new_until_offsets(scanner: RecordBatchLogScanner, stopping_offsets: HashMap<TableBucket, i64>) -> Result<Self>读取到每个 bucket 的自定义停止 offset 为止
async fn next_batch(&mut self) -> Result<Option<ScanBatch>>获取下一个带 bucket/offset 元数据的批次;当所有 bucket 都追平后返回 None
async fn collect_all_batches(&mut self) -> Result<Vec<ScanBatch>>排空所有批次(含元数据),直到满足停止 offset
fn schema(&self) -> SchemaRef产出批次的 Arrow schema
fn to_record_batch_reader(self, handle: tokio::runtime::Handle) -> SyncRecordBatchLogReader实现 arrow::RecordBatchReader 的同步适配器(见下文)

SyncRecordBatchLogReader ​

RecordBatchLogReader 的同步适配器。可通过 RecordBatchLogReader::to_record_batch_reader(handle) 创建。

它同时实现了 [Iterator] 和 [arrow::record_batch::RecordBatchReader],因此可以接入更广泛的 Arrow 生态——FFI、PyArrow 的 pa.RecordBatchReader.from_batches、C++ Arrow 的 RecordBatchReader 接口、DataFusion source 等。

每次调用 next() 都会通过 tokio::runtime::Handle::block_on 驱动底层的异步 reader。不要在属于同一 runtime 的 Tokio worker 线程内调用——嵌套 block_on 会 panic。在异步 Rust 代码中优先使用 RecordBatchLogReader::next_batch;仅在同步/FFI 边界使用此适配器。

ScanBatch 携带的 bucket 与 offset 元数据在此处会被丢弃,因为 Arrow trait 约定只产出普通的 RecordBatch。如果你需要每个批次的 offset 或 bucket 标识,请改用 next_batch。

方法说明
fn next(&mut self) -> Option<Result<RecordBatch, ArrowError>>Iterator:下一批;追平后返回 None
fn schema(&self) -> SchemaRef产出批次的 Arrow schema

LimitBatchScanner ​

由 TableScan::limit(n).create_bucket_batch_scanner(bucket) 创建的一次性有界 scanner。用 next_batch 轮询它,直到返回 None(与 RecordBatchLogReader 类似)。同时支持 log table 和 primary key table(后者返回服务端去重后的当前状态);产出单个批次,最多包含 n 行。

方法说明
async fn next_batch(&mut self) -> Result<Option<ScanBatch>>首次调用返回行数据,之后返回 None
async fn collect_all_batches(&mut self) -> Result<Vec<ScanBatch>>排空为所有批次
fn bucket(&self) -> &TableBucket被扫描的 bucket

ScanRecord ​

方法说明
fn row(&self) -> &dyn InternalRow获取行数据
fn offset(&self) -> i64记录在 log 中的 offset
fn timestamp(&self) -> i64记录时间戳
fn change_type(&self) -> &ChangeTypeChange type(AppendOnly、Insert 等)

ChangeType ​

ScanRecord 所表示的变更种类。Log(append-only)表始终产生 AppendOnly;扫描 primary key table 的 changelog 会产生下述 CDC 变体。

变体符号含义
AppendOnly+A仅追加记录(log table)
Insert+I插入了一个新的 primary key
UpdateBefore-U更新之前的行镜像
UpdateAfter+U更新之后的行镜像
Delete-D删除某个 primary key(携带旧行)

在默认的 FULL changelog 模式下(table.changelog.image),更新已有 key 会先发出 -U 再发出 +U;WAL 模式只发出 +U。

ScanRecords ​

方法说明
fn count(&self) -> usize记录数量
fn is_empty(&self) -> bool结果集是否为空
fn records(&self, bucket: &TableBucket) -> &[ScanRecord]获取某个 bucket 的记录
fn records_by_buckets(&self) -> &HashMap<TableBucket, Vec<ScanRecord>>获取按 bucket 分组的所有记录

ScanRecords 还实现了 IntoIterator,因此可以直接遍历所有记录:

rust
for record in records {
    println!("offset={}", record.offset());
}

ScanBatch ​

方法说明
fn bucket(&self) -> &TableBucket此批次所属的 bucket
fn batch(&self) -> &RecordBatchArrow RecordBatch 数据
fn base_offset(&self) -> i64第一条记录的 offset
fn last_offset(&self) -> i64最后一条记录的 offset
fn commit_timestamp(&self) -> i64提交时间(毫秒时间戳)
fn schema_id(&self) -> i32来源 log batch 的 Schema ID
fn num_records(&self) -> usize批次中的记录数

commit_timestamp 在该 batch 不携带单一时间戳时为 fluss::record::NO_COMMIT_TIMESTAMP(-1);limit scan 会将多个 log batch 合并为一个 Arrow batch,因此属于这种情况。

schema_id 是写入该 log batch 时所用 schema 的 ID。它可能与 batch 各列所属的 schema 不同,因为默认情况下 scanner 会将每个 batch 对齐到创建它时所使用的表 schema。对于 limit scan,它为 fluss::record::NO_SCHEMA_ID(-1);limit scan 会将多个 log batch 合并为一个 batch。

TableUpsert ​

方法说明
fn create_writer(&self) -> Result<UpsertWriter>创建 upsert writer
fn partial_update(&self, column_indices: Option<Vec<usize>>) -> Result<TableUpsert>按列索引创建 partial update builder
fn partial_update_with_column_names(&self, names: &[&str]) -> Result<TableUpsert>按列名创建 partial update builder

UpsertWriter ​

方法说明
fn upsert(&self, row: &impl InternalRow) -> Result<WriteResultFuture>Upsert 一行(按 PK 插入或更新)
fn delete(&self, row: &impl InternalRow) -> Result<WriteResultFuture>按 primary key 删除一行
async fn flush(&self) -> Result<()>Flush 所有待处理操作

TableLookup ​

方法说明
fn create_lookuper(&self) -> Result<Lookuper>为点查创建 lookuper

Lookuper ​

方法说明
async fn lookup(&self, key: &impl InternalRow) -> Result<LookupResult>按 primary key 查找一行

当 lookup 所在 bucket 没有已知 leader 时,客户端会在刷新该 bucket 元数据的同时等待,并按 lookup_retry_backoff_ms 退避。每个 bucket 最多有 lookup_queue_size 个 lookup 等待;超出的会直接以 Error::BufferExhausted 失败。若表被删除或重建,等待中的 lookup 会以 API 错误 TableNotExist 失败;若分区被删除,则以 PartitionNotExists 失败;若客户端无权访问表的元数据,则以 AuthorizationException 失败。凭据或 API 版本被拒绝同样会导致失败;其他刷新错误(例如 schema 尚不可见,或服务端在 30 秒内未响应元数据请求)会让它继续等待。向已关闭客户端发起的 lookup、关闭时最后一次刷新后仍无 leader 的 lookup,以及关闭超时后仍未完成的 lookup,都会以 Error::LookupClosed 失败。

LookupResult ​

方法说明
fn get_single_row(&self) -> Result<Option<impl InternalRow>>从结果中获取单行
fn get_rows(&self) -> Result<Vec<impl InternalRow>>从结果中获取所有行
fn to_record_batch(&self) -> Result<RecordBatch>将所有行转换为 Arrow RecordBatch,供 DataFusion 或其他基于 Arrow 的工具使用

WriteResultFuture ​

说明
实现了 Future<Output = Result<(), Error>>。await 可等待服务端确认。由 append()、upsert() 和 delete() 返回。

用法:

rust
// Fire-and-forget (batched)
writer.append(&row)?;
writer.flush().await?;

// Per-record acknowledgment
writer.append(&row)?.await?;

Schema ​

方法说明
fn builder() -> SchemaBuilder创建 schema builder
fn columns(&self) -> &[Column]获取所有列
fn primary_key(&self) -> Option<&PrimaryKey>获取 primary key(无 primary key 时为 None)
fn column_names(&self) -> Vec<&str>获取所有列名
fn primary_key_indexes(&self) -> Vec<usize>获取 primary key 列索引

SchemaBuilder ​

方法说明
fn column(name: &str, data_type: DataType) -> Self添加一列
fn primary_key(keys: Vec<&str>) -> Self设置 primary key 列
fn build() -> Result<Schema>构建 schema

SchemaInfo ​

schema 及其由服务端分配的版本 id。由 FlussAdmin::get_table_schema 返回。

方法说明
fn new(schema: Schema, schema_id: i32) -> Self由 schema 和 id 构造
fn schema(&self) -> &Schema借用 schema
fn schema_id(&self) -> i32获取服务端分配的 schema id
fn into_parts(self) -> (Schema, i32)消费并返回 (schema, schema_id)

TableDescriptor ​

方法说明
fn builder() -> TableDescriptorBuilder创建 table descriptor builder
fn schema(&self) -> &Schema获取表 schema
fn partition_keys(&self) -> &[String]获取分区键列名
fn has_primary_key(&self) -> bool检查表是否有 primary key
fn properties(&self) -> &HashMap<String, String>获取所有表属性
fn custom_properties(&self) -> &HashMap<String, String>获取自定义属性
fn comment(&self) -> Option<&str>获取表注释

TableDescriptorBuilder ​

方法说明
fn schema(schema: Schema) -> Self设置 schema
fn log_format(format: LogFormat) -> Self设置 log format(例如 LogFormat::ARROW)
fn kv_format(format: KvFormat) -> Self设置 KV format(例如 KvFormat::COMPACTED)
fn property(key: &str, value: &str) -> Self设置表属性
fn custom_property(key: impl Into<String>, value: impl Into<String>) -> Self设置单个自定义属性
fn custom_properties(properties: HashMap<impl Into<String>, impl Into<String>>) -> Self设置自定义属性
fn partitioned_by(keys: Vec<&str>) -> Self设置分区列
fn distributed_by(bucket_count: Option<i32>, bucket_keys: Vec<String>) -> Self设置 bucket 分布
fn comment(comment: &str) -> Self设置表注释
fn build() -> Result<TableDescriptor>构建 table descriptor

TablePath ​

方法说明
TablePath::new(database: &str, table: &str) -> Self创建表路径
fn database(&self) -> &str获取数据库名
fn table(&self) -> &str获取表名

TableInfo ​

字段 / 方法说明
.table_pathTablePath —— 表路径
.table_idi64 —— 表 ID
.schema_idi32 —— Schema ID
.schemaSchema —— 表 schema
.primary_keysVec<String> —— primary key 列名
.partition_keysVec<String> —— 分区键列名
.num_bucketsi32 —— bucket 数量
.propertiesHashMap<String, String> —— 所有表属性
.custom_propertiesHashMap<String, String> —— 仅自定义属性
.commentOption<String> —— 表注释
.created_timei64 —— 创建时间戳
.modified_timei64 —— 最后修改时间戳

TableBucket ​

方法说明
TableBucket::new(table_id: i64, bucket_id: i32) -> Self创建非分区 bucket
TableBucket::new_with_partition(table_id: i64, partition_id: Option<i64>, bucket_id: i32) -> Self创建分区 bucket
fn table_id(&self) -> i64获取表 ID
fn partition_id(&self) -> Option<i64>获取 partition ID(非分区时为 None)
fn bucket_id(&self) -> i32获取 bucket ID

PartitionSpec ​

方法说明
PartitionSpec::new(spec_map: HashMap<&str, &str>) -> Self由分区列名到值的映射创建
fn get_spec_map(&self) -> &HashMap<String, String>获取 partition spec 映射

PartitionInfo ​

方法说明
fn get_partition_id(&self) -> i64获取 partition ID
fn get_partition_name(&self) -> String获取 partition 名称
fn get_bucket_count(&self) -> i32获取分区的 bucket 数

DatabaseDescriptor ​

方法说明
fn builder() -> DatabaseDescriptorBuilder创建 database descriptor builder
fn comment(&self) -> Option<&str>获取数据库注释
fn custom_properties(&self) -> &HashMap<String, String>获取自定义属性

DatabaseDescriptorBuilder ​

方法说明
fn comment(comment: impl Into<String>) -> Self设置数据库注释
fn custom_properties(properties: HashMap<impl Into<String>, impl Into<String>>) -> Self设置自定义属性
fn custom_property(key: impl Into<String>, value: impl Into<String>) -> Self设置单个自定义属性
fn build() -> DatabaseDescriptor构建 database descriptor

DatabaseInfo ​

方法说明
fn database_name(&self) -> &str获取数据库名
fn created_time(&self) -> i64获取创建时间戳
fn modified_time(&self) -> i64获取最后修改时间戳
fn database_descriptor(&self) -> &DatabaseDescriptor获取 database descriptor

LakeSnapshot ​

字段说明
.snapshot_idi64 —— 快照 ID
.table_buckets_offsetHashMap<TableBucket, i64> —— 所有 bucket 的 offset

GenericRow<'a> ​

方法说明
GenericRow::new(field_count: usize) -> Self创建具有指定字段数的新 Row
fn set_field(&mut self, pos: usize, value: impl Into<Datum<'a>>)按位置设置字段值
GenericRow::from_data(data: Vec<impl Into<Datum<'a>>>) -> Self从已有字段数据创建 Row

实现了 InternalRow trait(见下文)。

InternalRow trait ​

方法说明
fn is_null_at(&self, idx: usize) -> Result<bool>检查字段是否为 null
fn get_boolean(&self, idx: usize) -> Result<bool>获取 boolean 值
fn get_byte(&self, idx: usize) -> Result<i8>获取 tinyint 值
fn get_short(&self, idx: usize) -> Result<i16>获取 smallint 值
fn get_int(&self, idx: usize) -> Result<i32>获取 int 值
fn get_long(&self, idx: usize) -> Result<i64>获取 bigint 值
fn get_float(&self, idx: usize) -> Result<f32>获取 float 值
fn get_double(&self, idx: usize) -> Result<f64>获取 double 值
fn get_string(&self, idx: usize) -> Result<&str>获取 string 值
fn get_decimal(&self, idx: usize, precision: usize, scale: usize) -> Result<Decimal>获取 decimal 值
fn get_date(&self, idx: usize) -> Result<Date>获取 date 值
fn get_time(&self, idx: usize) -> Result<Time>获取 time 值
fn get_timestamp_ntz(&self, idx: usize, precision: u32) -> Result<TimestampNtz>获取 timestamp 值
fn get_timestamp_ltz(&self, idx: usize, precision: u32) -> Result<TimestampLtz>获取带本地时区的 timestamp 值
fn get_bytes(&self, idx: usize) -> Result<&[u8]>获取 bytes 值
fn get_binary(&self, idx: usize, length: usize) -> Result<&[u8]>获取固定长度 binary 值
fn get_char(&self, idx: usize, length: usize) -> Result<&str>获取固定长度 char 值
fn get_array(&self, idx: usize) -> Result<ArrayView<'_>>获取 array 值(零拷贝视图)
fn get_map(&self, idx: usize) -> Result<MapView<'_>>获取 map 值(零拷贝视图)
fn get_row(&self, idx: usize) -> Result<RowView<'_>>获取嵌套 row 值(零拷贝视图)

嵌套 getter 返回借用视图——ArrayView、MapView、RowView。可直接通过 DataGetters 访问器读取元素,或调用 try_into_binary()(对 row 则用 try_into_generic())获取拥有所有权的二进制形式。

ArrayView<'a> ​

由 get_array() 返回。实现了 InternalArray + DataGetters,因此可以通过类型化 getter(get_int()、get_string()、嵌套的 get_array() / get_map() 等)原地读取元素。

方法说明
fn try_into_binary(self) -> Result<FlussArray>物化出拥有的二进制 FlussArray,如有需要会重新编码列式切片

MapView<'a> ​

由 get_map() 返回。实现了 InternalMap。

方法说明
fn try_into_binary(self) -> Result<FlussMap>物化出拥有的二进制 FlussMap,如有需要会重新编码列式切片

RowView<'a> ​

由 get_row() 返回。实现了 InternalRow,因此可以通过类型化 getter 原地读取嵌套字段。

方法说明
fn try_into_generic(self, row_type: &RowType) -> Result<GenericRow<'static>>物化出拥有的 GenericRow,如有需要会逐字段遍历列式游标

FlussArray ​

FlussArray 是 ARRAY 值拥有所有权的二进制 Row 表示。可通过 ArrayView::try_into_binary() 获取。

方法说明
fn size(&self) -> usize数组中元素的数量
fn is_null_at(&self, pos: usize) -> bool检查某个元素是否为 null
fn as_bytes(&self) -> &[u8]获取数组的编码字节

元素 getter 与 InternalRow 的类型化 getter 对应,返回 Result<T>。例如,对基本类型元素使用 get_int()、get_long() 和 get_double(),对变长或嵌套元素使用 get_string()、get_binary()、get_decimal()、get_timestamp_ntz()、get_timestamp_ltz() 和 get_array()。

FlussMap ​

FlussMap 是 MAP 值拥有所有权的二进制 Row 表示。可通过 MapView::try_into_binary() 获取。

方法说明
fn size(&self) -> usizemap 中 entry 的数量
fn as_bytes(&self) -> &[u8]获取 map 的编码字节
fn key_type(&self) -> &DataTypeschema 声明的 key 类型
fn value_type(&self) -> &DataTypeschema 声明的 value 类型
fn entries(&self) -> Entries<'_>产出 Result<(Datum, Datum)> 对的迭代器
fn get(&self, key: &Datum) -> Result<Option<Datum>>按键线性扫描查找(O(n))
fn key_array(&self) -> &FlussArray并行的 key 数组(零拷贝视图)
fn value_array(&self) -> &FlussArray并行的 value 数组(零拷贝视图)

大多数用户代码应优先使用 entries()(迭代)和 get()(查找)。key_array() / value_array() 视图面向需要对底层并行数组布局进行零拷贝访问的 serdes 和 Arrow 适配器代码。

FlussMapWriter ​

FlussMapWriter 用于在写入路径上构建 FlussMap。

方法说明
fn new(capacity: usize, key_type: &DataType, value_type: &DataType) -> Self创建容量为 capacity 个 entry 的 writer
fn write_entry(&mut self, key: Datum, value: Datum) -> Result<()>追加单个 entry;拒绝 null key 和类型不匹配
fn extend<I, K, V>(&mut self, entries: I) -> Result<()>追加 entries: IntoIterator<Item = (K, V)> 中的每一对
fn complete(self) -> Result<FlussMap>完成 writer 并产出 FlussMap

ChangeType ​

值短字符串说明
ChangeType::AppendOnly+A仅追加记录
ChangeType::Insert+I插入的行
ChangeType::UpdateBefore-U更新行的旧值
ChangeType::UpdateAfter+U更新行的新值
ChangeType::Delete-D删除的行
方法说明
fn short_string(&self) -> &str获取短字符串表示

OffsetSpec ​

变体说明
OffsetSpec::Earliest从最早可用的 offset 开始
OffsetSpec::Latest从最新 offset 开始(仅新记录)
OffsetSpec::Timestamp(i64)从指定时间戳(毫秒)开始

常量 ​

常量值说明
fluss::client::EARLIEST_OFFSET-2从最早可用的 offset 开始读取

若要从最新 offset 开始读取(仅新记录),请在订阅前通过 list_offsets 解析当前 offset:

rust
use fluss::rpc::message::OffsetSpec;

let offsets = admin.list_offsets(&table_path, &[0], OffsetSpec::Latest).await?;
let latest = offsets[&0];
log_scanner.subscribe(0, latest).await?;

DataTypes 工厂 ​

方法返回说明
DataTypes::boolean()DataTypeBoolean 类型
DataTypes::tinyint()DataType8 位有符号整数
DataTypes::smallint()DataType16 位有符号整数
DataTypes::int()DataType32 位有符号整数
DataTypes::bigint()DataType64 位有符号整数
DataTypes::float()DataType32 位浮点数
DataTypes::double()DataType64 位浮点数
DataTypes::string()DataType变长字符串
DataTypes::bytes()DataType变长字节数组
DataTypes::date()DataTypeDate(自 epoch 起的天数)
DataTypes::time()DataTypeTime(自午夜起的毫秒数)
DataTypes::timestamp()DataType不带时区的 timestamp
DataTypes::timestamp_ltz()DataType带本地时区的 timestamp
DataTypes::decimal(precision: u32, scale: u32)DataType定点 decimal
DataTypes::char(length: u32)DataType定长字符串
DataTypes::binary(length: usize)DataType定长字节数组
DataTypes::array(element: DataType)DataType元素数组
DataTypes::map(key: DataType, value: DataType)DataType键值对 map
DataTypes::row(fields: Vec<DataField>)DataType嵌套 row 类型

DataField ​

方法说明
DataField::new(name: impl Into<String>, data_type: DataType, description: Option<String>) -> DataField创建 data field
fn name(&self) -> &str获取字段名

Fluss 中文文档