AmrDeveloper / GQL

Git Query language is a SQL like language to perform queries on .git files with supports of most of SQL features such as grouping, ordering and aggregations functions
https://amrdeveloper.github.io/GQL/
MIT License
3.3k stars 90 forks source link

Application of `WHERE` clause and renaming columns #94

Closed uberroot4 closed 5 months ago

uberroot4 commented 8 months ago

Hello, I've encountered your project and tried to implement some (imo) missing columns for some types. When it comes to the diffs table, I am missing a reference to where the diff was made to. Checking the code I found it and decided to simply add it to the possible columns:

  1. Extending the TABLES_FIELDS_TYPES by map.insert("diff_to", DataType::Text);
  2. Extending the TABLES_FIELDS_NAMES ("diffs") by "diff_to"
  3. Modifying the git_data_provider by:

    if field_name == "diff_to" {
    let diff_to_cid = commit_info
        .parent_ids()
        .next()
        .map(|p| p.object().unwrap().id.to_string());
    
    match diff_to_cid {
        Some(value) => values.push(Value::Text(value)),
        None => values.push(Value::Text("".to_string())),
    };
    
    continue;
    }
  4. Pretty straight forward all together, also it works when I execute the query like this:
    SELECT commit_id AS from_,diff_to AS to_,name FROM diffs LIMIT 10;
  5. However, when I execute it like this (i.e. renaming the diff_to while I'm having it in the WHERE clause, it raises an error: "Invalid column name diff_to". When i use WHERE to_ IS NULL then it wirks fine.
    SELECT commit_id AS from_,diff_to AS to_,name AS b FROM diffs WHERE diff_to IS NULL LIMIT 10;

Expected behavior As far as I am aware of SQL, renaming a column and using it in a WHERE clause is exact the opposite as in GQL. So I think the renamig part in the rust Code should be applied after the consolidation of all columns.

Another remark When investigating the problem (at first I thought the problem lies somewhere else), I encountered that the LIMIT X clause is applied after the SELECT statement -- respectively I just tried a simple println for debugging. For the sake of resource management, shouldn't it be applied before? Meaning that GQL could abort the revwalk section after X iterations?

GQL:

Best, Manuel

AmrDeveloper commented 8 months ago

Hello @uberroot4,

The first point is valid and should be improved to work exactly like SQL

The Limit point is on TODO but it will require a more advanced QueryPlanner and Optimizer to make it work perfect

AmrDeveloper commented 5 months ago

Hello @uberroot4,

This issue fixed on 0.22.0

You can now run select commit_count as cc from branches where commit_count > 1

AmrDeveloper commented 5 months ago

https://github.com/AmrDeveloper/GQL/releases/tag/0.22.0