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

Function validate_path_constructor

graphlite/src/ast/validator.rs:1299–1340  ·  view source on GitHub ↗

Validate PATH constructor expressions

(
    path_constructor: &crate::ast::PathConstructor,
    ctx: &mut ValidationContext,
    errors: &mut Vec<ValidationError>,
)

Source from the content-addressed store, hash-verified

1297
1298/// Validate PATH constructor expressions
1299fn validate_path_constructor(
1300 path_constructor: &crate::ast::PathConstructor,
1301 ctx: &mut ValidationContext,
1302 errors: &mut Vec<ValidationError>,
1303) {
1304 // Validate each element in the PATH constructor
1305 for element in &path_constructor.elements {
1306 validate_expression(element, ctx, errors);
1307
1308 // Check that element types are suitable for PATH constructor
1309 if let Ok(element_type) = infer_expression_type(element, ctx) {
1310 match element_type {
1311 GqlType::String { .. }
1312 | GqlType::Integer
1313 | GqlType::BigInt
1314 | GqlType::SmallInt
1315 | GqlType::Double
1316 | GqlType::Float { .. }
1317 | GqlType::Real => {
1318 // These types are valid for PATH elements (can be converted to string IDs)
1319 }
1320 _ => {
1321 errors.push(ValidationError {
1322 message: format!(
1323 "PATH constructor element must be a string or number type, got: {:?}",
1324 element_type
1325 ),
1326 location: Some(crate::ast::Location::default()),
1327 error_type: ValidationErrorType::Type,
1328 });
1329 }
1330 }
1331 }
1332 }
1333
1334 // PATH elements should follow node-edge-node pattern (optional validation)
1335 if path_constructor.elements.len().is_multiple_of(2) && path_constructor.elements.len() > 2 {
1336 // Even number of elements > 2 might indicate incomplete path
1337 // This is a warning rather than an error since PATH[node, edge] might be valid
1338 // in some contexts
1339 }
1340}
1341
1342/// Validate CAST expressions
1343fn validate_cast_expression(

Callers 1

validate_expressionFunction · 0.85

Calls 3

validate_expressionFunction · 0.85
infer_expression_typeFunction · 0.85
lenMethod · 0.45

Tested by

no test coverage detected