Commit 09183b32 authored by Erik Alexandre Pucci's avatar Erik Alexandre Pucci

database: Replanning the database and its data marts 46

Signed-off-by: default avatarErik Alexandre Pucci <eap08@c3sl.ufpr.br>
parent 79295cbe
......@@ -81,7 +81,7 @@ create table fact_inventory (
os_id integer references dim_component not null,
kernel_id integer references dim_component not null,
processor_id integer references dim_component not null,
memory integer not null,
memory_size integer not null,
hd_id integer references dim_component not null,
hd_used integer not null,
hd2_id integer references dim_component,
......
......@@ -113,7 +113,7 @@ begin
/* Create temporary tables to migrate data to the fact tables */
raise log 'Creating and populating temporary tables...';
/* Temporary table to get machines ids and machines contact dates */
/* Temporary table to get machine ids and machine contact dates */
create temporary table tmp_machine (
contact_date date,
machine_id integer,
......@@ -121,7 +121,7 @@ begin
old_id integer
);
/* Temporary tables to get machines components ids */
/* Temporary tables to get machine components ids */
create temporary table tmp_os (
component_id integer,
date_id integer,
......@@ -260,8 +260,8 @@ begin
raise log 'Inserting contact data from "mectb05_disponibilidade_fact" '
'data to "fact_inventory", using "no data" flag for the components...';
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, hash)
kernel_id, processor_id, memory_size, hd_id, hd_used, hd2_id,
hd2_used, extra_hds, hash)
select load_date, *, no_data_os, no_data_kernel, no_data_processor, 0,
no_data_hd, 0, null, null, 0, no_data_hash from (select dat_data,
dim_machine.id from mectb05_disponibilidade_fact,
......@@ -274,34 +274,22 @@ begin
count := count + tmp;
raise log 'Done';*/
/* Create temporary table to hold the machines modifications in different
* lines */
with tmp_alert as (
select id, contact_date, machine_id, hash, row_number() over (partition
by machine_id order by contact_date) as row_n from (select distinct
on (i.machine_id, hash) id, contact_date, i.machine_id, hash from
fact_inventory i, (select machine_id from (select distinct
machine_id, hash from fact_inventory) s group by machine_id having
count(*) > 1) t where i.machine_id = t.machine_id) u
),
new_inventory as (
select id, row_n - 1 as row_n from tmp_alert where row_n > 1
),
old_inventory as (
select id, row_n from tmp_alert
) select o.id, n.id from old_inventory o, new_inventory n where o.row_n =
n.row_n;
-- ) select distinct on (contact_date, machine_id) id, contact_date,
-- machine_id, hash from tmp_alert order by contact_date, machine_id, hash
/* Insert machines changes data into fact_alert */
/* Insert machine modifications data into fact_alert */
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 load_date, first_value(id) over (partition by contact_date order
by contact_date), id, ..., ...
from
with tmp_alert as (
select *, row_number() over (partition by machine_id order by
contact_date) as row_n from (select distinct on (i.machine_id, hash)
i.id, contact_date, i.machine_id, hash, memory_size, detail::integer
as "hd_size" from fact_inventory i, dim_component c, (select
machine_id from (select distinct machine_id, hash from
fact_inventory) s group by machine_id having count(*) > 1) t where
i.machine_id = t.machine_id and i.hd_id = c.id) u
) select load_date_id, o.id, n.id, case when n.memory_size <
o.memory_size * 0.9 then true else false end, case when n.hd_size <
o.hd_size * 0.9 then true else false end from tmp_alert o, tmp_alert
n where o.machine_id = n.machine_id and o.row_n = n.row_n - 1;
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