Skip to content

Commit

Permalink
parser: semantic: add some tests for JOIN ON expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
PauloMigAlmeida committed Nov 2, 2023
1 parent 5882139 commit e7248aa
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 26 deletions.
19 changes: 0 additions & 19 deletions src/parser/semantic_select.c
Original file line number Diff line number Diff line change
Expand Up @@ -2101,25 +2101,6 @@ bool semantic_analyse_select_stmt(struct database *db, struct ast_node *node, ch
if (!check_having_clause(node, out_err, out_err_len, &column_alias))
goto err_having_clause;

/*
* TODO:
* - Check for duplicate / invalid aliases (table done, columns done)
* -> Need to change implementation though... instead of storing as KV alias->table_name (for table aliases)
* and alias->?? (for column), I need to find a common denominator. Otherwise, it will become hard to
* validate the existence of columns at some point... my best guess, it to use some structure that resembles
* the ast_sel_fieldname_nome... -> I think I've done it (TBC)
* - Check for aliases use in the where clause (also group, order, having).
* -> This is becoming a big dilemma for me as although column aliases are not available in where clause (MySQL)
* they seem to be used in group by and order by.... I wonder if I should implement it for all
* like SQLite does:
*
* ex: SELECT val as f1 FROM A group by f1 order by f1;
*
* - check field name (full qualified ones) as they can contain either table name or alias
* - check for columns existence
* - check for ambiguous columns on join statements
*/

/* cleanup */
hashtable_foreach(&column_alias, &free_hashmap_entries, NULL);
hashtable_free(&column_alias);
Expand Down
8 changes: 1 addition & 7 deletions tests/parser/semantic.c
Original file line number Diff line number Diff line change
Expand Up @@ -909,13 +909,7 @@ static void select_tests(void)
helper(&db, "SELECT * FROM I_J_1 JOIN I_J_2 ON f1 = f2 JOIN I_J_3 ON f2 = f4;", true); // no such column
helper(&db, "SELECT * FROM I_J_1 v1 JOIN I_J_2 v2 ON v1.f1 = v2.f3 JOIN I_J_3 ON v2.f2 = f3;", true); // no such column
helper(&db, "SELECT * FROM I_J_1 v1 JOIN I_J_2 v2 ON v1.f1 = v2.f2 JOIN I_J_3 ON v2.f2 = f4;", true); // no such column

helper(&db, "SELECT * FROM I_J_1 a JOIN I_J_2 b ON a.f1 = c.f2;", true); // invalid alias
helper(&db, "SELECT * FROM I_J_1 JOIN I_J_2 ON I_J_1.f1 = I_J_3.f2;", true); // table isn't part of JOIN

// helper(&db, "SELECT * FROM V_J_1 JOIN V_J_2 ON f1 = f2 JOIN V_J_3 ON f2 = f3;", false); // multi-join
// helper(&db, "SELECT * FROM V_J_1 a JOIN V_J_2 b ON a.f1 = b.f2 JOIN V_J_3 c ON b.f2 = c.f3;", false);
// helper(&db, "SELECT * FROM V_J_1 JOIN V_J_2 ON V_J_1.f1 = V_J_2.f2 JOIN V_J_3 ON V_J_2.f2 = V_J_3.f3;", false);
helper(&db, "SELECT * FROM I_J_1 v1 JOIN I_J_2 v2 ON I_J_1.f1 = I_J_2.f2 JOIN I_J_3 ON I_J_2.f2 = I_J_3.f3;", true); // after alias is created, we can't use fqfield

database_close(&db);
}
Expand Down

0 comments on commit e7248aa

Please sign in to comment.