|
1 | 1 | # lkml2cube
|
2 | 2 |
|
3 |
| -lkml2cube is a tool that converts LookML models into Cube data models. |
| 3 | +A comprehensive tool for bidirectional conversion between LookML and Cube data models. |
4 | 4 |
|
5 |
| -## Usage |
| 5 | +## Features |
6 | 6 |
|
7 |
| -There are two main commands, `cubes` and `views`. Both commands read all the files in the provided input parameter, including those referenced by the LookML keyword `includes`. |
8 |
| -The difference is that the `cubes` command only creates Cube's `cube` model definitions, while the `views` command creates `cube` and `view` model definitions. LookML syntax defines the join relationships at the explore level (equivalent to Cube's `view`). That's why explores need special treatment and why they are ignored in the lkml2cube `cubes` command. |
| 7 | +- **LookML → Cube**: Convert LookML views and explores to Cube model definitions |
| 8 | +- **Cube → LookML**: Generate production-ready LookML from Cube meta API |
| 9 | +- **Smart Detection**: Automatically distinguishes between Cube cubes (→ LookML views) and Cube views (→ LookML explores) |
| 10 | +- **Production Ready**: Generates LookML with includes, proper joins, primary keys, and drill fields |
| 11 | +- **Rich Output**: Beautiful console tables showing generated files |
9 | 12 |
|
10 |
| -### Install |
| 13 | +## Installation |
11 | 14 |
|
12 | 15 | ```sh
|
13 | 16 | pip install lkml2cube
|
14 | 17 | ```
|
15 | 18 |
|
16 |
| -### Convert LookML views into Cube YAML definition. |
| 19 | +## Commands |
| 20 | + |
| 21 | +lkml2cube provides three main commands for different conversion scenarios: |
| 22 | + |
| 23 | +### 1. `cubes` - LookML Views → Cube Models |
| 24 | + |
| 25 | +Converts LookML view files into Cube YAML definitions (cubes only). |
| 26 | + |
| 27 | +```sh |
| 28 | +# Convert a single LookML view |
| 29 | +lkml2cube cubes path/to/orders.view.lkml --outputdir examples/ |
| 30 | + |
| 31 | +# Parse and inspect LookML structure |
| 32 | +lkml2cube cubes --parseonly path/to/orders.view.lkml |
| 33 | + |
| 34 | +# Convert with custom root directory for includes |
| 35 | +lkml2cube cubes views/orders.view.lkml --outputdir models/ --rootdir ../my_project/ |
| 36 | +``` |
| 37 | + |
| 38 | +### 2. `views` - LookML Explores → Cube Models |
| 39 | + |
| 40 | +Converts LookML explore files into Cube YAML definitions (cubes + views with joins). |
17 | 41 |
|
18 | 42 | ```sh
|
19 |
| -lkml2cube cubes path/to/file.view.lkml --outputdir examples/ |
| 43 | +# Convert LookML explores with join relationships |
| 44 | +lkml2cube views path/to/sales_analysis.explore.lkml --outputdir examples/ |
| 45 | + |
| 46 | +# Print YAML output to console |
| 47 | +lkml2cube views --printonly path/to/sales_analysis.explore.lkml |
20 | 48 | ```
|
21 | 49 |
|
22 |
| -### Show Python dict representation of the LookerML object |
| 50 | +### 3. `explores` - Cube Meta API → LookML ✨ **NEW** |
| 51 | + |
| 52 | +Generates production-ready LookML files from Cube's meta API endpoint. |
23 | 53 |
|
24 | 54 | ```sh
|
25 |
| -lkml2cube cubes --parseonly path/to/file.view.lkml |
| 55 | +# Generate LookML from Cube deployment |
| 56 | +lkml2cube explores "https://your-cube.com/cubejs-api/v1/meta" \ |
| 57 | + --token "your-jwt-token" \ |
| 58 | + --outputdir looker_models/ |
| 59 | + |
| 60 | +# Preview the parsed Cube model |
| 61 | +lkml2cube explores "https://your-cube.com/cubejs-api/v1/meta" \ |
| 62 | + --token "your-jwt-token" \ |
| 63 | + --parseonly |
| 64 | + |
| 65 | +# Print generated LookML to console |
| 66 | +lkml2cube explores "https://your-cube.com/cubejs-api/v1/meta" \ |
| 67 | + --token "your-jwt-token" \ |
| 68 | + --printonly |
| 69 | +``` |
| 70 | + |
| 71 | +## What Gets Generated |
| 72 | + |
| 73 | +### From Cube Cubes → LookML Views |
| 74 | + |
| 75 | +```yaml |
| 76 | +# Cube cube definition |
| 77 | +cubes: |
| 78 | + - name: orders |
| 79 | + sql_table: public.orders |
| 80 | + dimensions: |
| 81 | + - name: id |
| 82 | + type: number |
| 83 | + sql: "{TABLE}.id" |
| 84 | +``` |
| 85 | +
|
| 86 | +**Generates:** |
| 87 | +
|
| 88 | +```lookml |
| 89 | +view orders { |
| 90 | + label: "Orders" |
| 91 | + sql_table_name: public.orders ;; |
| 92 | + |
| 93 | + dimension: id { |
| 94 | + label: "Order ID" |
| 95 | + type: number |
| 96 | + primary_key: yes |
| 97 | + sql: ${TABLE}.id ;; |
| 98 | + } |
| 99 | + |
| 100 | + measure: count { |
| 101 | + type: count |
| 102 | + drill_fields: [id, name] |
| 103 | + } |
| 104 | +} |
| 105 | +``` |
| 106 | + |
| 107 | +### From Cube Views → LookML Explores |
| 108 | + |
| 109 | +```yaml |
| 110 | +# Cube view with joins |
| 111 | +views: |
| 112 | + - name: order_analysis |
| 113 | + cubes: |
| 114 | + - join_path: orders |
| 115 | + - join_path: customers |
| 116 | +``` |
| 117 | +
|
| 118 | +**Generates:** |
| 119 | +
|
| 120 | +```lookml |
| 121 | +include: "/views/orders.view.lkml" |
| 122 | +include: "/views/customers.view.lkml" |
| 123 | + |
| 124 | +explore order_analysis { |
| 125 | + label: "Order Analysis" |
| 126 | + view_name: orders |
| 127 | + |
| 128 | + join: customers { |
| 129 | + view_label: "Customers" |
| 130 | + type: left_outer |
| 131 | + relationship: many_to_one |
| 132 | + sql_on: ${orders.customer_id} = ${customers.id} ;; |
| 133 | + } |
| 134 | +} |
26 | 135 | ```
|
27 | 136 |
|
28 |
| -### Convert LookML Explores into Cube's views YAML definition. |
| 137 | +## Advanced Usage |
| 138 | + |
| 139 | +### Working with Includes |
| 140 | + |
| 141 | +The tool automatically handles LookML `include` statements and can resolve relative paths: |
29 | 142 |
|
30 | 143 | ```sh
|
31 |
| -lkml2cube views path/to/file.explore.lkml --outputdir examples/ |
| 144 | +# Use --rootdir to resolve include paths |
| 145 | +lkml2cube views explores/sales.explore.lkml \ |
| 146 | + --outputdir output/ \ |
| 147 | + --rootdir /path/to/lookml/project/ |
32 | 148 | ```
|
33 | 149 |
|
34 |
| -### Use the `--rootdir` parameter to prepend a path for all `include:` paths. |
| 150 | +### Authentication for Cube API |
| 151 | + |
| 152 | +The `explores` command requires a valid JWT token for Cube authentication: |
| 153 | + |
35 | 154 | ```sh
|
36 |
| -lkml2cube views ../my_lookml_project/views/countries.view.lkml --outputdir model/ --rootdir ../my_lookml_project/ |
| 155 | +# Get your token from Cube's authentication |
| 156 | +export CUBE_TOKEN="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." |
| 157 | + |
| 158 | +lkml2cube explores "https://your-cube.com/cubejs-api/v1/meta" \ |
| 159 | + --token "$CUBE_TOKEN" \ |
| 160 | + --outputdir looker_models/ |
| 161 | +``` |
| 162 | + |
| 163 | +## Output Structure |
| 164 | + |
| 165 | +The tool creates organized directory structures: |
| 166 | + |
| 167 | +``` |
| 168 | +outputdir/ |
| 169 | +├── views/ # LookML views or Cube cubes → LookML views |
| 170 | +│ ├── orders.view.lkml |
| 171 | +│ └── customers.view.lkml |
| 172 | +└── explores/ # Cube views → LookML explores |
| 173 | + └── sales_analysis.explore.lkml |
37 | 174 | ```
|
38 | 175 |
|
| 176 | +## Key Features |
| 177 | + |
| 178 | +- **Smart Detection**: Automatically identifies Cube cubes vs views based on `aliasMember` usage |
| 179 | +- **Include Generation**: Explores automatically include referenced view files |
| 180 | +- **Primary Key Detection**: Auto-detects ID fields and marks them as primary keys |
| 181 | +- **Rich Metadata**: Preserves labels, descriptions, and data types |
| 182 | +- **Join Relationships**: Generates proper LookML join syntax with relationships |
| 183 | +- **Production Ready**: Follows LookML best practices and conventions |
| 184 | + |
0 commit comments