Skip to content

Commit 703c1d0

Browse files
Add missing custom properties method and doc for table descriptor builder in C++. Add assertion for custom property in integration test.
1 parent eaadb3f commit 703c1d0

7 files changed

Lines changed: 61 additions & 11 deletions

File tree

bindings/cpp/include/fluss.hpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ struct TableDescriptor {
376376
int32_t bucket_count{0};
377377
std::vector<std::string> bucket_keys;
378378
std::unordered_map<std::string, std::string> properties;
379+
std::unordered_map<std::string, std::string> custom_properties;
379380
std::string comment;
380381

381382
class Builder {
@@ -405,6 +406,21 @@ struct TableDescriptor {
405406
return *this;
406407
}
407408

409+
Builder& SetCustomProperty(std::string key, std::string value) {
410+
custom_properties_[std::move(key)] = std::move(value);
411+
return *this;
412+
}
413+
414+
Builder& SetLogFormat(std::string format) {
415+
properties_["table.log.format"] = std::move(format);
416+
return *this;
417+
}
418+
419+
Builder& SetKvFormat(std::string format) {
420+
properties_["table.kv.format"] = std::move(format);
421+
return *this;
422+
}
423+
408424
Builder& SetComment(std::string comment) {
409425
comment_ = std::move(comment);
410426
return *this;
@@ -413,7 +429,8 @@ struct TableDescriptor {
413429
TableDescriptor Build() {
414430
return TableDescriptor{std::move(schema_), std::move(partition_keys_),
415431
bucket_count_, std::move(bucket_keys_),
416-
std::move(properties_), std::move(comment_)};
432+
std::move(properties_), std::move(custom_properties_),
433+
std::move(comment_)};
417434
}
418435

419436
private:
@@ -422,6 +439,7 @@ struct TableDescriptor {
422439
int32_t bucket_count_{0};
423440
std::vector<std::string> bucket_keys_;
424441
std::unordered_map<std::string, std::string> properties_;
442+
std::unordered_map<std::string, std::string> custom_properties_;
425443
std::string comment_;
426444
};
427445

bindings/cpp/src/ffi_converter.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,15 @@ inline ffi::FfiTableDescriptor to_ffi_table_descriptor(const TableDescriptor& de
195195
}
196196
ffi_desc.properties = std::move(props);
197197

198+
rust::Vec<ffi::HashMapValue> custom_props;
199+
for (const auto& [k, v] : desc.custom_properties) {
200+
ffi::HashMapValue prop;
201+
prop.key = rust::String(k);
202+
prop.value = rust::String(v);
203+
custom_props.push_back(prop);
204+
}
205+
ffi_desc.custom_properties = std::move(custom_props);
206+
198207
ffi_desc.comment = rust::String(desc.comment);
199208

200209
return ffi_desc;

bindings/cpp/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ mod ffi {
7676
bucket_count: i32,
7777
bucket_keys: Vec<String>,
7878
properties: Vec<HashMapValue>,
79+
custom_properties: Vec<HashMapValue>,
7980
comment: String,
8081
}
8182

bindings/cpp/src/types.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ pub fn ffi_descriptor_to_core(
156156
builder = builder.property(&prop.key, &prop.value);
157157
}
158158

159+
for prop in &descriptor.custom_properties {
160+
builder = builder.custom_property(&prop.key, &prop.value);
161+
}
162+
159163
if !descriptor.comment.is_empty() {
160164
builder = builder.comment(&descriptor.comment);
161165
}

crates/fluss/tests/integration/admin.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ mod admin_test {
143143
.property("table.replication.factor", "1")
144144
.log_format(LogFormat::ARROW)
145145
.kv_format(KvFormat::INDEXED)
146+
.custom_property("owner", "test-suite")
147+
.custom_property("env", "integration")
146148
.build()
147149
.expect("Failed to build table descriptor");
148150

@@ -206,6 +208,18 @@ mod admin_test {
206208
"Properties mismatch"
207209
);
208210

211+
// verify custom properties round-trip
212+
let expected_custom: HashMap<String, String> = [
213+
("owner".to_string(), "test-suite".to_string()),
214+
("env".to_string(), "integration".to_string()),
215+
]
216+
.into();
217+
assert_eq!(
218+
table_info.get_custom_properties(),
219+
&expected_custom,
220+
"Custom properties mismatch"
221+
);
222+
209223
// drop table
210224
admin
211225
.drop_table(&table_path, false)

website/docs/user-guide/cpp/api-reference.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -285,15 +285,18 @@ When using `table.NewRow()`, the `Set()` method auto-routes to the correct type
285285

286286
## `TableDescriptor::Builder`
287287

288-
| Method | Description |
289-
|-----------------------------------------------------------------------------|----------------------------|
290-
| `SetSchema(const Schema& schema) -> Builder&` | Set the table schema |
291-
| `SetPartitionKeys(const std::vector<std::string>& keys) -> Builder&` | Set partition key columns |
292-
| `SetBucketCount(int32_t count) -> Builder&` | Set the number of buckets |
293-
| `SetBucketKeys(const std::vector<std::string>& keys) -> Builder&` | Set bucket key columns |
294-
| `SetProperty(const std::string& key, const std::string& value) -> Builder&` | Set a table property |
295-
| `SetComment(const std::string& comment) -> Builder&` | Set a table comment |
296-
| `Build() -> TableDescriptor` | Build the table descriptor |
288+
| Method | Description |
289+
|-----------------------------------------------------------------------------------|-------------------------------------|
290+
| `SetSchema(const Schema& schema) -> Builder&` | Set the table schema |
291+
| `SetPartitionKeys(const std::vector<std::string>& keys) -> Builder&` | Set partition key columns |
292+
| `SetBucketCount(int32_t count) -> Builder&` | Set the number of buckets |
293+
| `SetBucketKeys(const std::vector<std::string>& keys) -> Builder&` | Set bucket key columns |
294+
| `SetProperty(const std::string& key, const std::string& value) -> Builder&` | Set a table property |
295+
| `SetCustomProperty(const std::string& key, const std::string& value) -> Builder&` | Set a user-defined custom property |
296+
| `SetLogFormat(const std::string& format) -> Builder&` | Set log format (e.g., `"ARROW"`) |
297+
| `SetKvFormat(const std::string& format) -> Builder&` | Set KV format (e.g., `"COMPACTED"`) |
298+
| `SetComment(const std::string& comment) -> Builder&` | Set a table comment |
299+
| `Build() -> TableDescriptor` | Build the table descriptor |
297300

298301
## `DataType`
299302

website/docs/user-guide/rust/api-reference.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,12 +249,13 @@ writer.append(&row)?.await?;
249249

250250
## `TableDescriptorBuilder`
251251

252-
| Method | Description |
252+
| Method | Description |
253253
|----------------------------------------------------------------------------------|---------------------------------------------|
254254
| `fn schema(schema: Schema) -> Self` | Set the schema |
255255
| `fn log_format(format: LogFormat) -> Self` | Set log format (e.g., `LogFormat::ARROW`) |
256256
| `fn kv_format(format: KvFormat) -> Self` | Set KV format (e.g., `KvFormat::COMPACTED`) |
257257
| `fn property(key: &str, value: &str) -> Self` | Set a table property |
258+
| `fn custom_property(key: &str, value: &str) -> Self` | Set a user-defined custom property |
258259
| `fn partitioned_by(keys: Vec<&str>) -> Self` | Set partition columns |
259260
| `fn distributed_by(bucket_count: Option<i32>, bucket_keys: Vec<String>) -> Self` | Set bucket distribution |
260261
| `fn comment(comment: &str) -> Self` | Set table comment |

0 commit comments

Comments
 (0)