Power of Three

Start with everything. Keep what performs. Pre-aggregate what matters.

A Type-Safe, Ergonomic Approach to Business Intelligence in Elixir

What is Power of Three

Power of Three is the Elixir library that provides macros to define a cube, dimensions and measures along side with Ecto.Schema.

These definitions are compiled to cube config files on mix compile.

The yaml output only for now.

The cube config files can then be shared with the running Cube.

Key Features

Auto-Generation with Compile-Time Feedback

Just write cube :my_cube, sql_table: "my_table" and get a complete, syntax-highlighted cube definition during compilation. PowerOfThree introspects your Ecto schema and generates sensible defaults for all dimensions and measures.

What gets auto-generated:

See the output with our blocky Minecraft-style lifter victoriously holding the barbell overhead - representing PowerOfThree successfully lifting heavy analytics workloads.

Read the full story: Auto-Generation Blog Post

Type Safety and Validation

All cube definitions are validated at compile time against your Ecto schemas. Field names, types, and SQL expressions are checked to ensure correctness.

Ergonomic DSL

Define cubes inline with your schemas using familiar Elixir syntax. No context switching between languages or files.

Quick Start

defmodule MyApp.Order do
  use Ecto.Schema
  use PowerOfThree

  schema "orders" do
    field :customer_email, :string
    field :total_amount, :float
    field :status, :string
    field :item_count, :integer
    timestamps()
  end

  # Just this - no block needed!
  cube :orders, sql_table: "orders"
end

Run mix compile and see:

Then refine: copy the output, delete what you don't need, add business logic.

Workflow: Scaffold → Refine → Own

How to: https://github.com/borodark/power_of_three/blob/master/ANALYTICS_WORKFLOW.md

Quick guide: https://github.com/borodark/power_of_three/blob/master/QUICK_REFERENCE.md

Please see separate project for examples showing working features.

What is Cube[.dev]

Solution for data analytics:

How to use cube:

TODO:

The future plans are bellow in the order of priority:

NOT TODO

Handle of cube's sql will not be done. Only sql_table. If you find yourself thinking adding support for sql, please fork and let the force be with you.

Why inline in Ecto Schema modules?

The names of tables and columns used in definitions of measures and dimensions are verifiable to be present in Ecto.Schema, hence why write/maintain another yaml or even worse json?

DEV environment

For crafting Cubes here is the docker: compose.yaml

Deployment Overview

Four types of containers:

Logical deployment

Two need the DB connection: API and Refresh Workers.

Router needs shared storage with Store Workers: S3 is recommended.

Installation

To install the Cube Core and run locally see here:

To use library

Available in Hex, the package can be installed by adding power_of_3 to your list of dependencies in mix.exs:

def deps do
  [
    {:power_of_3, "~> 0.1.3"}
  ]
end