You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Data warehouses offer the overarching and unique benefit of allowing organizations to analyze large amounts of variant data and extract significant value from it, as well as to keep a historical record.
Support for SQL, machine learning, graph, and spatial processing
Data import with using files init.sql and trans.sql
Task 1: OLTP (Online Transational Processing)
(1) Restore sql files (init.sql and trans.sql) into your database, using a separate schema is strongly recommended to avoid name clash with existing tables.
CREATESCHEMArestored_schema;
-- Loading the backup files
\i /path/to/init.sql
\i /path/to/trans.sql
**Task 2: OLAP (Online Analytical Processing) **
(2)** Design an OLAP star model based on the given OLTP system. Create at least 3 dimensions.
(3) Implement OLAP as a relational database in a new schema, e.g. olap; when working with schemas, remember about setting the search_path variable, e.g.:
CREATESCHEMAolap;
SET search_path TO olap, public;
-- Customer dimension tableCREATETABLEolap.customer (
customer_id varchar(10) NOT NULL,
customer_password varchar(10) NOT NULL,
customer_name varchar(40) NOT NULL,
customer_city varchar(40) NOT NULL,
customer_zip char(6) NOT NULL,
customer_address varchar(40) NOT NULL,
customer_email varchar(40),
customer_phone varchar(16) NOT NULL,
customer_fax varchar(16),
customer_nip char(13),
customer_regon char(9)
);
-- Product dimension tableCREATETABLEolap.product (
product_id INTPRIMARY KEY,
product_name VARCHAR (100),
product_description VARCHAR (100),
product_price NUMERIC (7,2),
product_available INT
);
-- Addressee dimension tableCREATETABLEolap.addressee (
addressee_id integerNOT NULL,
addressee_name varchar(40) NOT NULL,
addressee_city varchar(40) NOT NULL,
addressee_zip char(6) NOT NULL,
addressee_address varchar(60) NOT NULL
);
-- Orders fact tableCREATETABLEolap.orders (
idorder integerNOT NULL,
idcustomer varchar(10) NOT NULL,
idaddressee integerNOT NULL,
idproduct char(5) NOT NULL,
order_date dateNOT NULL,
price numeric(7,2),
paid boolean,
comments varchar(200)
);
(4) Implement ETL with SQL loading your OLAP model with data from the OLTP tables. Use INSERT INTO ... SELECT.
(5) Write an SQL query on the OLAP model which provides aggregated values for each month for a selected year. Pick the value depending on what your fact table looks like.
SELECT
EXTRACT(MONTH FROMo.order_date) AS month,
c.customer_name, --customer dimension p.product_name, -- product dimensiona.addressee_city, --addressee dimensionSUM(o.quantity) AS total_quantity,
SUM(o.total_price) AS total_price
FROMolap.orders o
JOINolap.customer c ONo.customer_id=c.customer_idJOINolap.product p ONo.product_id=p.product_idJOINolap.address a ONo.address_id=a.address_idWHERE
EXTRACT(YEAR FROMo.order_date) =2023-- replace GROUP BY
month,
c.customer_name,
p.product_name,
a.addressee_cityORDER BY
month;