-
Notifications
You must be signed in to change notification settings - Fork 6
Add tests & title, description to dimensions #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -162,8 +162,6 @@ cython_debug/ | |
|
||
|
||
# default location to write files | ||
cubes/ | ||
views/ | ||
examples/ | ||
|
||
|
||
|
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
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
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
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
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import pytest | ||
import yaml | ||
|
||
from os.path import join, dirname | ||
|
||
from lkml2cube.parser.loader import file_loader | ||
from lkml2cube.parser.views import parse_view | ||
from lkml2cube.parser.explores import parse_explores, generate_cube_joins | ||
|
||
# Dynamically calculate the root directory | ||
rootdir = join(dirname(__file__), "samples") | ||
|
||
|
||
class TestExamples: | ||
def test_simple_view(self): | ||
file_path = "lkml/views/orders.view.lkml" | ||
# print(join(rootdir, file_path)) | ||
lookml_model = file_loader(join(rootdir, file_path), rootdir) | ||
|
||
# lookml_model can't be None | ||
# if None it means file was not found or couldn't be parsed | ||
assert lookml_model is not None | ||
|
||
cube_def = parse_view(lookml_model) | ||
cube_def = generate_cube_joins(cube_def, lookml_model) | ||
|
||
# Convert the generated cube definition to a dictionary | ||
generated_yaml = yaml.safe_load(yaml.dump(cube_def, allow_unicode=True)) | ||
|
||
# print("Expected yaml:") | ||
# print(yaml.dump(generated_yaml, allow_unicode=True)) | ||
|
||
file_path = "cubeml/orders.yml" | ||
# print(join(rootdir, file_path)) | ||
with open(join(rootdir, file_path)) as f: | ||
cube_model = yaml.safe_load(f) | ||
|
||
# print(cube_model) | ||
|
||
# Compare the two dictionaries | ||
assert ( | ||
generated_yaml == cube_model | ||
), "Generated YAML does not match the expected YAML" | ||
|
||
assert True | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
cubes: | ||
- description: Orders | ||
dimensions: | ||
- name: id | ||
primary_key: true | ||
sql: '{CUBE}."ID"' | ||
type: number | ||
- description: My description | ||
name: item_id | ||
sql: '{CUBE}.item_id' | ||
title: Item ID | ||
type: number | ||
- name: order_status | ||
sql: '{CUBE}."STATUS"' | ||
type: string | ||
- name: is_cancelled | ||
sql: case {CUBE}."STATUS" when "CANCELLED" then true else false end | ||
title: Is Cancelled | ||
type: boolean | ||
- name: created_at | ||
sql: '{CUBE}."CREATED_AT"' | ||
type: time | ||
- name: completed_at | ||
sql: '{CUBE}."COMPLETED_AT"' | ||
type: time | ||
joins: [] | ||
measures: | ||
- name: count | ||
type: count | ||
- name: order_count_distinct | ||
sql: '{id}' | ||
type: count_distinct_approx | ||
name: orders | ||
sql_table: '{{_user_attributes[''ecom_database'']}}.{{_user_attributes[''ecom_schema'']}}."ORDERS"' |
39 changes: 39 additions & 0 deletions
39
lkml2cube/tests/samples/lkml/explores/orders_summary.model.lkml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
connection: "my_connection" | ||
|
||
include: "/views/*.view.lkml" # include all views in the views/ folder in this project | ||
# include: "/**/*.view.lkml" # include all views in this project | ||
# include: "/**/*.dashboard.lookml" # include a LookML dashboard called my_dashboard | ||
|
||
|
||
explore: orders { | ||
label: "Orders Summary" | ||
|
||
join: line_items { | ||
relationship: one_to_many | ||
sql_on: ${orders.id} = ${line_items.order_id} ;; | ||
type: left_outer | ||
} | ||
|
||
join: products { | ||
relationship: many_to_one | ||
sql_on: ${line_items.product_id} = ${products.id} ;; | ||
type: left_outer | ||
} | ||
|
||
} | ||
|
||
explore: line_items { | ||
label: "Line Items Summary" | ||
|
||
join: orders { | ||
relationship: many_to_one | ||
sql_on: ${line_items.order_id} = ${orders.id} ;; | ||
type: left_outer | ||
} | ||
|
||
join: products { | ||
relationship: many_to_one | ||
sql_on: ${line_items.product_id} = ${products.id} ;; | ||
type: left_outer | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# The name of this view in Looker is "Line Items" | ||
view: line_items { | ||
view_label: "Line Items" | ||
# The sql_table_name parameter indicates the underlying database table | ||
# to be used for all fields in this view. | ||
sql_table_name: {{_user_attributes['ecom_database']}}.{{_user_attributes['ecom_schema']}}."LINE_ITEMS" | ||
;; | ||
# In order to join this view in an Explore, | ||
# define primary_key: yes on a dimension that has no repeated values. | ||
|
||
dimension: id { | ||
primary_key: yes | ||
type: number | ||
sql: ${TABLE}."ID" ;; | ||
} | ||
|
||
# This table contains a foreign key to other tables. | ||
# Joins are defined in explores | ||
dimension: order_id { | ||
hidden: yes | ||
type: number | ||
sql: ${TABLE}."ORDER_ID" ;; | ||
} | ||
|
||
dimension: product_id { | ||
hidden: yes | ||
type: number | ||
sql: ${TABLE}."PRODUCT_ID" ;; | ||
} | ||
|
||
dimension: price { | ||
type: number | ||
sql: ${TABLE}."PRICE" ;; | ||
} | ||
|
||
dimension: quantity { | ||
label: "Quantity" | ||
type: number | ||
sql: ${TABLE}."QUANTITY" ;; | ||
} | ||
|
||
# You can reference other dimensions while defining a dimension. | ||
dimension: line_amount { | ||
type: number | ||
sql: ${quantity} * ${price};; | ||
} | ||
|
||
dimension: quantity_bins { | ||
type: tier | ||
style: integer | ||
bins: [0,10,50,100] | ||
sql: ${quantity} ;; | ||
} | ||
|
||
# A measure is a field that uses a SQL aggregate function. Here are defined sum and count | ||
# measures for this view, but you can also add measures of many different aggregates. | ||
|
||
measure: total_quantity { | ||
type: sum | ||
sql: ${quantity} ;; | ||
} | ||
|
||
measure: total_amount { | ||
type: sum | ||
sql: ${line_amount} ;; | ||
} | ||
|
||
measure: count { | ||
type: count | ||
} | ||
|
||
|
||
# Dates and timestamps can be represented in Looker using a dimension group of type: time. | ||
# Looker converts dates and timestamps to the specified timeframes within the dimension group. | ||
|
||
dimension_group: created_at { | ||
type: time | ||
timeframes: [ | ||
raw, | ||
time, | ||
date, | ||
week, | ||
month, | ||
quarter, | ||
year | ||
] | ||
sql: ${TABLE}."CREATED_AT" ;; | ||
} | ||
|
||
} |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.