(
context: &mut ParserContext,
env: &mut Environment,
tables_to_select_from: &mut Vec<String>,
joins: &mut Vec<Join>,
tokens: &[Token],
position: &mut usize,
)
| 829 | } |
| 830 | |
| 831 | fn parse_from_option( |
| 832 | context: &mut ParserContext, |
| 833 | env: &mut Environment, |
| 834 | tables_to_select_from: &mut Vec<String>, |
| 835 | joins: &mut Vec<Join>, |
| 836 | tokens: &[Token], |
| 837 | position: &mut usize, |
| 838 | ) -> Result<(), Box<Diagnostic>> { |
| 839 | if is_current_token(tokens, position, TokenKind::From) { |
| 840 | // Consume `From` keyword |
| 841 | *position += 1; |
| 842 | |
| 843 | // Parse and consume Symbol as Table name |
| 844 | let table_name = consume_conditional_token_or_errors( |
| 845 | tokens, |
| 846 | position, |
| 847 | |token| matches!(token.kind, TokenKind::Symbol(_)), |
| 848 | "Expect `Table` value after `FROM` keyword", |
| 849 | )? |
| 850 | .to_string(); |
| 851 | |
| 852 | if !env |
| 853 | .schema |
| 854 | .tables_fields_names |
| 855 | .contains_key(table_name.as_str()) |
| 856 | { |
| 857 | let mut diagnostic = |
| 858 | Diagnostic::error(&format!("Cannot find table with name `{table_name}`")) |
| 859 | .add_note("You can use the `SHOW TABLES` query to get list of current tables") |
| 860 | .add_note("Check the documentations to see available tables") |
| 861 | .with_location(calculate_safe_location(tokens, *position)); |
| 862 | |
| 863 | let canditates: Vec<&&str> = env.schema.tables_fields_names.keys().collect(); |
| 864 | if let Some(closest_valid_name) = find_closeest_string(&table_name, &canditates) { |
| 865 | let message = |
| 866 | &format!("a table with a similar name exists: `{closest_valid_name}`"); |
| 867 | diagnostic = diagnostic.add_help(message); |
| 868 | } |
| 869 | |
| 870 | return Err(diagnostic.as_boxed()); |
| 871 | } |
| 872 | |
| 873 | // Register the table |
| 874 | tables_to_select_from.push(table_name.to_string()); |
| 875 | context.selected_tables.push(table_name.to_string()); |
| 876 | register_current_table_fields_types(env, &table_name)?; |
| 877 | |
| 878 | // Parse Joins |
| 879 | let mut number_previous_of_joins = 0; |
| 880 | while is_join_or_join_type_token(tokens, position) { |
| 881 | let join_token = &tokens[*position]; |
| 882 | |
| 883 | // The default join type now is cross join because we don't support `ON` Condition |
| 884 | let mut join_kind = JoinKind::Default; |
| 885 | if join_token.kind != TokenKind::Join { |
| 886 | join_kind = match join_token.kind { |
| 887 | TokenKind::Left => JoinKind::Left, |
| 888 | TokenKind::Right => JoinKind::Right, |
no test coverage detected
searching dependent graphs…