From 068a1530f904dd35bfebe473ea456fc21615f677 Mon Sep 17 00:00:00 2001 From: xav-db Date: Tue, 5 Aug 2025 15:58:42 +0100 Subject: [PATCH 1/2] fixing clippy --- helix-container/src/queries.rs | 205 +----------------- helix-db/src/grammar.pest | 34 ++- .../graph_core/ops/source/add_n.rs | 4 +- .../graph_core/ops/source/v_from_id.rs | 2 +- .../graph_core/ops/util/update.rs | 10 +- .../helix_engine/storage_core/storage_core.rs | 2 +- .../builtin/all_nodes_and_edges.rs | 10 +- .../embedding_providers.rs | 19 +- helix-db/src/helixc/analyzer/analyzer.rs | 2 +- .../analyzer/methods/migration_validation.rs | 12 +- .../helixc/analyzer/methods/schema_methods.rs | 2 +- helix-db/src/helixc/generator/migrations.rs | 11 +- helix-db/src/helixc/generator/utils.rs | 2 +- helix-db/src/helixc/parser/helix_parser.rs | 6 +- helix-db/src/protocol/value.rs | 2 +- helix-db/src/utils/items.rs | 2 +- hql-tests/file13/file13.hx | 34 ++- 17 files changed, 76 insertions(+), 283 deletions(-) diff --git a/helix-container/src/queries.rs b/helix-container/src/queries.rs index 1e2aeb5e..c7084958 100644 --- a/helix-container/src/queries.rs +++ b/helix-container/src/queries.rs @@ -1,205 +1,6 @@ // DEFAULT CODE -// use helix_db::helix_engine::graph_core::config::Config; - -// pub fn config() -> Option { -// None -// } - -use chrono::{DateTime, Utc}; -use heed3::RoTxn; -use helix_db::{ - embed, exclude_field, field_addition_from_old_field, field_addition_from_value, - field_remapping, field_type_cast, - helix_engine::{ - graph_core::{ - config::{Config, GraphConfig, VectorConfig}, - ops::{ - bm25::search_bm25::SearchBM25Adapter, - g::G, - in_::{in_::InAdapter, in_e::InEdgesAdapter, to_n::ToNAdapter, to_v::ToVAdapter}, - out::{ - from_n::FromNAdapter, from_v::FromVAdapter, out::OutAdapter, - out_e::OutEdgesAdapter, - }, - source::{ - add_e::{AddEAdapter, EdgeType}, - add_n::AddNAdapter, - e_from_id::EFromIdAdapter, - e_from_type::EFromTypeAdapter, - n_from_id::NFromIdAdapter, - n_from_index::NFromIndexAdapter, - n_from_type::NFromTypeAdapter, - }, - tr_val::{Traversable, TraversalVal}, - util::{ - dedup::DedupAdapter, drop::Drop, exist::Exist, filter_mut::FilterMut, - filter_ref::FilterRefAdapter, map::MapAdapter, order::OrderByAdapter, - paths::ShortestPathAdapter, props::PropsAdapter, range::RangeAdapter, - update::UpdateAdapter, - }, - vectors::{ - brute_force_search::BruteForceSearchVAdapter, insert::InsertVAdapter, - search::SearchVAdapter, - }, - }, - }, - types::GraphError, - vector_core::vector::HVector, - }, - helix_gateway::{ - embedding_providers::embedding_providers::{EmbeddingModel, get_embedding_model}, - mcp::mcp::{MCPHandler, MCPHandlerSubmission, MCPToolInput}, - router::router::HandlerInput, - }, - identifier_remapping, node_matches, props, - protocol::{ - format::Format, - remapping::{Remapping, RemappingMap, ResponseRemapping}, - response::Response, - return_values::ReturnValue, - value::{ - Value, - casting::{CastType, cast}, - }, - }, - traversal_remapping, - utils::{ - count::Count, - filterable::Filterable, - id::ID, - items::{Edge, Node}, - }, - value_remapping, -}; -use helix_macros::{handler, mcp_handler, migration, tool_call}; -use sonic_rs::{Deserialize, Serialize}; -use std::collections::{HashMap, HashSet}; -use std::sync::Arc; -use std::time::Instant; +use helix_db::helix_engine::graph_core::config::Config; pub fn config() -> Option { - return Some(Config { - vector_config: Some(VectorConfig { - m: Some(16), - ef_construction: Some(128), - ef_search: Some(768), - }), - graph_config: Some(GraphConfig { - secondary_indices: Some(vec![]), - }), - db_max_size_gb: Some(20), - mcp: Some(true), - bm25: Some(true), - schema: Some( - r#"{ - "schema": { - "nodes": [], - "vectors": [ - { - "name": "UserEmbedding", - "properties": { - "id": "ID", - "userId": "String", - "dataType": "String", - "createdAt": "Date", - "metadata": "String", - "lastUpdated": "String" - } - } - ], - "edges": [] - }, - "queries": [ - { - "name": "CreateUserBioEmbedding", - "parameters": { - "userId": "String", - "bioText": "String", - "lastUpdated": "String" - }, - "returns": [ - "embedding" - ] - }, - { - "name": "SearchSimilarUsers", - "parameters": { - "k": "I64", - "queryText": "String", - "dataType": "String" - }, - "returns": [ - "search_results" - ] - } - ] -}"# - .to_string(), - ), - embedding_model: None, - graphvis_node_label: None, - }); -} - -pub struct UserEmbedding { - pub userId: String, - pub dataType: String, - pub metadata: String, - pub lastUpdated: String, - pub createdAt: DateTime, -} - -#[derive(Serialize, Deserialize)] -pub struct CreateUserBioEmbeddingInput { - pub userId: String, - pub bioText: String, - pub lastUpdated: String, -} -#[handler(with_write)] -pub fn CreateUserBioEmbedding(input: &HandlerInput) -> Result { - { - let embedding = G::new_mut(Arc::clone(&db), &mut txn) -.insert_v:: bool>(&embed!(db, &data.bioText), "UserEmbedding", Some(props! { "metadata" => "{}", "userId" => data.userId.clone(), "dataType" => "bio", "lastUpdated" => data.lastUpdated.clone() })).collect_to_obj(); - let mut return_vals: HashMap = HashMap::new(); - return_vals.insert( - "embedding".to_string(), - ReturnValue::from_traversal_value_with_mixin( - embedding.clone().clone(), - remapping_vals.borrow_mut(), - ), - ); - } -} - -#[derive(Serialize, Deserialize)] -pub struct SearchSimilarUsersInput { - pub queryText: Option, - pub k: i64, - pub dataType: String, -} -#[handler(with_read)] -pub fn SearchSimilarUsers(input: &HandlerInput) -> Result { - { - let search_results = G::new(Arc::clone(&db), &txn) - .search_v:: bool, _>( - &embed!( - db, - data.queryText - .as_ref() - .ok_or_else(|| GraphError::ParamNotFound("queryText"))? - ), - data.k.clone(), - "UserEmbedding", - None, - ) - .collect_to::>(); - let mut return_vals: HashMap = HashMap::new(); - return_vals.insert( - "search_results".to_string(), - ReturnValue::from_traversal_value_array_with_mixin( - search_results.clone().clone(), - remapping_vals.borrow_mut(), - ), - ); - } -} + None +} \ No newline at end of file diff --git a/helix-db/src/grammar.pest b/helix-db/src/grammar.pest index dc23599f..e79d4e5d 100644 --- a/helix-db/src/grammar.pest +++ b/helix-db/src/grammar.pest @@ -7,7 +7,7 @@ source = { SOI ~ (schema_def | migration_def | query_def)* ~ EOI } // --------------------------------------------------------------------- // Schema definitions // --------------------------------------------------------------------- -schema_def = {( schema_version ~ "{" ~ (vector_def | node_def | edge_def)* ~ "}") | (vector_def | node_def | edge_def) } +schema_def = {( schema_version ~ "{" ~ (vector_def | node_def | edge_def | enum_def)* ~ "}") | (vector_def | node_def | edge_def | enum_def) } vector_def = { "V::" ~ identifier_upper ~ node_body? } node_def = { "N::" ~ identifier_upper ~ node_body? } edge_def = { "E::" ~ identifier_upper ~ edge_body } @@ -22,6 +22,12 @@ default = { "DEFAULT" ~ (now | float | integer | boolean | string_literal | non properties = { "Properties" ~ ":" ~ "{" ~ field_defs? ~ "}" } schema_version = { "schema::" ~ integer } + +enum_def = { "Enum::" ~ identifier_upper ~ "{" ~ enum_body ~ "}" } +enum_body = { "{" ~ enum_fields ~ "}" } +enum_fields = { (enum_field ~ ",")* ~ (enum_field ~ ","?)? } +enum_field = { identifier_upper ~ ("(" ~ identifier_upper ~ ")")? } + // --------------------------------------------------------------------- // Migration definitions // --------------------------------------------------------------------- @@ -44,6 +50,14 @@ edge_migration = { "{" ~ "Properties" ~ ":" ~ "{" ~ field_migrations ~ "}" ~ "}" migration_item_mapping = { item_def ~ "=>" ~ (item_def | anon_decl) ~ (node_migration | edge_migration) } migration_body = { migration_item_mapping* } +// --------------------------------------------------------------------- +// Macros +// --------------------------------------------------------------------- +built_in_macro = { mcp_macro | model_macro } +mcp_macro = { "#[mcp]" } + +model_macro = { "#[" ~ "model" ~ "(" ~ model_name ~ ")" ~ "]" } +model_name = { identifier | string_literal } // --------------------------------------------------------------------- // Query definitions @@ -62,7 +76,7 @@ get_stmt = { identifier ~ "<-" ~ evaluates_to_anything } traversal = { (start_node | start_edge | search_vector) ~ step* ~ last_step? } id_traversal = { identifier ~ ((step+ ~ last_step?) | last_step) } anonymous_traversal = { "_" ~ ((step+ ~ last_step?) | last_step)? } -step = { "::" ~ (graph_step | order_by | where_step | closure_step | object_step | exclude_field | count | ID | range_step | AddE) } +step = { "::" ~ ((variable_declaration~graph_step) | order_by | where_step | closure_step | object_step | exclude_field | count | ID | range_step | AddE) } last_step = { "::" ~ (bool_operations | update) } // change this for loop to be able to take traversals etc in the future. for_loop = { "FOR" ~ for_argument ~ "IN" ~ identifier ~ "{" ~ query_body ~ "}" } @@ -225,16 +239,18 @@ exclude_field = { "!" ~ "{" ~ identifier ~ ("," ~ identifier)* ~ "}" } closure_step = { "|" ~ identifier ~ "|" ~ object_step } spread_object = { ".." ~ ","?} mapping_field = { (identifier ~ (":" ~ (anonymous_traversal | evaluates_to_anything | object_step))) | identifier } +variable_declaration = { "|" ~ identifier ~ "|" } + // --------------------------------------------------------------------- -// Macros +// Match steps // --------------------------------------------------------------------- -built_in_macro = { mcp_macro | model_macro } -mcp_macro = { "#[mcp]" } - -model_macro = { "#[" ~ "model" ~ "(" ~ model_name ~ ")" ~ "]" } -model_name = { identifier | string_literal } - +match_step = { "MATCH" ~ match_variable? ~ "{" ~ match_statements ~ "}" } +match_variable = { "|" ~ (identifier | traversal | "_") ~ "|" } +match_statements = { (match_statement ~ ",")* ~ match_statement ~ ","? } +match_statement = { match_type ~ "=>" ~ match_value } +match_type = { identifier_upper ~ "::" ~ identifier_upper ~ ("(" ~ identifier ~ ")")?} +match_value = { "{" ~ query_body ~ "}" | traversal | id_traversal | anonymous_traversal | none | identifier } // --------------------------------------------------------------------- diff --git a/helix-db/src/helix_engine/graph_core/ops/source/add_n.rs b/helix-db/src/helix_engine/graph_core/ops/source/add_n.rs index f71c46a4..93c8eecf 100644 --- a/helix-db/src/helix_engine/graph_core/ops/source/add_n.rs +++ b/helix-db/src/helix_engine/graph_core/ops/source/add_n.rs @@ -1,8 +1,8 @@ use super::super::tr_val::TraversalVal; use crate::{ helix_engine::{ - bm25::bm25::{BM25Flatten, BM25}, - graph_core::{ops::version_info::VersionInfo, traversal_iter::RwTraversalIterator}, + bm25::bm25::{BM25, BM25Flatten}, + graph_core::traversal_iter::RwTraversalIterator, types::GraphError, }, protocol::value::Value, diff --git a/helix-db/src/helix_engine/graph_core/ops/source/v_from_id.rs b/helix-db/src/helix_engine/graph_core/ops/source/v_from_id.rs index f4ba1e31..74986d8f 100644 --- a/helix-db/src/helix_engine/graph_core/ops/source/v_from_id.rs +++ b/helix-db/src/helix_engine/graph_core/ops/source/v_from_id.rs @@ -2,7 +2,7 @@ use crate::{ helix_engine::vector_core::vector::HVector, helix_engine::{ graph_core::{ops::tr_val::TraversalVal, traversal_iter::RoTraversalIterator}, - storage_core::{storage_core::HelixGraphStorage, storage_methods::StorageMethods}, + storage_core::{storage_core::HelixGraphStorage}, types::GraphError, }, }; diff --git a/helix-db/src/helix_engine/graph_core/ops/util/update.rs b/helix-db/src/helix_engine/graph_core/ops/util/update.rs index 36ee9b83..84dee0c8 100644 --- a/helix-db/src/helix_engine/graph_core/ops/util/update.rs +++ b/helix-db/src/helix_engine/graph_core/ops/util/update.rs @@ -1,14 +1,11 @@ -use std::collections::HashMap; - use heed3::PutFlags; - use crate::{ helix_engine::{ graph_core::traversal_iter::RwTraversalIterator, storage_core::{storage_core::HelixGraphStorage, storage_methods::StorageMethods}, types::GraphError, }, - protocol::value::{Value, properties_format}, + protocol::value::{Value}, }; use super::super::tr_val::TraversalVal; @@ -56,10 +53,7 @@ impl<'scope, 'env, I: Iterator>> UpdateA match item { Ok(TraversalVal::Node(node)) => match storage.get_node(self.txn, &node.id) { Ok(mut old_node) => { - let mut properties = match old_node.properties { - Some(properties) => properties, - None => HashMap::new(), - }; + let mut properties = old_node.properties.unwrap_or_default(); if let Some(ref props) = props { for (key, _new_value) in props.iter() { diff --git a/helix-db/src/helix_engine/storage_core/storage_core.rs b/helix-db/src/helix_engine/storage_core/storage_core.rs index 7f66f38d..a99259d1 100644 --- a/helix-db/src/helix_engine/storage_core/storage_core.rs +++ b/helix-db/src/helix_engine/storage_core/storage_core.rs @@ -4,7 +4,7 @@ use crate::{ bm25::bm25::HBM25Config, graph_core::{ config::Config, - ops::version_info::{self, VersionInfo}, + ops::version_info::VersionInfo, }, storage_core::storage_methods::StorageMethods, types::GraphError, diff --git a/helix-db/src/helix_gateway/builtin/all_nodes_and_edges.rs b/helix-db/src/helix_gateway/builtin/all_nodes_and_edges.rs index 372cd19f..52f6c09b 100644 --- a/helix-db/src/helix_gateway/builtin/all_nodes_and_edges.rs +++ b/helix-db/src/helix_gateway/builtin/all_nodes_and_edges.rs @@ -115,10 +115,8 @@ pub fn nodes_edges_inner(input: &HandlerInput) -> Result { let url_str = _url.unwrap_or("http://localhost:8699/embed"); - Url::parse(url_str).map_err(|e| GraphError::from(format!("Invalid URL: {}", e)))?; + Url::parse(url_str).map_err(|e| GraphError::from(format!("Invalid URL: {e}")))?; Some(url_str.to_string()) } _ => None, @@ -99,11 +99,10 @@ impl EmbeddingModelImpl { .unwrap_or("text-embedding-ada-002"); Ok((EmbeddingProvider::OpenAI, model_name.to_string())) } - Some(m) if m == "local" => Ok((EmbeddingProvider::Local, "local".to_string())), + Some("local") => Ok((EmbeddingProvider::Local, "local".to_string())), Some(m) => Err(GraphError::from(format!( - "Unknown embedding model '{}'. Please use 'openai:', 'gemini:', or 'local' prefix", - m + "Unknown embedding model '{m}'. Please use 'openai:', 'gemini:', or 'local' prefix" ))), None => Err(GraphError::from("No embedding provider available")), } @@ -122,7 +121,7 @@ impl EmbeddingModel for EmbeddingModelImpl { let response = self .client .post("https://api.openai.com/v1/embeddings") - .header("Authorization", format!("Bearer {}", api_key)) + .header("Authorization", format!("Bearer {api_key}")) .json(&json!({ "input": text, "model": &self.model, @@ -210,16 +209,14 @@ impl EmbeddingModel for EmbeddingModelImpl { "chunk_size": 100 })) .send() - .map_err(|e| GraphError::from(format!("Request failed: {}", e)))?; + .map_err(|e| GraphError::from(format!("Request failed: {e}")))?; let text_response = response .text() - .map_err(|e| GraphError::from(format!("Failed to parse response: {}", e)))?; + .map_err(|e| GraphError::from(format!("Failed to parse response: {e}")))?; - let response = - sonic_rs::from_str::(&text_response).map_err(|e| { - GraphError::from(format!("Failed to parse JSON response: {}", e)) - })?; + let response = sonic_rs::from_str::(&text_response) + .map_err(|e| GraphError::from(format!("Failed to parse JSON response: {e}")))?; let embedding = response["embedding"] .as_array() diff --git a/helix-db/src/helixc/analyzer/analyzer.rs b/helix-db/src/helixc/analyzer/analyzer.rs index 55522434..3055e4f8 100644 --- a/helix-db/src/helixc/analyzer/analyzer.rs +++ b/helix-db/src/helixc/analyzer/analyzer.rs @@ -9,7 +9,7 @@ use crate::helixc::{ }, types::Type, }, - generator::{migrations::GeneratedMigration, Source as GeneratedSource}, + generator::{Source as GeneratedSource}, parser::helix_parser::{EdgeSchema, ExpressionType, Field, Query, Source}, }; use serde::Serialize; diff --git a/helix-db/src/helixc/analyzer/methods/migration_validation.rs b/helix-db/src/helixc/analyzer/methods/migration_validation.rs index 4cf631ec..b978be40 100644 --- a/helix-db/src/helixc/analyzer/methods/migration_validation.rs +++ b/helix-db/src/helixc/analyzer/methods/migration_validation.rs @@ -1,5 +1,4 @@ use crate::{ - generate_error, helixc::{ analyzer::analyzer::Ctx, generator::{ @@ -10,15 +9,12 @@ use crate::{ utils::{GenRef, GeneratedValue, Separator}, }, parser::helix_parser::{ - FieldValue, FieldValueType, Migration, MigrationItem, MigrationItemMapping, - MigrationPropertyMapping, + FieldValueType, Migration, MigrationItem, MigrationPropertyMapping, }, }, protocol::value::Value, }; -use paste::paste; - pub(crate) fn validate_migration(ctx: &mut Ctx, migration: &Migration) { // check from version exists if !ctx @@ -104,10 +100,6 @@ pub(crate) fn validate_migration(ctx: &mut Ctx, migration: &Migration) { loc: _, } in &item.remappings { - println!("property_name: {:?}", property_name); - println!("property_value: {:?}", property_value); - println!("default: {:?}", default); - println!("cast: {:?}", cast); // check the new property exists in to version schema let to_property_field = match to_fields.get(property_name.1.as_str()) { @@ -231,8 +223,6 @@ pub(crate) fn validate_migration(ctx: &mut Ctx, migration: &Migration) { item_mappings.push(generated_migration_item_mapping); } - println!("{:?}", item_mappings); - ctx.output.migrations.push(GeneratedMigration { from_version: migration.from_version.1.to_string(), to_version: migration.to_version.1.to_string(), diff --git a/helix-db/src/helixc/analyzer/methods/schema_methods.rs b/helix-db/src/helixc/analyzer/methods/schema_methods.rs index 8e137f31..3e39aa6c 100644 --- a/helix-db/src/helixc/analyzer/methods/schema_methods.rs +++ b/helix-db/src/helixc/analyzer/methods/schema_methods.rs @@ -14,7 +14,7 @@ pub(crate) struct SchemaVersionMap<'a>(HashMap, FieldLoo impl<'a> SchemaVersionMap<'a> { pub fn get_latest(&self) -> (FieldLookup<'a>, FieldLookup<'a>, FieldLookup<'a>) { - self.0.get(&self.0.keys().max().unwrap()).unwrap().clone() + self.0.get(self.0.keys().max().unwrap()).unwrap().clone() } pub fn inner(&self) -> &HashMap, FieldLookup<'a>, FieldLookup<'a>)> { diff --git a/helix-db/src/helixc/generator/migrations.rs b/helix-db/src/helixc/generator/migrations.rs index 0e51124f..e2a2dcc4 100644 --- a/helix-db/src/helixc/generator/migrations.rs +++ b/helix-db/src/helixc/generator/migrations.rs @@ -50,7 +50,7 @@ impl std::fmt::Display for GeneratedMigration { )?; writeln!(f, "let mut new_props = HashMap::new();")?; for remapping in item.remappings.iter() { - writeln!(f, "{}", remapping)?; + writeln!(f, "{remapping}")?; } writeln!(f, "new_props")?; writeln!(f, "}}")?; @@ -67,21 +67,18 @@ impl std::fmt::Display for GeneratedMigrationPropertyMapping { new_field, } => write!( f, - "field_addition_from_old_field!(&mut props, &mut new_props, {}, {})", - new_field, old_field + "field_addition_from_old_field!(&mut props, &mut new_props, {new_field}, {old_field})" ), GeneratedMigrationPropertyMapping::FieldAdditionFromValue { new_field, value } => { write!( f, - "field_addition_from_value!(&mut new_props, {}, {})", - new_field, value + "field_addition_from_value!(&mut new_props, {new_field}, {value})" ) } GeneratedMigrationPropertyMapping::FieldTypeCast { field, cast } => { write!( f, - "field_type_cast!(&mut props, &mut new_props, {}, {})", - field, cast + "field_type_cast!(&mut props, &mut new_props, {field}, {cast})" ) } } diff --git a/helix-db/src/helixc/generator/utils.rs b/helix-db/src/helixc/generator/utils.rs index a5168c47..72996f4b 100644 --- a/helix-db/src/helixc/generator/utils.rs +++ b/helix-db/src/helixc/generator/utils.rs @@ -311,7 +311,7 @@ impl Display for Separator { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Separator::Comma(t) => write!(f, ",\n{t}"), - Separator::Semicolon(t) => write!(f, "{t};\n"), + Separator::Semicolon(t) => writeln!(f, "{t};"), Separator::Period(t) => write!(f, "\n.{t}"), Separator::Newline(t) => write!(f, "\n{t}"), Separator::Empty(t) => write!(f, "{t}"), diff --git a/helix-db/src/helixc/parser/helix_parser.rs b/helix-db/src/helixc/parser/helix_parser.rs index 59b4432d..1f25ff61 100644 --- a/helix-db/src/helixc/parser/helix_parser.rs +++ b/helix-db/src/helixc/parser/helix_parser.rs @@ -2,7 +2,7 @@ use super::{ location::{HasLoc, Loc}, parser_methods::ParserError, }; -use crate::protocol::{remapping, value::Value}; +use crate::protocol::value::Value; use chrono::{DateTime, NaiveDate, Utc}; use itertools::Itertools; use pest::{ @@ -1607,7 +1607,9 @@ impl HelixParser { }; // gets optional param - let is_optional = inner.peek().map_or(false, |p| p.as_rule() == Rule::optional_param); + let is_optional = inner + .peek() + .is_some_and(|p| p.as_rule() == Rule::optional_param); if is_optional { inner.next(); } diff --git a/helix-db/src/protocol/value.rs b/helix-db/src/protocol/value.rs index 1ddde9fc..94b2ae3d 100644 --- a/helix-db/src/protocol/value.rs +++ b/helix-db/src/protocol/value.rs @@ -1322,7 +1322,7 @@ impl CastValue for Value { } pub mod casting { - use crate::helixc::parser::helix_parser::{FieldType, FieldValueType}; + use crate::helixc::parser::helix_parser::FieldType; use super::*; diff --git a/helix-db/src/utils/items.rs b/helix-db/src/utils/items.rs index 0bb9a3fe..2c506397 100644 --- a/helix-db/src/utils/items.rs +++ b/helix-db/src/utils/items.rs @@ -20,7 +20,7 @@ pub struct Node { pub id: u128, /// The label of the node. pub label: String, - /// + /// The version of the node. pub version: u8, /// The properties of the node. /// diff --git a/hql-tests/file13/file13.hx b/hql-tests/file13/file13.hx index fc7f2e41..f4035566 100644 --- a/hql-tests/file13/file13.hx +++ b/hql-tests/file13/file13.hx @@ -1,25 +1,23 @@ N::User { user_field: String, + user_type: UserType, } -N::Admin { - admin_field: String, +Enum::UserType { + User, + Admin, } -N::Guest { - guest_field: String, -} +QUERY GetAdmins() => + users <- N::MATCH|_::{user_type}|{ + UserType::User => _::{user_field}, + UserType::Admin => _::{user_field}, + } + RETURN users -// Enum::UserType { -// NormalUser(User), -// AdminUser(Admin), -// GuestUser(Guest), -// } -// -// QUERY GetAdmins() => -// users <- N::MATCH|_|{ -// UserType::NormalUser(user) => user::{user_field}, -// UserType::AdminUser(admin) => admin::{admin_field}, -// UserType::GuestUser(guest) => guest::{guest_field} -// } -// RETURN users \ No newline at end of file +QUERY Search() => + nodes <- SearchV(queryText)::MATCH|_|{ + N::User(user) => user::{user_field}, + ? => SKIP, + } + RETURN nodes \ No newline at end of file From e330907f024c8b7583553d5f27d68906e3717b55 Mon Sep 17 00:00:00 2001 From: xav-db Date: Tue, 26 Aug 2025 15:09:01 +0100 Subject: [PATCH 2/2] updating grammar --- helix-db/src/grammar.pest | 31 ++++++------------- .../tests/adding_chunk_to_memory/schema.hx | 2 +- 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/helix-db/src/grammar.pest b/helix-db/src/grammar.pest index 92c2e5b8..800943e2 100644 --- a/helix-db/src/grammar.pest +++ b/helix-db/src/grammar.pest @@ -7,7 +7,7 @@ source = { SOI ~ (schema_def | migration_def | query_def)* ~ EOI } // --------------------------------------------------------------------- // Schema definitions // --------------------------------------------------------------------- -schema_def = {( schema_version ~ "{" ~ (vector_def | node_def | edge_def | enum_def)* ~ "}") | (vector_def | node_def | edge_def | enum_def) } +schema_def = {( schema_version ~ "{" ~ (vector_def | node_def | edge_def)* ~ "}") | (vector_def | node_def | edge_def) } vector_def = { "V::" ~ identifier_upper ~ node_body? } node_def = { "N::" ~ identifier_upper ~ node_body? } edge_def = { "E::" ~ identifier_upper ~ edge_body } @@ -18,16 +18,9 @@ field_defs = { (field_def ~ ",")* ~ (field_def ~ ","?)? } field_def = { index? ~ identifier ~ ":" ~ param_type ~ (default)? } index= { "INDEX" } default = { "DEFAULT" ~ (now | float | integer | boolean | string_literal | none) } -// optional = { "OPTIONAL" } -properties = { "Properties" ~ ":" ~ "{" ~ field_defs? ~ "}" } +properties = { "Properties" ~ optional_param? ~ ":" ~ "{" ~ field_defs? ~ "}" } schema_version = { "schema::" ~ integer } - -enum_def = { "Enum::" ~ identifier_upper ~ "{" ~ enum_body ~ "}" } -enum_body = { "{" ~ enum_fields ~ "}" } -enum_fields = { (enum_field ~ ",")* ~ (enum_field ~ ","?)? } -enum_field = { identifier_upper ~ ("(" ~ identifier_upper ~ ")")? } - // --------------------------------------------------------------------- // Migration definitions // --------------------------------------------------------------------- @@ -50,14 +43,6 @@ edge_migration = { "{" ~ "Properties" ~ ":" ~ "{" ~ field_migrations ~ "}" ~ "}" migration_item_mapping = { item_def ~ "=>" ~ (item_def | anon_decl) ~ (node_migration | edge_migration) } migration_body = { migration_item_mapping* } -// --------------------------------------------------------------------- -// Macros -// --------------------------------------------------------------------- -built_in_macro = { mcp_macro | model_macro } -mcp_macro = { "#[mcp]" } - -model_macro = { "#[" ~ "model" ~ "(" ~ model_name ~ ")" ~ "]" } -model_name = { identifier | string_literal } // --------------------------------------------------------------------- // Query definitions @@ -76,7 +61,7 @@ get_stmt = { identifier ~ "<-" ~ evaluates_to_anything } traversal = { (start_node | start_edge | search_vector | start_vector) ~ step* ~ last_step? } id_traversal = { identifier ~ ((step+ ~ last_step?) | last_step) } anonymous_traversal = { "_" ~ ((step+ ~ last_step?) | last_step)? } -step = { "::" ~ ((variable_declaration~graph_step) | order_by | where_step | closure_step | object_step | exclude_field | count | ID | range_step | AddE) } +step = { "::" ~ (graph_step | order_by | where_step | closure_step | object_step | exclude_field | count | ID | range_step | AddE) } last_step = { "::" ~ (bool_operations | update) } // change this for loop to be able to take traversals etc in the future. for_loop = { "FOR" ~ for_argument ~ "IN" ~ identifier ~ "{" ~ query_body ~ "}" } @@ -239,8 +224,14 @@ exclude_field = { "!" ~ "{" ~ identifier ~ ("," ~ identifier)* ~ "}" } closure_step = { "|" ~ identifier ~ "|" ~ object_step } spread_object = { ".." ~ ","?} mapping_field = { (identifier ~ (":" ~ (anonymous_traversal | evaluates_to_anything | object_step))) | identifier } -variable_declaration = { "|" ~ identifier ~ "|" } +// --------------------------------------------------------------------- +// Macros +// --------------------------------------------------------------------- +built_in_macro = { mcp_macro | model_macro } +mcp_macro = { "#[mcp]" } +model_macro = { "#[" ~ "model" ~ "(" ~ model_name ~ ")" ~ "]" } +model_name = { identifier | string_literal } // --------------------------------------------------------------------- // Match steps @@ -252,7 +243,6 @@ match_statement = { match_type ~ "=>" ~ match_value } match_type = { identifier_upper ~ "::" ~ identifier_upper ~ ("(" ~ identifier ~ ")")?} match_value = { "{" ~ query_body ~ "}" | traversal | id_traversal | anonymous_traversal | none | identifier } - // --------------------------------------------------------------------- // Types // --------------------------------------------------------------------- @@ -283,4 +273,3 @@ now = { "NOW" } // --------------------------------------------------------------------- WHITESPACE = _{ " " | "\t" | "\n" | "\r" } COMMENT = _{ "//" ~ (!"\n" ~ ANY)* } - diff --git a/hql-tests/tests/adding_chunk_to_memory/schema.hx b/hql-tests/tests/adding_chunk_to_memory/schema.hx index 585d8641..6faefc8a 100644 --- a/hql-tests/tests/adding_chunk_to_memory/schema.hx +++ b/hql-tests/tests/adding_chunk_to_memory/schema.hx @@ -1,6 +1,6 @@ // User node - represents users of the memory system with email indexing N::User { - email: String, + email?: String, name: String, created_at: String, updated_at: String,