Kotoba Execution
Complete query execution and planning engine for the Kotoba graph database. Provides comprehensive GQL (Graph Query Language) parsing, optimization, and execution capabilities.
๐ฏ Overview
Kotoba Execution serves as the core query processing layer, transforming GQL queries into optimized execution plans and delivering high-performance graph traversals. It provides:
- Complete GQL Implementation: Full Graph Query Language support with advanced features
- Cost-Based Optimization: Intelligent query planning with multiple execution strategies
- Rich Expression Engine: 50+ built-in functions for graph, math, string, and collection operations
- Streaming Execution: Memory-efficient processing for large result sets
๐๏ธ Architecture
Query Processing Pipeline
GQL Query โ Parser โ Logical Plan โ Optimizer โ Physical Plan โ Executor โ Results
โ โ โ โ โ โ โ
Tokenize Parse Rewrite Optimize Execute Evaluate Stream
Core Components
GQL Parser (gql_parser.rs
)
// Complete GQL syntax support
let mut parser = new;
let plan = parser.parse?;
Expression Evaluator (executor.rs
)
// Rich expression evaluation with 50+ functions
let expr = Fn ;
// Evaluates to: Value::Int(5)
Query Planning (planner/
)
- Logical Planner: GQL โ Logical algebra with rewrite rules
- Physical Planner: Cost-based operator selection and join ordering
- Optimizer: Rule-based query transformations and predicate pushdown
๐ Quality Metrics
Metric | Status |
---|---|
Compilation | โ Clean (with warnings to fix) |
Tests | โ Comprehensive test suite |
Documentation | โ Complete API docs |
Performance | โ Cost-based optimization |
GQL Compliance | โ Full syntax support |
๐ง Usage
Basic Query Execution
use *;
use ;
use GraphRef;
// Create execution components
let executor = new;
let mut parser = new;
// Parse and execute GQL query
let query = "MATCH (n:Person) WHERE n.age > 25 RETURN n.name, n.age";
let plan = parser.parse?;
let graph = new;
let catalog = empty;
let results = executor.execute_plan?;
Advanced Expression Evaluation
use QueryExecutor;
// Create executor and test data
let executor = new;
let row = Row ;
// Evaluate complex expressions
let expr = Fn ;
let result = executor.evaluate_expr;
// Result: Value::Int(3)
๐ Ecosystem Integration
Kotoba Execution is the query processing foundation:
Crate | Purpose | Integration |
---|---|---|
kotoba-core |
Required | Base types and IR definitions |
kotoba-graph |
Required | Graph data structures for execution |
kotoba-storage |
Required | Index and storage access |
kotoba-server |
Required | HTTP query endpoints |
kotoba-rewrite |
Optional | Additional rewrite rules |
๐งช Testing
Test Coverage:
- โ GQL parser correctness and tokenization
- โ Expression evaluation for all function types
- โ Query executor creation and basic operations
- โ Math, string, and conversion functions
- โ Error handling and edge cases
Function Categories Tested
- Graph Functions:
degree()
,labels()
,properties()
- Math Functions:
abs()
,sqrt()
,sin()
,cos()
- String Functions:
length()
,toUpper()
,toLower()
,trim()
- Conversion Functions:
toString()
,toInteger()
๐ Performance
- Cost-Based Optimization: Intelligent selection of execution plans
- Predicate Pushdown: Filters applied as early as possible
- Index-Aware Execution: Automatic index utilization
- Memory-Efficient Streaming: Low memory footprint for large queries
- Parallel Processing Ready: Foundation for concurrent execution
๐ Security
- Type-Safe Evaluation: Strongly typed expression evaluation
- Input Validation: Comprehensive GQL syntax validation
- Resource Limits: Protection against expensive queries
- No Code Injection: Safe expression evaluation without eval()
๐ API Reference
Core Types
- [
QueryExecutor
] - Main execution engine - [
GqlParser
] - GQL tokenizer and parser - [
Expr
] - Expression AST for evaluation - [
LogicalPlan
] - Logical query representation - [
PhysicalPlan
] - Optimized execution plan
Expression Functions
- Graph:
degree()
,labels()
,keys()
,hasLabel()
,properties()
- Math:
abs()
,sqrt()
,sin()
,cos()
,tan()
,log()
,exp()
- String:
length()
,substring()
,startsWith()
,endsWith()
,contains()
- Collections:
size()
,isEmpty()
,reverse()
- Conversion:
toString()
,toInteger()
,toFloat()
,toBoolean()
Planning Components
- [
LogicalPlanner
] - GQL to logical algebra - [
QueryOptimizer
] - Rule-based optimization - [
PhysicalPlanner
] - Cost-based physical planning
๐ค Contributing
See the main Kotoba repository for contribution guidelines.
๐ License
Licensed under MIT OR Apache-2.0. See LICENSE for details.