| Crates.io | hyperQL |
| lib.rs | hyperQL |
| version | 0.1.0 |
| created_at | 2025-11-03 03:38:25.776183+00 |
| updated_at | 2025-11-03 03:38:25.776183+00 |
| description | Query language for hyperspatial graph databases with temporal and spatial semantics |
| homepage | |
| repository | https://github.com/tomWhiting/hyperQL |
| max_upload_size | |
| id | 1913858 |
| size | 1,313,783 |
HyperQL is a revolutionary query language that unifies SQL-like syntax with graph traversal, geometric queries, and cascade operations. It enables seamless querying across multiple paradigms within the Hyperspatial database's unified hyperbolic space.
Traditional databases force developers to use different query languages for different data models:
HyperQL eliminates this fragmentation by providing a unified syntax that can:
HyperQL seamlessly combines multiple query paradigms:
SELECT entity, measure_value, influence_score
FROM users u
TRAVERSE connected_to -> friends f
-> colleagues c
WHERE u.age > 25
AND similarity(u.interests, f.interests) > 0.8
AND hyperbolic_distance(u, f) < 2.0
AND c.department = 'engineering'
CASCADE user_influence FROM u TO f WITH decay_factor(0.9)
ORDER BY measure_value DESC, influence_score DESC
LIMIT 100
Leverage the hyperbolic positioning system for:
Powerful cascade operations for hierarchical computations:
-- Aggregate sales up organizational hierarchy
CASCADE total_sales = SUM(sales_amount)
FROM transactions t
PROPAGATE UP THROUGH organizational_hierarchy
-- Distribute budget down to teams
CASCADE budget_allocation = DISTRIBUTE(total_budget, allocation_weights)
FROM departments d
PROPAGATE DOWN TO teams
-- Compute influence propagation through social networks
CASCADE influence_score = INFLUENCE(base_score, decay_factor: 0.9)
FROM influencers i
PROPAGATE THROUGH social_network
WITH MAX_DEPTH 3
-- Traditional SQL-style query
SELECT name, age, email
FROM users
WHERE age > 30 AND department = 'engineering'
ORDER BY name
-- Find friends of friends with similar interests
SELECT u.name, f.name, ff.name
FROM users u
TRAVERSE friends -> f
-> friends -> ff
WHERE similarity(u.interests, ff.interests) > 0.7
AND u.id != ff.id
-- Find entities within hyperbolic distance
SELECT entity, hyperbolic_distance(entity, @anchor) as distance
FROM products
WHERE hyperbolic_distance(entity, @anchor) < 1.5
ORDER BY distance ASC
-- K-nearest neighbors with filtering
SELECT item, similarity(item.embedding, @query_vector) as score
FROM items
WHERE category = 'electronics'
AND price < 500
ORDER BY similarity(item.embedding, @query_vector) DESC
LIMIT 10
-- Recommendation system combining multiple signals
SELECT
p.title,
similarity(p.content_embedding, u.preference_vector) as content_score,
hyperbolic_distance(p, u) as position_score,
cascade_measure as social_score
FROM products p, users u
TRAVERSE u.friends -> f
WHERE u.id = @user_id
AND p.category IN @preferred_categories
AND similarity(p.content_embedding, u.preference_vector) > 0.6
CASCADE social_influence
FROM f.purchased_items
TO p
WITH influence_weight(f.social_score)
ORDER BY
(0.4 * content_score + 0.3 * position_score + 0.3 * social_score) DESC
LIMIT 20
-- Analyze movement patterns over time
SELECT
entity,
trajectory_similarity(entity.position_history, @pattern) as match_score
FROM moving_objects
WHERE timerange(entity.timestamps, '2024-01-01', '2024-12-31')
AND trajectory_length(entity.position_history) > 100
ORDER BY match_score DESC
Direct query execution for interactive analysis:
use hyperql::*;
#[tokio::main]
async fn main() -> Result<()> {
let engine = HyperQLEngine::new().await?;
let query = r#"
SELECT name, age
FROM users
WHERE age > 25
TRAVERSE friends -> f
WHERE similarity(interests, f.interests) > 0.8
"#;
let results = engine.execute(query).await?;
for row in results {
println!("{:?}", row);
}
Ok(())
}
Pre-compiled queries for production performance:
use hyperql::*;
#[tokio::main]
async fn main() -> Result<()> {
let engine = HyperQLEngine::new().await?;
// Compile query once
let compiled = engine.compile(r#"
SELECT entity, measure_value
FROM users u
TRAVERSE connected_to -> friends f
WHERE u.age > $age_threshold
AND similarity(u.interests, f.interests) > $similarity_threshold
CASCADE user_influence FROM u TO f
ORDER BY measure_value DESC
LIMIT $limit
"#).await?;
// Execute multiple times with different parameters
let results1 = compiled.execute(
&[("age_threshold", 25), ("similarity_threshold", 0.8), ("limit", 50)]
).await?;
let results2 = compiled.execute(
&[("age_threshold", 30), ("similarity_threshold", 0.9), ("limit", 20)]
).await?;
Ok(())
}
Combine compiled templates with dynamic query construction:
use hyperql::*;
#[tokio::main]
async fn main() -> Result<()> {
let engine = HyperQLEngine::new().await?;
// Build query dynamically
let mut query_builder = QueryBuilder::new()
.select(["entity", "score"])
.from("products")
.where_clause("category = $category")
.order_by("score DESC")
.limit(10);
// Add conditional traversal
if include_recommendations {
query_builder = query_builder
.traverse("recommended_by -> users u")
.where_and("u.trust_score > $trust_threshold");
}
let compiled = query_builder.compile(&engine).await?;
let results = compiled.execute(
&[("category", "electronics"), ("trust_threshold", 0.7)]
).await?;
Ok(())
}
HyperQL follows a traditional compiler pipeline optimized for hyperbolic queries:
βββββββββββββββ βββββββββββββββ βββββββββββββββ βββββββββββββββ
β Query βββββΆβ AST βββββΆβ Execution βββββΆβ Results β
β Text β β β β Plan β β β
βββββββββββββββ βββββββββββββββ βββββββββββββββ βββββββββββββββ
β β β β
βββββββββββ βββββββββββ βββββββββββ βββββββββββ
β Parser β βCompiler β βExecutor β βHyperbolicβ
β (Winnow)β β β β Engine β β Space β
βββββββββββ βββββββββββ βββββββββββ βββββββββββ
src/
βββ ast/ # Abstract syntax tree definitions
β βββ mod.rs
β βββ query.rs # Core query structures
β βββ expression.rs # Expression trees
β βββ literal.rs # Literal values
β βββ identifier.rs # Entity identifiers
β βββ function.rs # Function calls
β βββ predicate.rs # Boolean expressions
β βββ traverse.rs # Graph traversal
β βββ cascade.rs # Cascade operations
β βββ aggregate.rs # Aggregation functions
βββ parser/ # Winnow-based query parser
β βββ mod.rs
β βββ lexer.rs # Tokenization
β βββ grammar.rs # Grammar rules
β βββ combinators.rs # Parser combinators
βββ compiler/ # AST to execution plan compilation
β βββ mod.rs
β βββ planner.rs # Query planning
β βββ type_checker.rs # Type analysis
β βββ code_gen.rs # Code generation
βββ executor/ # Query execution engine
β βββ mod.rs
β βββ engine.rs # Execution engine
β βββ operators.rs # Query operators
β βββ results.rs # Result handling
βββ functions/ # Built-in function library
β βββ mod.rs
β βββ similarity.rs # Vector similarity functions
β βββ geometric.rs # Hyperbolic geometry functions
β βββ aggregates.rs # Aggregation functions
β βββ temporal.rs # Time-based functions
βββ cascade/ # Cascade system for measure propagation
β βββ mod.rs
β βββ propagation.rs # Propagation algorithms
β βββ measures.rs # Measure definitions
β βββ hierarchy.rs # Hierarchy detection
β βββ scheduler.rs # Cascade scheduling
βββ optimizer/ # Query optimization
β βββ mod.rs
β βββ rules.rs # Optimization rules
β βββ cost_model.rs # Cost modeling
β βββ statistics.rs # Query statistics
βββ context/ # Query execution context
β βββ mod.rs
β βββ variables.rs # Variable binding
β βββ scope.rs # Scope management
βββ runtime/ # Custom function runtime
β βββ mod.rs
β βββ lua.rs # Lua integration
β βββ wasm.rs # WASM integration
β βββ sandbox.rs # Security sandbox
β βββ function_registry.rs # Function registry
βββ ir/ # Intermediate representation
β βββ mod.rs
β βββ operators.rs # IR operators
β βββ plans.rs # Execution plans
β βββ serialization.rs # Plan serialization
βββ error.rs # Error types and handling
βββ types.rs # Core type definitions
βββ lib.rs # Library root with documentation
HyperQL is tightly integrated with the Hyperspatial database engine:
Extend HyperQL with custom Lua functions:
use hyperql::runtime::lua::LuaRuntime;
#[tokio::main]
async fn main() -> Result<()> {
let mut runtime = LuaRuntime::new().await?;
// Register custom Lua function
runtime.register_function("custom_similarity", r#"
function custom_similarity(vec1, vec2, weights)
local sum = 0
for i = 1, #vec1 do
sum = sum + (vec1[i] * vec2[i] * weights[i])
end
return sum / (#vec1 * #vec2)
end
"#).await?;
let engine = HyperQLEngine::with_runtime(runtime).await?;
// Use custom function in queries
let results = engine.execute(r#"
SELECT entity, custom_similarity(entity.embedding, @query_vector, @weights) as score
FROM products
WHERE custom_similarity(entity.embedding, @query_vector, @weights) > 0.8
ORDER BY score DESC
"#).await?;
Ok(())
}
Deploy compiled functions for maximum performance:
use hyperql::runtime::wasm::WasmRuntime;
#[tokio::main]
async fn main() -> Result<()> {
let mut runtime = WasmRuntime::new().await?;
// Load compiled WASM module
let wasm_bytes = std::fs::read("custom_functions.wasm")?;
runtime.load_module("custom", &wasm_bytes).await?;
let engine = HyperQLEngine::with_runtime(runtime).await?;
// Use WASM functions in queries
let results = engine.execute(r#"
SELECT entity, custom.fast_similarity(entity.embedding, @query) as score
FROM large_dataset
WHERE custom.fast_similarity(entity.embedding, @query) > 0.9
"#).await?;
Ok(())
}
Add HyperQL to your Cargo.toml:
[dependencies]
hyperQL = "0.1.0"
tokio = { version = "1.0", features = ["full"] }
use hyperql::*;
#[tokio::main]
async fn main() -> Result<()> {
// Initialize the HyperQL engine
let engine = HyperQLEngine::new().await?;
// Execute a simple query
let results = engine.execute(r#"
SELECT name, age
FROM users
WHERE age > 25
ORDER BY name
"#).await?;
// Process results
for row in results {
let name: String = row.get("name")?;
let age: i32 = row.get("age")?;
println!("{}: {} years old", name, age);
}
Ok(())
}
use hyperql::*;
use hyperql::config::*;
#[tokio::main]
async fn main() -> Result<()> {
let config = EngineConfig::builder()
.max_parallel_queries(100)
.enable_query_cache(true)
.cascade_thread_pool_size(16)
.lua_sandbox_enabled(true)
.wasm_memory_limit(1_000_000)
.build();
let engine = HyperQLEngine::with_config(config).await?;
// Engine is now ready with custom configuration
Ok(())
}
| Operation | Dataset Size | Performance |
|---|---|---|
| Simple Filter | 1M entities | ~50ms |
| Graph Traversal (depth 3) | 100K entities | ~200ms |
| K-NN Search (k=100) | 10M vectors | ~10ms |
| CASCADE Propagation | 1M hierarchy | ~500ms |
| Multi-Paradigm Query | 1M entities | ~150ms |
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
# Clone the repository
git clone https://github.com/hyperspatial/hyperQL.git
cd hyperQL
# Install dependencies
cargo build
# Run tests
cargo test
# Run examples
cargo run --example basic_query
This project is licensed under the MIT License - see the LICENSE file for details.
HyperQL - Revolutionizing database queries through unified multi-paradigm syntax and hyperbolic intelligence.
For more information, visit our documentation or join our community discussions.