Commit a3880203 authored by Erik Alexandre Pucci's avatar Erik Alexandre Pucci

database: Replanning the database and its data marts 40

Signed-off-by: default avatarErik Alexandre Pucci <eap08@c3sl.ufpr.br>
parent 7923818c
......@@ -105,7 +105,7 @@ begin
raise log 'Done';
/* ---------------------------------------------------------------------- */
/* Migrate fact tables */
/* Create temporary tables to migrate data to the fact tables */
/*raise log 'Migrating "mectb05_disponibilidade_fact" data to '
'"fact_availability"...';
......@@ -124,6 +124,7 @@ begin
create temporary table tmp_machine (
contact_date date,
machine_id integer,
date_id integer,
old_id integer
);
......@@ -146,32 +147,39 @@ begin
create temporary table tmp_hd2 (like tmp_hd);
create temporary table tmp_extra_hds (like tmp_os);
/* ---------------------------------------------------------------------- */
/* Insert data into temporary tables */
insert into tmp_machine (contact_date, machine_id, old_id)
select distinct dat_data, dim_machine.id, inv_maq_id from
/* Get contact dates and new machine ids */
insert into tmp_machine (contact_date, machine_id, date_id, old_id)
select distinct dat_data, dim_machine.id, dat_id, inv_maq_id from
mectb07_inventario_fact, mectb01_escola_dim, mectb03_data_dim,
mectb04_maquina_dim, dim_school, dim_machine where inv_dat_id =
dat_id, inv_maq_id = maq_id and maq_esc_id = esc_id and
maq_mac::macaddr = machine and esc_inep = inep and school_id =
dim_school.id;
/* Get new OS ids from each combination of data and machine */
insert into tmp_os (component_id, machine_id, date_id)
select distinct id, inv_maq_id, inv_dat_id from mectb07_inventario_fact,
mectb02_catalogo_dim, dim_component where cat_componente = 'SO' and
inv_cat_id = cat_id and trim(both from cat_descricao) = detail;
/* Get new kernel ids from each combination of data and machine */
insert into tmp_kernel (component_id, machine_id, date_id)
select distinct id, inv_maq_id, inv_dat_id from mectb07_inventario_fact,
mectb02_catalogo_dim, dim_component where cat_componente = 'KERNEL'
and inv_cat_id = cat_id and trim(both from cat_modelo) =
description;
/* Get new processor ids from each combination of data and machine */
insert into tmp_processor (component_id, machine_id, date_id)
select distinct id, inv_maq_id, inv_dat_id from mectb07_inventario_fact,
mectb02_catalogo_dim, dim_component where cat_componente = 'PROC'
and inv_cat_id = cat_id and trim(both from cat_modelo) =
description;
/* Get memory sizes from each combination of data and machine */
insert into tmp_memory (component_id, machine_id, date_id)
select distinct cat_modelo::integer, inv_maq_id, inv_dat_id from
mectb07_inventario_fact, mectb02_catalogo_dim, dim_component where
......@@ -197,19 +205,34 @@ begin
cat_descricao) = detail order by inv_dat_id, inv_maq_id, id desc)
except (select * from tmp_hd);
/* Get quantity of extra HDs for each combination of data and machine */
insert into tmp_extra_hds (component_id, machine_id, date_id)
select count(*), inv_dat_id, inv_maq_id from (select
distinct inv_dat_id, inv_maq_id, cat_modelo, cat_descricao from
mectb07_inventario_fact, mectb02_catalogo_dim where inv_cat_id =
cat_id and cat_componente = 'HD' order by inv_dat_id, inv_maq_id) s
group by inv_dat_id, inv_maq_id having count(*) > 2;
/* ---------------------------------------------------------------------- */
/* Finally, migrate data to fact_inventory */
raise log 'Migrating "mectb07_inventario_fact" data to '
'"fact_inventory"...';
insert into fact_inventory (load_date, contact_date, machine_id, os_id,
kernel_id, processor_id, memory, hd_id, hd_used, hd2_id, hd2_used,
extra_hds)
select load_date_id, contact_date, tmp_machine.machine.id,
tmp_os.component_id, tmp_kernel.component_id,
tmp_processor.component_id, tmp_memory.component_id,
tmp_hd.component_id, tmp_hd.used, tmp_hd2.component_id,
tmp_hd2.used,
select load_date_id, contact_date, t.machine_id, o.component_id,
k.component_id, p.component_id, m.component_id, h.component_id,
h.used, i.component_id, i.used, e.component_id from tmp_machine t,
tmp_os o, tmp_kernel k, tmp_processor p, tmp_memory m, tmp_hd h,
tmp_hd i, tmp_extra_hds e where t.old_id = o.machine_id and
t.contact_date = o.contact_date and t.old_id = k.machine_id and
t.contact_date = k.contact_date and t.old_id = p.machine_id and
t.contact_date = p.contact_date and t.old_id = m.machine_id and
t.contact_date = m.contact_date and t.old_id = h.machine_id and
t.contact_date = h.contact_date and t.old_id = i.machine_id and
t.contact_date = i.contact_date and t.old_id = e.machine_id and
t.contact_date = e.contact_date
get diagnostics tmp = ROW_COUNT;
count := count + tmp;
raise log 'Done';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment