Commit 9c47ff85 authored by Erik Alexandre Pucci's avatar Erik Alexandre Pucci

database: Replanning the database and its data marts 41

Signed-off-by: default avatarErik Alexandre Pucci <eap08@c3sl.ufpr.br>
parent a3880203
......@@ -71,6 +71,8 @@ comment on table fact_inventory is 'Fact table with the history of machines '
'connections with their inventory';
comment on table fact_alert is 'Fact table with the history of machines '
'modifications';
comment on column fact_alert.hd_alert is 'Alert representing changes in the '
' first HD';
comment on table fact_net_usage is 'Fact table with the history of network '
'usage per school and 5 minutes sample';
comment on table fact_net_usage_avail is 'Fact table of the list of schools '
......
......@@ -111,7 +111,8 @@ create table fact_alert (
old_inventory integer references fact_inventory not null,
inventory integer references fact_inventory not null,
memory_alert boolean default false not null,
hd_alert boolean default false not null
hd_alert boolean default false not null /* Alert representing changes
* in the first HD */
);
/* Fact table of the list of schools with network usage data collected (i.e. at
......
......@@ -106,19 +106,7 @@ begin
/* ---------------------------------------------------------------------- */
/* Create temporary tables to migrate data to the fact tables */
/*raise log 'Migrating "mectb05_disponibilidade_fact" data to '
'"fact_availability"...';
insert into fact_availability (load_date, contact_date, machine_id)
select distinct load_date_id, dat_data, dim_machine.id from
mectb05_disponibilidade_fact, mectb01_escola_dim, mectb03_data_dim,
mectb04_maquina_dim, dim_school, dim_machine where dis_dat_id =
dat_id and dis_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 diagnostics tmp = ROW_COUNT;
count := count + tmp;
raise log 'Done';*/
raise log 'Creating and populating temporary tables...';
/* Temporary table to get machines ids and machines contact dates */
create temporary table tmp_machine (
......@@ -131,8 +119,8 @@ begin
/* Temporary tables to get machines components ids */
create temporary table tmp_os (
component_id integer,
machine_id integer,
date_id integer
date_id integer,
old_id integer
);
create temporary table tmp_kernel (like tmp_os);
create temporary table tmp_processor (like tmp_os);
......@@ -140,8 +128,8 @@ begin
create temporary table tmp_hd (
component_id integer,
machine_id integer,
date_id integer,
old_id integer,
used integer
);
create temporary table tmp_hd2 (like tmp_hd);
......@@ -155,40 +143,39 @@ begin
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
dat_id and 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,
insert into tmp_os (component_id, date_id, old_id)
select distinct id, inv_dat_id, inv_maq_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,
insert into tmp_kernel (component_id, date_id, old_id)
select distinct id, inv_dat_id, inv_maq_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,
insert into tmp_processor (component_id, date_id, old_id)
select distinct id, inv_dat_id, inv_maq_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
cat_componente = 'MEM' and inv_cat_id = cat_id and cat_modelo is not
null;
insert into tmp_memory (component_id, date_id, old_id)
select distinct cat_modelo::integer, inv_dat_id, inv_maq_id from
mectb07_inventario_fact, mectb02_catalogo_dim where cat_componente =
'MEM' and inv_cat_id = cat_id and cat_modelo is not null;
/* Get first HD component id from each combination of data and machine */
insert into tmp_hd (component_id, machine_id, date_id, used)
select distinct on (inv_dat_id, inv_maq_id) id, inv_maq_id, inv_dat_id,
insert into tmp_hd (component_id, date_id, old_id, used)
select distinct on (inv_dat_id, inv_maq_id) id, inv_dat_id, inv_maq_id,
inv_disco_usado from mectb07_inventario_fact, mectb02_catalogo_dim,
dim_component where cat_componente = 'HD' and inv_cat_id = cat_id
and trim(both from cat_modelo) = description and trim(both from
......@@ -197,8 +184,8 @@ begin
/* Get last HD component id from each combination of data and machine and
* keep only the difference from the tmp_hd table, to avoid treating the
* only HD of many machines as a second one */
insert into tmp_hd2 (component_id, machine_id, date_id, used)
(select distinct on (inv_dat_id, inv_maq_id) id, inv_maq_id, inv_dat_id,
insert into tmp_hd2 (component_id, date_id, old_id, used)
(select distinct on (inv_dat_id, inv_maq_id) id, inv_dat_id, inv_maq_id,
inv_disco_usado from mectb07_inventario_fact, mectb02_catalogo_dim,
dim_component where cat_componente = 'HD' and inv_cat_id = cat_id
and trim(both from cat_modelo) = description and trim(both from
......@@ -206,13 +193,14 @@ begin
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)
insert into tmp_extra_hds (component_id, date_id, old_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;
raise log 'Done';
/* ---------------------------------------------------------------------- */
/* Finally, migrate data to fact_inventory */
......@@ -220,27 +208,44 @@ begin
'"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, t.machine_id, o.component_id,
extra_hds, hash)
select load_date_id, contact_date, 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
h.used, i.component_id, i.used, e.component_id,
md5(o.component_id::text || k.component_id::text ||
p.component_id::text || m.component_id::text || h.component_id::text
|| h.used::text || i.component_id::text || i.used::text ||
e.component_id::text)
from tmp_machine t join tmp_os o using (date_id, old_id)
join tmp_kernel k using (date_id, old_id)
join tmp_processor p using (date_id, old_id)
join tmp_memory m using (date_id, old_id)
join tmp_hd h using (date_id, old_id)
left join tmp_hd i using (date_id, old_id)
left join tmp_extra_hds e using (date_id, old_id);
get diagnostics tmp = ROW_COUNT;
count := count + tmp;
raise log 'Done';
raise log 'Migrating "mectb07_inventario_fact" data to "fact_alert"...';
/*raise log 'Inserting contact data from "mectb05_disponibilidade_fact" '
'data to "fact_inventory"...';
insert into fact_inventory (load_date, contact_date, machine_id)
select distinct load_date_id, dat_data, dim_machine.id from
mectb05_disponibilidade_fact, mectb01_escola_dim, mectb03_data_dim,
mectb04_maquina_dim, dim_school, dim_machine where dis_dat_id =
dat_id and dis_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 diagnostics tmp = ROW_COUNT;
count := count + tmp;
raise log 'Done';*/
select distinct on (machine_id, hash) contact_date, machine_id, hash from
fact_inventory order by contact_date, machine_id
raise log 'Inserting alert data from "fact_inventory" to "fact_alert"...';
insert into fact_alert (load_date, old_inventory, inventory, memory_alert,
hd_alert)
--select from ;
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