Add CubeSchema - Generate Ecto schemas for querying Cube cubes#7
Open
Add CubeSchema - Generate Ecto schemas for querying Cube cubes#7
Conversation
…ns without learning a new query API.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Merge after cube-js/cube#10308 is merged
This is tested against future Cube version: cube-js/cube#10308
Summary
This PR adds
PowerOfThree.CubeSchema, a new macro that generates Ecto schemas for querying Cube cubes via the PostgreSQL wire protocol. This completes the bidirectional flow between Ecto and Cube.Motivation
Power of Three originally provided one direction:
This PR adds the reverse direction:
This enables Elixir developers to query Cube using familiar Ecto patterns without learning a new query API.
Dependency
This feature requires cube-js/cube#10308 which fixes Postgrex/Ecto type bootstrap in Cube SQL API.
New Module:
PowerOfThree.CubeSchemaTwo Ways to Define Schemas
1. Explicit definition with DSL:
2. Auto-generation from YAML:
Usage with Ecto.Query
Type Mapping
string:stringnumber:floattime:utc_datetimeboolean:booleancountmeasure:integercount_distinct:integersum/avg/min/max:floatSupported Ecto Operations
Repo.all/onewhere:with literalswhere: o.brand == "X"where:with paramswhere: o.brand == ^var(strings)where:with AND/ORwhere:with !=limit:/offset:order_by:asc/descgroup_by:singlegroup_by:multisum(),count()select:tuple{o.brand, sum(o.total)}select:map%{brand: o.brand, total: sum(o.total)}select:list[o.brand, sum(o.total)]Known Limitations
Query Syntax Constraints
where: x in ^listwhere: x == "a" or x == "b"where: x not in ^listwhere: x != "a" and x != "b"fragment(...)having: count() > ^paramMeasure Aggregation Rules
sum(o.count)not justo.countSUM()on them - use only with count-compatible aggregations1.0e3::float) are not supported by Cube SQLExample Patterns
The Complete Vision
Nothing is duplicated. Nothing is reinterpreted. Intellectual economy applied to analytics architecture.
Files Changed
lib/power_of_three/cube_schema.ex(new) - The CubeSchema macro moduletest/cube_schema_live_test.exs(new) - Live integration teststest/cube_schema_extended_live_test.exs(new) - Extended live testsmix.exs- Addedpostgrexdependency for live testsTesting
45 live integration tests against Cube SQL API on port 9432:
Repo.all,Repo.one, limit, offsetRun tests with:
mix test --include live_cubeRequires Cube SQL API running on localhost:9432.