fresh-borzoni commented on code in PR #349:
URL: https://github.com/apache/fluss-rust/pull/349#discussion_r2818962778
##########
website/docs/user-guide/cpp/data-types.md:
##########
@@ -52,46 +52,88 @@ row.Set("created_at",
fluss::Timestamp::FromMillis(1700000000000));
row.Set("nickname", nullptr); // set to null
```
-## GenericRow Getters
+## Reading Field Values
+
+Field values are read through `RowView` (from scan results) and `LookupResult`
(from lookups), not through `GenericRow`. Both provide the same getter
interface with zero-copy access to string and bytes data.
+
+:::warning Lifetime
+`RowView` borrows from `ScanRecords`. It must not outlive the `ScanRecords`
that produced it (similar to `std::string_view` borrowing from `std::string`).
+
+```cpp
+// DON'T — string_view dangles after ScanRecords is destroyed:
+std::string_view dangling;
+{
+ fluss::ScanRecords records;
+ scanner.Poll(5000, records);
+ dangling = records[0].row.GetString(0); // points into ScanRecords memory
+}
+// dangling is undefined behavior here — ScanRecords is gone!
+
+// DO — use values within ScanRecords lifetime, or copy when you need
ownership:
+fluss::ScanRecords records;
+scanner.Poll(5000, records);
+for (const auto& rec : records) {
+ auto name = rec.row.GetString(0); // zero-copy string_view
+ auto owned = std::string(rec.row.GetString(0)); // explicit copy when
needed
+ process(owned);
+}
+```
+:::
+
+### From Scan Results (RowView)
```cpp
-std::string name = result_row.GetString(1);
-float score = result_row.GetFloat32(3);
-std::string balance = result_row.DecimalToString(4);
-fluss::Date date = result_row.GetDate(5);
-fluss::Time time = result_row.GetTime(6);
-fluss::Timestamp ts = result_row.GetTimestamp(7);
+for (const auto& rec : records) {
+ auto name = rec.row.GetString(1); // zero-copy string_view
+ float score = rec.row.GetFloat32(3);
+ auto balance = rec.row.GetDecimalString(4); // std::string (already owned)
+ fluss::Date date = rec.row.GetDate(5);
+ fluss::Time time = rec.row.GetTime(6);
+ fluss::Timestamp ts = rec.row.GetTimestamp(7);
+}
+```
+
+### From Lookup Results (LookupResult)
+
+```cpp
+fluss::LookupResult result;
+lookuper.Lookup(pk_row, result);
+if (result.Found()) {
+ auto name = result.GetString(1); // zero-copy string_view
+ int64_t age = result.GetInt64(2);
+}
```
-## DatumType Enum
-
-| DatumType | C++ Type | Getter |
-|-----------------|------------------------|------------------------|
-| `Null` | -- | `IsNull(idx)` |
-| `Bool` | `bool` | `GetBool(idx)` |
-| `Int32` | `int32_t` | `GetInt32(idx)` |
-| `Int64` | `int64_t` | `GetInt64(idx)` |
-| `Float32` | `float` | `GetFloat32(idx)` |
-| `Float64` | `double` | `GetFloat64(idx)` |
-| `String` | `std::string` | `GetString(idx)` |
-| `Bytes` | `std::vector<uint8_t>` | `GetBytes(idx)` |
-| `Date` | `Date` | `GetDate(idx)` |
-| `Time` | `Time` | `GetTime(idx)` |
-| `TimestampNtz` | `Timestamp` | `GetTimestamp(idx)` |
-| `TimestampLtz` | `Timestamp` | `GetTimestamp(idx)` |
-| `DecimalString` | `std::string` | `DecimalToString(idx)` |
+## TypeId Enum
+
+| TypeId | C++ Type | Getter
|
+|-----------------|---------------------------------------------|---------------------------|
+| `Boolean` | `bool` |
`GetBool(idx)` |
+| `TinyInt` | `int32_t` |
`GetInt32(idx)` |
+| `SmallInt` | `int32_t` |
`GetInt32(idx)` |
Review Comment:
Hmm, it makes more sense for setters, for getters - it's just windened, so
it's correct here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]