p-ranav / tabulate

Table Maker for Modern C++
MIT License
1.91k stars 134 forks source link

Malformed table output #122

Closed neog24 closed 1 month ago

neog24 commented 1 month ago

Hi, I use tabulate to display may query result. When i output just one column, the format is perfect, but when I tried to display two columns, the output display an extra '|' and the hold table format is ruined, like below:

neograph> match (v:Person) return v.firstName limit 4
+-------------+
| v.firstName |
+-------------+
| Hossein     |
+-------------+
| Jan         |
+-------------+
| Wojciech    |
+-------------+
| Ali         |
+-------------+
4 rows.
neograph> match (v:Person) return v.id limit 4
+------+
| v.id |
+------+
| 1    |
+------+
| 2    |
+------+
| 3    |
+------+
| 4    |
+------+
4 rows.

Here we can see and extra '|' between the first and the second column, and the table format is ruined:

neograph> match (v:Person) return v.firstName, v.id limit 4
+-------------+------+
| v.firstName || v.id |
+-------------+------+
| Hossein     || 1    |
+-------------+------+
| Jan         || 2    |
+-------------+------+
| Wojciech    || 3    |
+-------------+------+
| Ali         || 4    |
+-------------+------+
4 rows.

Here is how I use tabulate :

    Table outputTable;
    outputTable.format().multi_byte_characters(true).trim_mode(
        tabulate::Format::TrimMode::kNone);

    // optimize plan
    plan = Optimizer::optimize(plan);

    // explain only
    if (boundedReq->isExplain) {
      outputTable.add_row({"Plan"});
      outputTable.add_row({plan->toString()});
      std::cout << outputTable << std::endl;
      continue;
    }

    auto rowType = plan->rowType();
    std::vector<std::string> headers;
    Row_t header;
    for (auto &col : rowType) {
      header.push_back(col.name);
    }
    outputTable.add_row(header);

    auto cb = [&outputTable](VectorTablePtr data) {
      if (data == nullptr) {
        return;
      }
      LOG(INFO) << "size: " << data->size();
      int sz = data->size();
      auto colsz = data->cols();
      for (int i = 0; i < sz; i++) {
        Row_t row;
        for (size_t j = 0; j < colsz; j++) {
          auto val = data->getCol(j)->getValue(i);
          row.push_back(val.toString());
        }
        outputTable.add_row(row);
      }
    };

Anything I can do to fix this? Thanks in advance!

p-ranav commented 1 month ago

Hello, are you using the latest commit in the main branch or a particular release?

This may be fixed in https://github.com/p-ranav/tabulate/commit/e111a262bc772e64b5b6ed1f1ddc9b27a63579a6

p-ranav commented 1 month ago

I'll create a new release soon so that the latest release has the fix as well (assuming it is fixed).

neog24 commented 1 month ago

Hello, are you using the latest commit in the main branch or a particular release?

This may be fixed in e111a26

I'll try later.

neog24 commented 1 month ago

Hello, are you using the latest commit in the main branch or a particular release?

This may be fixed in e111a26

It's been fixed when I tried the latest master branch, thanks so match!