-- STAGE TABLE
CREATE TABLE stage_tbl
(ID INTEGER,
change_id INTEGER,
update_time TIMESTAMP(6),
columnname VARCHAR(30),
change_log_from VARCHAR(10),
change_log_to VARCHAR(10)
) PRIMARY INDEX (ID);
INSERT INTO stage_tbl VALUES (1234,5678,'2013-07-01 07:00.00.000000','change_col_1','','erf');
INSERT INTO stage_tbl VALUES (1234,5678,'2013-08-01 08:00.00.000000','change_col_2','lks','txh');
INSERT INTO stage_tbl VALUES (1234,5678,'2013-08-01 09:00.00.000000','change_col_1','erf','fdr');
INSERT INTO stage_tbl VALUES (1234,5678,'2013-08-01 09:00.00.000000','change_col_2','txh','rep');
INSERT INTO stage_tbl VALUES (1234,5678,'2013-08-01 09:00.00.000000','change_col_3','','fdy');
INSERT INTO stage_tbl VALUES (1234,5678,'2013-08-01 09:00.00.000000','change_col_4','rfd','uif');
INSERT INTO stage_tbl VALUES (1234,5678,'2013-08-01 09:00.00.000000','change_col_5','lop','jhr');
INSERT INTO stage_tbl VALUES (1234,5678,'2013-08-01 11:00.00.000000','change_col_5','jhr','puh');
INSERT INTO stage_tbl VALUES (1234,78965,'2013-07-01 07:00.00.000000','change_col_1','rdt','ted');
INSERT INTO stage_tbl VALUES (1234,78965,'2013-08-01 08:00.00.000000','change_col_2','wfs','trh');
INSERT INTO stage_tbl VALUES (1234,78965,'2013-08-01 09:00.00.000000','change_col_3','','');
INSERT INTO stage_tbl VALUES (1234,23654,'2013-08-01 08:00.00.000000','change_col_4','gfd','');
INSERT INTO stage_tbl VALUES (1234,32111,'2013-08-01 09:00.00.000000','change_col_5','red','');
-- WRITE A QUERY ON STAGE TABLE SO THAT WE GET THE RESULTS AS IN expected_res below:
CREATE TABLE expected_res
(ID INTEGER,
change_id INTEGER,
update_time TIMESTAMP(6),
change_col_1 VARCHAR(10),
change_col_2 VARCHAR(10),
change_col_3 VARCHAR(10),
change_col_4 VARCHAR(10),
change_col_5 VARCHAR(10)
) PRIMARY INDEX (ID);
INSERT INTO expected_res VALUES (1234,5678,'2013-07-01 07:00.00.000000','erf','lks',NULL,'rfd','lop');
INSERT INTO expected_res VALUES (1234,5678,'2013-08-01 08:00.00.000000','erf','txh',NULL,'rfd','lop');
INSERT INTO expected_res VALUES (1234,5678,'2013-08-01 09:00.00.000000','fdr','rep','fdy','uif','jhr');
INSERT INTO expected_res VALUES (1234,5678,'2013-08-01 11:00.00.000000','fdr','rep','fdy','uif','puh');
INSERT INTO expected_res VALUES (1234,78965,'2013-07-01 07:00.00.000000','ted','wfs',NULL,NULL,NULL);
INSERT INTO expected_res VALUES (1234,78965,'2013-08-01 08:00.00.000000','ted','trh',NULL,NULL,NULL);
INSERT INTO expected_res VALUES (1234,78965,'2013-08-01 09:00.00.000000','ted','trh',NULL,NULL,NULL);
INSERT INTO expected_res VALUES (1234,23654,'2013-08-01 08:00.00.000000',NULL,NULL,NULL,'gfd',NULL);
INSERT INTO expected_res VALUES (1234,32111,'2013-08-01 09:00.00.000000',NULL,NULL,NULL,NULL,'red');
LOGIC:
- The row in the target table should be at ID/Change_Id/update_time level
- If the value for a particluar column doesnt come in the following delta then we should take the previous value for e.g. 1234 5678 2013-07-01 07:00.00.000000
we got the value for change_column_1 as erf
but in the next days run i.e. 2013-08-01 08:00.00.000000 there was no value for change_column_1 as it had no change so we need to take the previuos days value.
-- STAGE TABLE
CREATE TABLE stage_tbl
(ID INTEGER,
change_id INTEGER,
update_time TIMESTAMP(6),
columnname VARCHAR(30),
change_log_from VARCHAR(10),
change_log_to VARCHAR(10)
) PRIMARY INDEX (ID);
INSERT INTO stage_tbl VALUES (1234,5678,'2013-07-01 07:00.00.000000','change_col_1','','erf');
INSERT INTO stage_tbl VALUES (1234,5678,'2013-08-01 08:00.00.000000','change_col_2','lks','txh');
INSERT INTO stage_tbl VALUES (1234,5678,'2013-08-01 09:00.00.000000','change_col_1','erf','fdr');
INSERT INTO stage_tbl VALUES (1234,5678,'2013-08-01 09:00.00.000000','change_col_2','txh','rep');
INSERT INTO stage_tbl VALUES (1234,5678,'2013-08-01 09:00.00.000000','change_col_3','','fdy');
INSERT INTO stage_tbl VALUES (1234,5678,'2013-08-01 09:00.00.000000','change_col_4','rfd','uif');
INSERT INTO stage_tbl VALUES (1234,5678,'2013-08-01 09:00.00.000000','change_col_5','lop','jhr');
INSERT INTO stage_tbl VALUES (1234,5678,'2013-08-01 11:00.00.000000','change_col_5','jhr','puh');
INSERT INTO stage_tbl VALUES (1234,78965,'2013-07-01 07:00.00.000000','change_col_1','rdt','ted');
INSERT INTO stage_tbl VALUES (1234,78965,'2013-08-01 08:00.00.000000','change_col_2','wfs','trh');
INSERT INTO stage_tbl VALUES (1234,78965,'2013-08-01 09:00.00.000000','change_col_3','','');
INSERT INTO stage_tbl VALUES (1234,23654,'2013-08-01 08:00.00.000000','change_col_4','gfd','');
INSERT INTO stage_tbl VALUES (1234,32111,'2013-08-01 09:00.00.000000','change_col_5','red','');
-- WRITE A QUERY ON STAGE TABLE SO THAT WE GET THE RESULTS AS IN expected_res below:
CREATE TABLE expected_res
(ID INTEGER,
change_id INTEGER,
update_time TIMESTAMP(6),
change_col_1 VARCHAR(10),
change_col_2 VARCHAR(10),
change_col_3 VARCHAR(10),
change_col_4 VARCHAR(10),
change_col_5 VARCHAR(10)
) PRIMARY INDEX (ID);
INSERT INTO expected_res VALUES (1234,5678,'2013-07-01 07:00.00.000000','erf','lks',NULL,'rfd','lop');
INSERT INTO expected_res VALUES (1234,5678,'2013-08-01 08:00.00.000000','erf','txh',NULL,'rfd','lop');
INSERT INTO expected_res VALUES (1234,5678,'2013-08-01 09:00.00.000000','fdr','rep','fdy','uif','jhr');
INSERT INTO expected_res VALUES (1234,5678,'2013-08-01 11:00.00.000000','fdr','rep','fdy','uif','puh');
INSERT INTO expected_res VALUES (1234,78965,'2013-07-01 07:00.00.000000','ted','wfs',NULL,NULL,NULL);
INSERT INTO expected_res VALUES (1234,78965,'2013-08-01 08:00.00.000000','ted','trh',NULL,NULL,NULL);
INSERT INTO expected_res VALUES (1234,78965,'2013-08-01 09:00.00.000000','ted','trh',NULL,NULL,NULL);
INSERT INTO expected_res VALUES (1234,23654,'2013-08-01 08:00.00.000000',NULL,NULL,NULL,'gfd',NULL);
INSERT INTO expected_res VALUES (1234,32111,'2013-08-01 09:00.00.000000',NULL,NULL,NULL,NULL,'red');
LOGIC:
- The row in the target table should be at ID/Change_Id/update_time level
- If the value for a particluar column doesnt come in the following delta then we should take the previous value for e.g. 1234 5678 2013-07-01 07:00.00.000000
we got the value for change_column_1 as erf
but in the next days run i.e. 2013-08-01 08:00.00.000000 there was no value for change_column_1 as it had no change so we need to take the previuos days value.