MCPcopy Create free account
hub / github.com/GraphLite-AI/GraphLite / create_index_statement

Function create_index_statement

graphlite/src/ast/parser.rs:4843–4916  ·  view source on GitHub ↗

Parse CREATE GRAPH INDEX [IF NOT EXISTS] statement

(tokens: &[Token])

Source from the content-addressed store, hash-verified

4841
4842/// Parse CREATE GRAPH INDEX [IF NOT EXISTS] statement
4843fn create_index_statement(tokens: &[Token]) -> IResult<&[Token], CreateIndexStatement> {
4844 let (tokens, _) = expect_token(Token::Create)(tokens)?;
4845
4846 // Parse index type specifier
4847 let (tokens, index_type) = alt((
4848 map(
4849 pair(
4850 preceded(expect_identifier("GRAPH"), expect_identifier("INDEX")),
4851 opt(graph_index_type),
4852 ),
4853 |(_, gtype)| {
4854 IndexTypeSpecifier::Graph(gtype.unwrap_or(GraphIndexTypeSpecifier::AdjacencyList))
4855 },
4856 ),
4857 // Default to adjacency list if just "CREATE INDEX"
4858 map(expect_identifier("INDEX"), |_| {
4859 IndexTypeSpecifier::Graph(GraphIndexTypeSpecifier::AdjacencyList)
4860 }),
4861 ))(tokens)?;
4862
4863 // Parse optional IF NOT EXISTS
4864 let (tokens, if_not_exists) = opt(tuple((
4865 expect_token(Token::If),
4866 expect_token(Token::Not),
4867 expect_token(Token::Exists),
4868 )))(tokens)?;
4869 let if_not_exists = if_not_exists.is_some();
4870
4871 // Parse index name - use lenient parser to accept various tokens for better error messages
4872 let (tokens, name) = parse_index_name(tokens)?;
4873
4874 // Parse ON table_name
4875 let (tokens, _) = expect_token(Token::On)(tokens)?;
4876 let (tokens, table) = parse_table_name(tokens)?;
4877
4878 // Parse optional column list (column1, column2, ...)
4879 let (tokens, columns) = opt(delimited(
4880 expect_token(Token::LeftParen),
4881 separated_list1(expect_token(Token::Comma), identifier),
4882 expect_token(Token::RightParen),
4883 ))(tokens)?;
4884
4885 // Parse optional USING clause
4886 let (tokens, _using_type) = opt(preceded(
4887 expect_identifier("USING"),
4888 alt((
4889 expect_identifier("IVF"),
4890 expect_identifier("FLAT"),
4891 expect_identifier("INVERTED"),
4892 expect_identifier("BM25"),
4893 expect_identifier("NGRAM"),
4894 expect_identifier("ADJACENCY_LIST"),
4895 expect_identifier("PATH_INDEX"),
4896 expect_identifier("REACHABILITY"),
4897 expect_identifier("PATTERN_INDEX"),
4898 )),
4899 ))(tokens)?;
4900

Callers

nothing calls this directly

Calls 5

expect_tokenFunction · 0.85
expect_identifierFunction · 0.85
GraphClass · 0.85
parse_index_nameFunction · 0.85
parse_table_nameFunction · 0.85

Tested by

no test coverage detected