MCPcopy Create free account
hub / github.com/AmrDeveloper/GQL / parse_select_all_or_expressions

Function parse_select_all_or_expressions

crates/gitql-parser/src/parser.rs:726–829  ·  view source on GitHub ↗
(
    context: &mut ParserContext,
    env: &mut Environment,
    tokens: &[Token],
    position: &mut usize,
    fields_names: &mut Vec<String>,
    selected_expr_titles: &mut Vec<String>,
    select

Source from the content-addressed store, hash-verified

724
725#[allow(clippy::too_many_arguments)]
726fn parse_select_all_or_expressions(
727 context: &mut ParserContext,
728 env: &mut Environment,
729 tokens: &[Token],
730 position: &mut usize,
731 fields_names: &mut Vec<String>,
732 selected_expr_titles: &mut Vec<String>,
733 selected_expr: &mut Vec<Box<dyn Expr>>,
734 is_select_all: &mut bool,
735) -> Result<(), Box<Diagnostic>> {
736 // Check if it `SELECT *`
737 if is_current_token(tokens, position, TokenKind::Star) {
738 // Consume `*`
739 *position += 1;
740 *is_select_all = true;
741 return Ok(());
742 }
743
744 // Parse list of expression separated by `,` or until end of file
745 while !is_current_token(tokens, position, TokenKind::From) {
746 let expression = parse_expression(context, env, tokens, position)?;
747 let expr_type = expression.expr_type().clone();
748 let field_name = expression_literal(&expression)
749 .unwrap_or_else(|| context.name_generator.generate_column_name());
750
751 // Assert that each selected field is unique
752 if fields_names.contains(&field_name) {
753 return Err(Diagnostic::error("Can't select the same field twice")
754 .with_location(calculate_safe_location(tokens, *position - 1))
755 .as_boxed());
756 }
757
758 // Check for Field name alias
759 if is_current_token(tokens, position, TokenKind::As) {
760 // Consume `as` keyword
761 *position += 1;
762
763 // Parse and consume Symbol as Elias name
764 let alias_name = consume_conditional_token_or_errors(
765 tokens,
766 position,
767 |token| matches!(token.kind, TokenKind::Symbol(_) | TokenKind::String(_)),
768 "Expect `Symbol` or `Text` as field alias name",
769 )?
770 .to_string();
771
772 // TODO [#120, #121]: Remove this check
773 if env
774 .schema
775 .tables_fields_types
776 .contains_key(alias_name.as_str())
777 {
778 return Err(Diagnostic::error("Can't use column name as Alias")
779 .add_note("Until supporting `table.column` you should use different alias name")
780 .with_location(tokens[*position - 1].location)
781 .as_boxed());
782 }
783

Callers 1

parse_select_statementFunction · 0.85

Calls 13

is_current_tokenFunction · 0.85
parse_expressionFunction · 0.85
expression_literalFunction · 0.85
calculate_safe_locationFunction · 0.85
expr_typeMethod · 0.80
generate_column_nameMethod · 0.80
containsMethod · 0.80
as_boxedMethod · 0.80
with_locationMethod · 0.80
add_noteMethod · 0.80
add_helpMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…