Admin 操作
python
admin = conn.get_admin()数据库
python
await admin.create_database("my_database", ignore_if_exists=True)
databases = await admin.list_databases()
exists = await admin.database_exists("my_database")
await admin.drop_database("my_database", ignore_if_not_exists=True, cascade=True)表
Schema 使用 PyArrow 定义,并包装在 fluss.Schema 中:
python
import pyarrow as pa
schema = fluss.Schema(pa.schema([
pa.field("id", pa.int32()),
pa.field("name", pa.string()),
pa.field("amount", pa.int64()),
]))
table_path = fluss.TablePath("my_database", "my_table")
await admin.create_table(table_path, fluss.TableDescriptor(schema), ignore_if_exists=True)
table_info = await admin.get_table_info(table_path)
tables = await admin.list_tables("my_database")
await admin.drop_table(table_path, ignore_if_not_exists=True)TableDescriptor 选项
TableDescriptor 接受以下可选参数:
| 参数 | 描述 |
|---|---|
partition_keys | 用于分区依据的列名(例如 ["region"]) |
bucket_count | 表的 bucket 数量(并行度单元) |
bucket_keys | 用于决定 bucket 分配的列 |
comment | 表注释 / 描述 |
log_format | Log 存储格式:"ARROW" 或 "INDEXED" |
kv_format | PrimaryKey Table 的 KV 存储格式:"INDEXED" 或 "COMPACTED" |
properties | 表配置属性,以 dict 形式提供(例如 {"table.replication.factor": "1"}) |
custom_properties | 用户自定义属性,以 dict 形式提供 |
Offsets
python
# Latest offsets for buckets
offsets = await admin.list_offsets(table_path, bucket_ids=[0, 1], offset_spec=fluss.OffsetSpec.latest())
# By timestamp
offsets = await admin.list_offsets(table_path, bucket_ids=[0], offset_spec=fluss.OffsetSpec.timestamp(1704067200000))
# Per-partition offsets
offsets = await admin.list_partition_offsets(table_path, partition_name="US", bucket_ids=[0], offset_spec=fluss.OffsetSpec.latest())Lake Snapshot
说明
Lake snapshot 需要在服务端启用 lake 集成(例如 Paimon 或 Iceberg)。若未启用,get_latest_lake_snapshot 会抛出错误。
python
snapshot = await admin.get_latest_lake_snapshot(table_path)
print(f"Snapshot ID: {snapshot.snapshot_id}")
print(f"Table buckets: {snapshot.get_table_buckets()}")
bucket = fluss.TableBucket(table_id=1, bucket=0)
offset = snapshot.get_bucket_offset(bucket)