diff --git a/categories.view.lkml b/categories.view.lkml new file mode 100644 index 0000000..2bdf295 --- /dev/null +++ b/categories.view.lkml @@ -0,0 +1,29 @@ +view: categories { + sql_table_name: Northwind2.Categories ;; + + dimension: category_id { + primary_key: yes + type: number + sql: ${TABLE}.CategoryID ;; + } + + dimension: category_name { + type: string + sql: ${TABLE}.CategoryName ;; + } + + dimension: description { + type: string + sql: ${TABLE}.Description ;; + } + + dimension: picture { + type: string + sql: ${TABLE}.Picture ;; + } + + measure: count { + type: count + drill_fields: [category_id, category_name] + } +} diff --git a/customer_customer_demo.view.lkml b/customer_customer_demo.view.lkml new file mode 100644 index 0000000..b0355c0 --- /dev/null +++ b/customer_customer_demo.view.lkml @@ -0,0 +1,19 @@ +view: customer_customer_demo { + sql_table_name: Northwind2.CustomerCustomerDemo ;; + + dimension: customer_id { + type: string + # hidden: yes + sql: ${TABLE}.CustomerID ;; + } + + dimension: customer_type_id { + type: string + sql: ${TABLE}.CustomerTypeID ;; + } + + measure: count { + type: count + drill_fields: [customers.contact_name, customers.company_name, customers.customer_id] + } +} diff --git a/customer_demographics.view.lkml b/customer_demographics.view.lkml new file mode 100644 index 0000000..4a7ec42 --- /dev/null +++ b/customer_demographics.view.lkml @@ -0,0 +1,18 @@ +view: customer_demographics { + sql_table_name: Northwind2.CustomerDemographics ;; + + dimension: customer_desc { + type: string + sql: ${TABLE}.CustomerDesc ;; + } + + dimension: customer_type_id { + type: string + sql: ${TABLE}.CustomerTypeID ;; + } + + measure: count { + type: count + drill_fields: [] + } +} diff --git a/customers.view.lkml b/customers.view.lkml new file mode 100644 index 0000000..007315e --- /dev/null +++ b/customers.view.lkml @@ -0,0 +1,65 @@ +view: customers { + sql_table_name: Northwind2.Customers ;; + + dimension: customer_id { + primary_key: yes + type: string + sql: ${TABLE}.CustomerID ;; + } + + dimension: address { + type: string + sql: ${TABLE}.Address ;; + } + + dimension: city { + type: string + sql: ${TABLE}.City ;; + } + + dimension: company_name { + type: string + sql: ${TABLE}.CompanyName ;; + } + + dimension: contact_name { + type: string + sql: ${TABLE}.ContactName ;; + } + + dimension: contact_title { + type: string + sql: ${TABLE}.ContactTitle ;; + } + + dimension: country { + type: string + map_layer_name: countries + sql: ${TABLE}.Country ;; + } + + dimension: fax { + type: string + sql: ${TABLE}.Fax ;; + } + + dimension: phone { + type: string + sql: ${TABLE}.Phone ;; + } + + dimension: postal_code { + type: string + sql: ${TABLE}.PostalCode ;; + } + + dimension: region { + type: string + sql: ${TABLE}.Region ;; + } + + measure: count { + type: count + drill_fields: [customer_id, contact_name, company_name, customer_customer_demo.count, orders.count] + } +} diff --git a/employee_territories.view.lkml b/employee_territories.view.lkml new file mode 100644 index 0000000..48b5a76 --- /dev/null +++ b/employee_territories.view.lkml @@ -0,0 +1,19 @@ +view: employee_territories { + sql_table_name: Northwind2.EmployeeTerritories ;; + + dimension: employee_id { + type: number + # hidden: yes + sql: ${TABLE}.EmployeeID ;; + } + + dimension: territory_id { + type: string + sql: ${TABLE}.TerritoryID ;; + } + + measure: count { + type: count + drill_fields: [employees.first_name, employees.last_name, employees.employee_id] + } +} diff --git a/employees.view.lkml b/employees.view.lkml new file mode 100644 index 0000000..15eb73a --- /dev/null +++ b/employees.view.lkml @@ -0,0 +1,121 @@ +view: employees { + sql_table_name: Northwind2.Employees ;; + + dimension: employee_id { + primary_key: yes + type: number + sql: ${TABLE}.EmployeeID ;; + } + + dimension: address { + type: string + sql: ${TABLE}.Address ;; + } + + dimension_group: birth { + type: time + timeframes: [ + raw, + time, + date, + week, + month, + quarter, + year + ] + sql: ${TABLE}.BirthDate ;; + } + + dimension: city { + type: string + sql: ${TABLE}.City ;; + } + + dimension: country { + type: string + map_layer_name: countries + sql: ${TABLE}.Country ;; + } + + dimension: extension { + type: string + sql: ${TABLE}.Extension ;; + } + + dimension: first_name { + type: string + sql: ${TABLE}.FirstName ;; + } + + dimension_group: hire { + type: time + timeframes: [ + raw, + time, + date, + week, + month, + quarter, + year + ] + sql: ${TABLE}.HireDate ;; + } + + dimension: home_phone { + type: string + sql: ${TABLE}.HomePhone ;; + } + + dimension: last_name { + type: string + sql: ${TABLE}.LastName ;; + } + + dimension: notes { + type: string + sql: ${TABLE}.Notes ;; + } + + dimension: photo { + type: string + sql: ${TABLE}.Photo ;; + } + + dimension: photo_path { + type: string + sql: ${TABLE}.PhotoPath ;; + } + + dimension: postal_code { + type: string + sql: ${TABLE}.PostalCode ;; + } + + dimension: region { + type: string + sql: ${TABLE}.Region ;; + } + + dimension: reports_to { + type: number + sql: ${TABLE}.ReportsTo ;; + } + + dimension: title { + type: string + sql: ${TABLE}.Title ;; + } + + dimension: title_of_courtesy { + type: string + sql: ${TABLE}.TitleOfCourtesy ;; + } + dimension: Employees_name { + type: string + sql: CONCAT(${first_name}, ' ', ${last_name}) ;; + } + measure: count { + type: count + drill_fields: [employee_id, first_name, last_name, employee_territories.count, orders.count] + } +} diff --git a/gintare.model.lkml b/gintare.model.lkml new file mode 100644 index 0000000..ca8cbed --- /dev/null +++ b/gintare.model.lkml @@ -0,0 +1,117 @@ +connection: "northwind_2" + +# include all the views +include: "*.view" + +# include all the dashboards +include: "*.dashboard" + +datagroup: northwind_challenge_default_datagroup { + # sql_trigger: SELECT MAX(id) FROM etl_log;; + max_cache_age: "1 hour" +} + +persist_with: northwind_challenge_default_datagroup + +explore: categories {} + +explore: customer_customer_demo { + join: customers { + type: left_outer + sql_on: ${customer_customer_demo.customer_id} = ${customers.customer_id} ;; + relationship: many_to_one + } +} + +explore: customer_demographics {} + +explore: customers { + join: orders { + type: left_outer + sql_on: ${customers.customer_id} = ${orders.customer_id} ;; + relationship: one_to_many + } +} + +explore: employee_territories { + join: employees { + type: left_outer + sql_on: ${employee_territories.employee_id} = ${employees.employee_id} ;; + relationship: many_to_one + } +} + +explore: employees {} + +explore: order_details { + join: orders { + type: left_outer + sql_on: ${order_details.order_id} = ${orders.order_id} ;; + relationship: many_to_one + } + + join: products { + type: left_outer + sql_on: ${order_details.product_id} = ${products.product_id} ;; + relationship: many_to_one + } +} + +explore: orders { + join: employees { + type: left_outer + sql_on: ${orders.employee_id} = ${employees.employee_id} ;; + relationship: many_to_one + } + + join: customers { + type: left_outer + sql_on: ${orders.customer_id} = ${customers.customer_id} ;; + relationship: many_to_one + } + join: order_details { + type: left_outer + sql_on: ${orders.order_id}=${order_details.order_id} ;; + relationship: one_to_many +} +} + +explore: products { + join: suppliers { + type: left_outer + sql_on: ${products.supplier_id} = ${suppliers.supplier_id} ;; + relationship: many_to_one + } + join: order_details { + type: left_outer + sql_on: ${products.product_id}=${order_details.product_id} ;; + relationship: one_to_many + } + join: categories { + type: left_outer + sql_on: ${products.category_id}=${categories.category_id} ;; + relationship: many_to_one + } +} + +explore: region {} + +explore: shippers { + join: orders { + type: left_outer + sql_on: ${shippers.shipper_id}=${orders.ship_via} ;; + relationship: one_to_many + } +} + +explore: suppliers {} + +explore: territories { + join: region { + type: left_outer + sql_on: ${territories.region_id} = ${region.region_id} ;; + relationship: many_to_one + } +} + +explore: usstates {} diff --git a/order_details.view.lkml b/order_details.view.lkml new file mode 100644 index 0000000..77182a9 --- /dev/null +++ b/order_details.view.lkml @@ -0,0 +1,59 @@ +view: order_details { + sql_table_name: Northwind2.Order_Details ;; + + dimension: discount { + type: number + sql: ${TABLE}.Discount ;; + } + + dimension: order_id { + type: number + # hidden: yes + sql: ${TABLE}.OrderID ;; + } + + dimension: product_id { + type: number + # hidden: yes + sql: ${TABLE}.ProductID ;; + } + + dimension: quantity { + type: number + sql: ${TABLE}.Quantity ;; + } + + dimension: unit_price { + type: number + sql: ${TABLE}.UnitPrice ;; + } + dimension_group: order_date { + type: time + timeframes: [ + raw, + time, + date, + week, + month, + quarter, + year + ] + sql: ( + SELECT OrderDate + FROM Orders + WHERE Orders.OrderID = ${TABLE}.OrderID + ) ;; + datatype:date # defaults to datetime + convert_tz: no +} + + measure: count { + type: count + drill_fields: [product_id,order_id,unit_price,quantity,discount] + } + measure: total_quantity { + type: sum + sql: ${quantity}*${unit_price} ;; + } + } + diff --git a/orders.view.lkml b/orders.view.lkml new file mode 100644 index 0000000..29e3eb2 --- /dev/null +++ b/orders.view.lkml @@ -0,0 +1,123 @@ +view: orders { + sql_table_name: Northwind2.Orders ;; + + dimension: order_id { + primary_key: yes + type: number + sql: ${TABLE}.OrderID ;; + } + + dimension: customer_id { + type: string + # hidden: yes + sql: ${TABLE}.CustomerID ;; + } + + dimension: employee_id { + type: number + # hidden: yes + sql: ${TABLE}.EmployeeID ;; + } + + dimension: freight { + type: number + sql: ${TABLE}.Freight ;; + } + + dimension_group: order { + type: time + timeframes: [ + raw, + time, + date, + week, + month, + quarter, + year + ] + sql: ${TABLE}.OrderDate ;; + } + + dimension_group: required { + type: time + timeframes: [ + raw, + time, + date, + week, + month, + quarter, + year + ] + sql: ${TABLE}.RequiredDate ;; + } + + dimension: ship_address { + type: string + sql: ${TABLE}.ShipAddress ;; + } + + dimension: ship_city { + type: string + sql: ${TABLE}.ShipCity ;; + } + + dimension: ship_country { + type: string + sql: ${TABLE}.ShipCountry ;; + } + + dimension: ship_name { + type: string + sql: ${TABLE}.ShipName ;; + } + + dimension: ship_postal_code { + type: string + sql: ${TABLE}.ShipPostalCode ;; + } + + dimension: ship_region { + type: string + sql: ${TABLE}.ShipRegion ;; + } + + dimension: ship_via { + type: number + sql: ${TABLE}.ShipVia ;; + } + + dimension_group: shipped { + type: time + timeframes: [ + raw, + time, + date, + week, + month, + quarter, + year + ] + sql: ${TABLE}.ShippedDate ;; + } + + measure: count { + type: count + drill_fields: [detail*] + } + + # ----- Sets of fields for drilling ------ + set: detail { + fields: [ + order_id, + ship_name, + employees.first_name, + employees.last_name, + employees.employee_id, + customers.contact_name, + customers.company_name, + customers.customer_id, + order_details.count + ] + } +} diff --git a/products.view.lkml b/products.view.lkml new file mode 100644 index 0000000..23d6367 --- /dev/null +++ b/products.view.lkml @@ -0,0 +1,88 @@ +view: products { + sql_table_name: Northwind2.Products ;; + + dimension: product_id { + primary_key: yes + type: number + sql: ${TABLE}.ProductID ;; + } + + dimension: category_id { + type: number + sql: ${TABLE}.CategoryID ;; + } + + dimension: discontinued { + type: yesno + sql: ${TABLE}.Discontinued ;; + } + + dimension: product_name { + type: string + sql: ${TABLE}.ProductName ;; + } + + dimension: quantity_per_unit { + type: string + sql: ${TABLE}.QuantityPerUnit ;; + } + + dimension: reorder_level { + type: number + sql: ${TABLE}.ReorderLevel ;; + } + + dimension: supplier_id { + type: number + # hidden: yes + sql: ${TABLE}.SupplierID ;; + } + + dimension: unit_price { + type: number + sql: ${TABLE}.UnitPrice ;; + } + + dimension: units_in_stock { + type: number + sql: ${TABLE}.UnitsInStock ;; + } + + dimension: units_on_order { + type: number + sql: ${TABLE}.UnitsOnOrder ;; + } + + measure: count { + type: count + drill_fields: [detail*] + } + measure: sum_of_stock { + type: sum + sql: ${units_in_stock} ;; + } + measure: sum_of_units_on_order { + type: sum + sql: ${units_on_order} ;; + } + measure: total { + type: sum + sql: ${units_in_stock}*${unit_price} ;; + value_format_name: usd + } +measure: distinct_unit_stock_value { + type: sum_distinct + sql: ${units_in_stock} ;; +} + # ----- Sets of fields for drilling ------ + set: detail { + fields: [ + product_id, + product_name, + suppliers.contact_name, + suppliers.company_name, + suppliers.supplier_id, + order_details.count + ] + } +} diff --git a/region.view.lkml b/region.view.lkml new file mode 100644 index 0000000..0e195e3 --- /dev/null +++ b/region.view.lkml @@ -0,0 +1,19 @@ +view: region { + sql_table_name: Northwind2.Region ;; + + dimension: region_id { + primary_key: yes + type: number + sql: ${TABLE}.RegionID ;; + } + + dimension: region_description { + type: string + sql: ${TABLE}.RegionDescription ;; + } + + measure: count { + type: count + drill_fields: [region_id, territories.count] + } +} diff --git a/shippers.view.lkml b/shippers.view.lkml new file mode 100644 index 0000000..e01f456 --- /dev/null +++ b/shippers.view.lkml @@ -0,0 +1,24 @@ +view: shippers { + sql_table_name: Northwind2.Shippers ;; + + dimension: shipper_id { + primary_key: yes + type: number + sql: ${TABLE}.ShipperID ;; + } + + dimension: company_name { + type: string + sql: ${TABLE}.CompanyName ;; + } + + dimension: phone { + type: string + sql: ${TABLE}.Phone ;; + } + + measure: count { + type: count + drill_fields: [shipper_id, company_name] + } +} diff --git a/sql_runner_query.view.lkml b/sql_runner_query.view.lkml new file mode 100644 index 0000000..3b89e78 --- /dev/null +++ b/sql_runner_query.view.lkml @@ -0,0 +1,36 @@ +view: sql_runner_query { + derived_table: { + sql: SELECT + suppliers.CompanyName AS `suppliers.company_name`, + SUM(order_details.UnitPrice*order_details.Quantity) AS total + FROM Northwind2.Products AS products + LEFT JOIN Northwind2.Suppliers AS suppliers ON products.SupplierID = suppliers.SupplierID + LEFT JOIN Northwind2.Order_Details AS order_details ON products.ProductID=order_details.ProductID + + WHERE + ((suppliers.CompanyName IS NOT NULL)) + GROUP BY 1,order_details.UnitPrice*order_details.Quantity + ORDER BY suppliers.CompanyName DESC + LIMIT 500 + ;; + } + + measure: count { + type: count + drill_fields: [detail*] + } + + dimension: suppliers_company_name { + type: string + sql: ${TABLE}.`suppliers.company_name` ;; + } + + dimension: total { + type: number + sql: ${TABLE}.total ;; + } + + set: detail { + fields: [suppliers_company_name, total] + } +} diff --git a/suppliers.view.lkml b/suppliers.view.lkml new file mode 100644 index 0000000..d2c61a4 --- /dev/null +++ b/suppliers.view.lkml @@ -0,0 +1,73 @@ +view: suppliers { + sql_table_name: Northwind2.Suppliers ;; + + dimension: supplier_id { + primary_key: yes + type: number + sql: ${TABLE}.SupplierID ;; + } + + dimension: address { + type: string + sql: ${TABLE}.Address ;; + } + + dimension: city { + type: string + sql: ${TABLE}.City ;; + } + + dimension: company_name { + type: string + sql: ${TABLE}.CompanyName ;; + } + + dimension: contact_name { + type: string + sql: ${TABLE}.ContactName ;; + } + + dimension: contact_title { + type: string + sql: ${TABLE}.ContactTitle ;; + } + + dimension: country { + type: string + map_layer_name: countries + sql: ${TABLE}.Country ;; + } + + dimension: fax { + type: string + sql: ${TABLE}.Fax ;; + } + + dimension: home_page { + type: string + sql: ${TABLE}.HomePage ;; + } + + dimension: phone { + type: string + sql: ${TABLE}.Phone ;; + } + + dimension: postal_code { + type: string + sql: ${TABLE}.PostalCode ;; + } + + dimension: region { + type: string + sql: ${TABLE}.Region ;; + } +measure: count_distinct_supplier{ + type: count_distinct + sql: ${supplier_id} ;; +} + measure: count { + type: count + drill_fields: [supplier_id, contact_name, company_name, products.count] + } +} diff --git a/territories.view.lkml b/territories.view.lkml new file mode 100644 index 0000000..97a8cea --- /dev/null +++ b/territories.view.lkml @@ -0,0 +1,25 @@ +view: territories { + sql_table_name: Northwind2.Territories ;; + + dimension: territory_id { + primary_key: yes + type: string + sql: ${TABLE}.TerritoryID ;; + } + + dimension: region_id { + type: number + # hidden: yes + sql: ${TABLE}.RegionID ;; + } + + dimension: territory_description { + type: string + sql: ${TABLE}.TerritoryDescription ;; + } + + measure: count { + type: count + drill_fields: [territory_id, region.region_id] + } +} diff --git a/usstates.view.lkml b/usstates.view.lkml new file mode 100644 index 0000000..e842661 --- /dev/null +++ b/usstates.view.lkml @@ -0,0 +1,28 @@ +view: usstates { + sql_table_name: Northwind2.USStates ;; + + dimension: state_abbr { + type: string + sql: ${TABLE}.StateAbbr ;; + } + + dimension: state_id { + type: number + sql: ${TABLE}.StateID ;; + } + + dimension: state_name { + type: string + sql: ${TABLE}.StateName ;; + } + + dimension: state_region { + type: string + sql: ${TABLE}.StateRegion ;; + } + + measure: count { + type: count + drill_fields: [state_name] + } +}