leekeiabstraction commented on code in PR #294:
URL: https://github.com/apache/fluss-rust/pull/294#discussion_r2784515858


##########
bindings/cpp/src/table.cpp:
##########
@@ -129,25 +129,54 @@ TableScan Table::NewScan() { return TableScan(table_); }
 // TableScan implementation
 TableScan::TableScan(ffi::Table* table) noexcept : table_(table) {}
 
-TableScan& TableScan::Project(std::vector<size_t> column_indices) {
+TableScan& TableScan::ProjectByIndex(std::vector<size_t> column_indices) {

Review Comment:
   nit: Keep similar to Rust side with `Project`



##########
bindings/cpp/src/table.cpp:
##########
@@ -163,15 +192,16 @@ Result TableScan::CreateRecordBatchScanner(LogScanner& 
out) {
     }
 
     try {
-        if (projection_.empty()) {
-            out.scanner_ = table_->new_record_batch_log_scanner();
-        } else {
+        auto resolved = !name_projection_.empty() ? ResolveNameProjection() : 
projection_;

Review Comment:
   nit: resolved_indices



##########
bindings/cpp/src/table.cpp:
##########
@@ -129,25 +129,54 @@ TableScan Table::NewScan() { return TableScan(table_); }
 // TableScan implementation
 TableScan::TableScan(ffi::Table* table) noexcept : table_(table) {}
 
-TableScan& TableScan::Project(std::vector<size_t> column_indices) {
+TableScan& TableScan::ProjectByIndex(std::vector<size_t> column_indices) {
     projection_ = std::move(column_indices);
+    name_projection_.clear();
     return *this;
 }
 
+TableScan& TableScan::ProjectByName(std::vector<std::string> column_names) {
+    name_projection_ = std::move(column_names);
+    projection_.clear();
+    return *this;
+}
+
+std::vector<size_t> TableScan::ResolveNameProjection() const {
+    auto ffi_info = table_->get_table_info_from_table();
+    const auto& columns = ffi_info.schema.columns;
+
+    std::vector<size_t> indices;
+    for (const auto& name : name_projection_) {
+        bool found = false;
+        for (size_t i = 0; i < columns.size(); ++i) {
+            if (std::string(columns[i].name) == name) {
+                indices.push_back(i);
+                found = true;
+                break;
+            }
+        }
+        if (!found) {
+            throw std::runtime_error("Column '" + name + "' not found");
+        }
+    }
+    return indices;
+}
+
 Result TableScan::CreateLogScanner(LogScanner& out) {
     if (table_ == nullptr) {
         return utils::make_error(1, "Table not available");
     }
 
     try {
-        if (projection_.empty()) {
-            out.scanner_ = table_->new_log_scanner();
-        } else {
+        auto resolved = !name_projection_.empty() ? ResolveNameProjection() : 
projection_;

Review Comment:
   nit: resolved_indices



##########
bindings/cpp/src/table.cpp:
##########
@@ -129,25 +129,54 @@ TableScan Table::NewScan() { return TableScan(table_); }
 // TableScan implementation
 TableScan::TableScan(ffi::Table* table) noexcept : table_(table) {}
 
-TableScan& TableScan::Project(std::vector<size_t> column_indices) {
+TableScan& TableScan::ProjectByIndex(std::vector<size_t> column_indices) {
     projection_ = std::move(column_indices);
+    name_projection_.clear();
     return *this;
 }
 
+TableScan& TableScan::ProjectByName(std::vector<std::string> column_names) {
+    name_projection_ = std::move(column_names);
+    projection_.clear();
+    return *this;
+}
+
+std::vector<size_t> TableScan::ResolveNameProjection() const {
+    auto ffi_info = table_->get_table_info_from_table();
+    const auto& columns = ffi_info.schema.columns;
+
+    std::vector<size_t> indices;
+    for (const auto& name : name_projection_) {
+        bool found = false;
+        for (size_t i = 0; i < columns.size(); ++i) {
+            if (std::string(columns[i].name) == name) {
+                indices.push_back(i);
+                found = true;
+                break;
+            }
+        }
+        if (!found) {
+            throw std::runtime_error("Column '" + name + "' not found");
+        }
+    }
+    return indices;
+}
+
 Result TableScan::CreateLogScanner(LogScanner& out) {

Review Comment:
   Seems like CreateLogScanner and CreateRecordBatchScanner have a lot of 
similar logic, can we benefit from some of dedupe?



-- 
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]

Reply via email to