Complete Example Scripts¶
The following examples demonstrate complete, runnable AQL scripts that exercise the major features of ArcaneDB.
Sales Analysis¶
create forced bucket Sales (
product: string,
price: float,
quantity: int,
revenue: float,
timestamp: int
);
insert into Sales ("Laptop", 999.99, 2, 1999.98, 1);
insert into Sales ("Mouse", 29.99, 5, 149.95, 2);
insert into Sales ("Keyboard", 79.99, 3, 239.97, 3);
insert into Sales ("Monitor", 299.99, 1, 299.99, 4);
# Sliding window over the 10 most recent records
analyze Sales revenue stream(10);
# Full time series: trend, forecast, and anomaly detection
analyze Sales revenue timeseries;
# Descriptive statistics for price and quantity
analyze Sales price statistics;
analyze Sales quantity statistics;
# Correlation between quantity sold and revenue generated
analyze Sales quantity correlation(revenue);
# Percentile queries
analyze Sales revenue percentile(90);
analyze Sales price percentile(50);
# Window functions over revenue
analyze Sales revenue window(row_number, 15);
analyze Sales revenue window(rank, 15);
analyze Sales revenue window(dense_rank, 15);
analyze Sales revenue window(percent_rank, 15);
Transactional Writes with Rollback¶
create forced unique bucket Puddles (
x: float,
y: float
);
# This block is rolled back; no records are persisted.
begin!;
insert into Puddles (x: 12.2, y: 4.5);
insert into Puddles (
[x: 14.4, y: 42.5],
[x: 20.2, y: 3.1],
[x: 4.0, y: 2.3]
);
rollback!;
# This block is committed; three records are persisted.
begin!;
insert into Puddles (
[x: 15.4, y: 45.8],
[x: 21.2, y: 3.2],
[x: 4.5, y: 2.4]
);
commit!;
Product Catalogue Management¶
create forced unique bucket Products (
name: string,
price: float,
in_stock: bool
);
truncate Products;
insert into Products (name: "Widget", price: 9.99, in_stock: true);
insert into Products (name: "Gadget", price: 24.99, in_stock: false);
insert into Products (name: "Doohickey", price: 4.49, in_stock: true);
commit!;
delete from Products where name = "Doohickey";
get * from Products;
get * from Products where in_stock = true;
get name, price from Products where in_stock = true order by price desc;
get avg(price), median(price), min(price), max(price), stddev(price)
from Products where in_stock = true;
get count(*) from Products;
export Products to csv("products.csv");
# Remove the price field from the schema permanently
drop price from Products;
describe Products;