A high-performance time series database written in Rust, featuring the innovative DataCrate concept for organizing time series data. This database is optimized specifically for time-based data operations with built-in SQL-like query capabilities and efficient data management.
- DataCrate Organization: Logical grouping of time series tables with individual retention policies
- Time Series Engine: Optimized storage and indexing for time-stamped data
- SQL-like Query Language: Flexible querying with time range filtering and aggregation
- Schema Management: Define fields and tags for structured time series data
- Efficient Indexing: Separate indices for time-based and tag-based queries
- Retention Policies: Automatic data expiration at both DataCrate and table levels
- DataCrate Concept: Organize time series data into logical collections (similar to databases)
- Multiple Tables: Each datacrate can contain multiple tables with different schemas
- Retention Policies: Set retention at both datacrate and table level
- Schema Management: Define fields and tags for structured data storage
- Efficient Indexing: Optimized for both time-based and tag-based queries
- Command Structure: Dedicated command sets for crate, table, and data operations
- Time Range Queries: Efficient filtering by timestamp ranges
- Tag-based Filtering: Filter by metadata tags (host, region, etc.)
- Field Selection: Choose specific fields to retrieve
- Aggregation Functions: COUNT, SUM, AVG, MIN, MAX with time grouping
- Sorting and Limiting: ORDER BY timestamp with result limits
- Complex WHERE Clauses: Multiple conditions with AND/OR logic
- Compression: Automatic data compression for storage efficiency
- Time-based Partitioning: Efficient data organization by time periods
- Concurrent Access: Thread-safe operations for multiple clients
- Memory Management: Configurable caching with high hit ratios
- Batch Operations: Optimized bulk insert and query operations
There are multiple ways to run the application:
Simply run the run.cmd script and select an option:
run.cmd
To run a demonstration of the time series database functionality:
run_tsdb_demo.cmd
To run a demonstration of the datacrate-based time series database functionality:
run_datacrate_demo.cmd
To run the server:
cargo run --bin my-database-app
To run the client:
cargo run --bin client
Make sure the server is running before connecting with the client.
Once the client is running, you can use the following commands:
| Command | Description | Example |
|---|---|---|
TSDB_CREATE_CRATE <name> "<description>" [retention_days] |
Create a new DataCrate | TSDB_CREATE_CRATE metrics "System metrics" 90 |
TSDB_LIST_CRATES |
List all DataCrates | TSDB_LIST_CRATES |
TSDB_GET_CRATE <name> |
Get DataCrate information | TSDB_GET_CRATE metrics |
TSDB_DELETE_CRATE <name> |
Delete a DataCrate | TSDB_DELETE_CRATE metrics |
| Command | Description | Example |
|---|---|---|
TSDB_CREATE_TABLE <crate> <table> <field_name>:<type> [<tag_name>, ...] |
Create a table | TSDB_CREATE_TABLE metrics cpu_usage value:float host,region |
TSDB_LIST_TABLES <crate> |
List tables in a crate | TSDB_LIST_TABLES metrics |
TSDB_GET_SCHEMA <crate> <table> |
Get table schema | TSDB_GET_SCHEMA metrics cpu_usage |
TSDB_DELETE_TABLE <crate> <table> |
Delete a table | TSDB_DELETE_TABLE metrics cpu_usage |
| Command | Description | Example |
|---|---|---|
TSDB_INSERT <crate> <table> <timestamp> <field>=<value> [<tag>=<value>, ...] |
Insert time series data | TSDB_INSERT metrics cpu_usage 1645123200 value=85.2 host=server1,region=us-east |
TSDB_QUERY <crate> [<table>] [START <timestamp>] [END <timestamp>] [WHERE <conditions>] |
Query time series data | TSDB_QUERY metrics cpu_usage START 1645123200 END 1645126800 WHERE host=server1 |
TSDB_DELETE <crate> <table> START <start> END <end> [WHERE <conditions>] |
Delete time series data | TSDB_DELETE metrics cpu_usage START 1645123200 END 1645126800 |
You can also use SQL-like syntax for complex queries:
SELECT value, timestamp FROM cpu_usage
WHERE host = 'server1' AND timestamp >= 1645123200
ORDER BY timestamp DESC LIMIT 100;
SELECT AVG(value) as avg_cpu, COUNT(*) as samples
FROM cpu_usage
WHERE timestamp >= 1645123200
GROUP BY timestamp / 3600;| Command | Description | Example |
|---|---|---|
TS_INSERT <measurement> <timestamp> <field>=<value> [<tag>=<value>, ...] |
Insert time series data | TS_INSERT cpu_usage 1645123200 value=85.2 host=server1 |
TS_QUERY <measurement> [START <timestamp>] [END <timestamp>] [WHERE <conditions>] |
Query time series data | TS_QUERY cpu_usage START 1645123200 WHERE host=server1 |
SELECT <fields> FROM <measurement> WHERE <conditions> |
Query data from a measurement | SELECT value, unit FROM temperature_reading WHERE value > 20 |
DELETE FROM <measurement> WHERE <conditions> |
Delete data from a measurement | DELETE FROM temperature_reading WHERE value < 0 |
CREATE RETENTION POLICY <name> ON <measurement> DURATION <duration> REPLICATION <n> |
Create a retention policy | CREATE RETENTION POLICY one_week ON temperature_reading DURATION 7d REPLICATION 1 |
SHOW MEASUREMENTS |
List all measurements | SHOW MEASUREMENTS |
SHOW TAG KEYS FROM <measurement> |
Show tag keys for a measurement | SHOW TAG KEYS FROM temperature_reading |
SHOW FIELD KEYS FROM <measurement> |
Show field keys for a measurement | SHOW FIELD KEYS FROM temperature_reading |
my-database-app
├── src
│ ├── main.rs # Entry point and server implementation
│ ├── database.rs # Core database operations
│ ├── compression.rs # Data compression utilities
│ ├── storage
│ │ ├── disk.rs # Persistent storage with WAL
│ │ └── memory.rs # In-memory storage
│ ├── query
│ │ ├── parser.rs # SQL and ML command parser
│ │ └── executor.rs # Query execution engine
│ ├── tsdb # Time Series Database
│ │ ├── types.rs # TSDB data structures
│ │ ├── index.rs # Time and tag indexing
│ │ ├── query.rs # SQL-like query parser and executor
│ │ └── storage.rs # TSDB storage engine
│ └── ml
│ ├── predictor.rs # ML model management
│ ├── feature_engineering.rs # Automated feature engineering
│ └── time_series.rs # Time series analysis
├── tests
│ ├── integration_tests.rs # Integration tests
│ └── tsdb_tests.rs # TSDB specific tests
├── Cargo.toml # Project configuration
└── README.md # Documentation
disk.rs: Implements persistent storage with Write-Ahead Loggingmemory.rs: Provides high-performance in-memory storagecompression.rs: Handles data compression using multiple algorithms
types.rs: Core TSDB data structures and schemasindex.rs: Efficient time-based and tag-based indexingquery.rs: SQL-like query language for time series datastorage.rs: Specialized storage engine for time series data
parser.rs: Parses both traditional SQL and ML-specific commandsexecutor.rs: Executes queries and manages transaction flow
predictor.rs: Manages ML models, training, and predictionsfeature_engineering.rs: Automates feature selection and engineeringtime_series.rs: Handles time series analysis and forecasting
-- Insert data
INSERT 1 {"temperature": 25.5, "humidity": 60}
-- Query data
GET 1
-- List all records
LIST
-- Count records
COUNT
-- Search records by content
SEARCH temperature
-- Delete data
DELETE 1
-- Create a measurement
TS.CREATE "{\"name\":\"weather\",\"fields\":{\"temperature\":0.0,\"humidity\":0.0,\"pressure\":0.0},\"retention_policy\":{\"Duration\":2592000}}"
-- Insert time series data
TS.INSERT weather "{\"timestamp\":\"2025-06-06T12:00:00Z\",\"fields\":{\"temperature\":72.5,\"humidity\":45.0,\"pressure\":1013.2},\"tags\":{\"location\":\"NYC\",\"station\":\"central\"}}"
-- Simple query
TS.QUERY "SELECT temperature, humidity FROM weather WHERE TIME >= '2025-06-01T00:00:00Z' AND TIME <= '2025-06-07T00:00:00Z'"
-- Query with tag filter
TS.QUERY "SELECT temperature, humidity FROM weather WHERE location = 'NYC'"
-- Aggregation query
TS.QUERY "SELECT AVG(temperature), MAX(humidity), MIN(pressure) FROM weather GROUP BY TIME(6h)"
-- List all measurements
TS.LIST
For more detailed documentation, see TSDB.md.
-- Create and train a predictor
CREATE PREDICTOR weather_forecast
FROM weather_data
PREDICT temperature
USING features (humidity, pressure, wind_speed)
WITH time_series_settings (
time_column='timestamp',
horizon=24,
window_size=168
);
-- Make predictions
SELECT temperature, confidence, explanation
FROM weather_forecast
WHERE humidity = 65 AND pressure = 1013;
-- Get feature importance
EXPLAIN weather_forecast
WITH feature_importance = true;-- Create a time series predictor
CREATE PREDICTOR stock_forecast
FROM stock_data
PREDICT price
USING features (volume, open, close, high, low)
WITH time_series_settings (
time_column='date',
horizon=7,
window_size=30
);
-- Get forecast with confidence intervals
SELECT price, confidence_interval, seasonal_components
FROM stock_forecast
NEXT 7 DAYS;-
Install Rust (if not already installed):
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
-
Clone and build the project:
git clone <repository-url> cd my-database-app cargo build --release
-
Run the database server:
cargo run --release
The server will start on localhost:8080 by default.
After running the application, you can interact with the database through the provided commands. Refer to the documentation in the source files for detailed usage instructions.
Contributions are welcome! Please open an issue or submit a pull request for any enhancements or bug fixes.