Wednesday, July 10, 2019

SLOWLY CHANGING DIMENSION (SCD) TYPES

Dimensions data change slowly over time, rather than changing on regular basis.

Slowly changing dimension (SCD) is the concept which describes how we store dimensional data (Historical or current) in warehouse.


Below are the types of SCD:

    Type 0 – In this the old dimensional data will be persisted and remains unchanged.


Customer_ID
Customer_Name
Customer_Type
1
Cust_1
Corporate

    Type 1 – In this the old dimensional data will be overwritten by the new data and history will not be preserved.

Before change
Customer_ID
Customer_Name
Customer_Type
1
Cust_1
Corporate

After change
Customer_ID
Customer_Name
Customer_Type
1
Cust_1
Retail

    Type 2 – In this the new record will be inserted for any change in the source and history will be preserved by creating a new additional record


Before the change: 
Customer_ID
Customer_Name
Customer_Type
Start_Date
End_Date
Current_Flag
1
Cust_1
Corporate
22-07-2010
31-12-9999
Y
After the change: 
Customer_ID
Customer_Name
Customer_Type
Start_Date
End_Date
Current_Flag
1
Cust_1
Corporate
22-07-2010
17-05-2012
N
2
Cust_1
Retail
18-05-2012
31-12-9999
Y

    Type 3 – This is similar to Type 2 SCD the only difference being instead of adding a new row we will be adding a new column.

          Unlike Type 2 SCD this will only store partial history as shown in below table. 

 Before the change: 

Customer_ID
Customer_Name
Current_Type
Previous_Type
1
Cust_1
Corporate
Corporate

After the change: 
Customer_ID
Customer_Name
Current_Type
Previous_Type
1
Cust_1
Retail
Corporate

    Type 4 – This is combination of SCD Type 1 and Type 2 where we create 2 dimension table one with the current data and other which stores historical data similar to type 2 dimension.


Current table: 
Customer_ID
Customer_Name
Customer_Type
1
Cust_1
Corporate
Historical table: 
Customer_ID
Customer_Name
Customer_Type
Start_Date
End_Date
1
Cust_1
Retail
01-01-2010
21-07-2010
1
Cust_1
Oher
22-07-2010
17-05-2012
1
Cust_1
Corporate
18-05-2012
31-12-9999

    Type 6 – It is a Combination of SCD type 1,2,3 (1+2+3=6) which stores historical data in rows and columns both as shown in below table.


Customer_ID
Customer_Name
Current_Type
Historical_Type
Start_Date
End_Date
Current_Flag
1
Cust_1
Corporate
Retail
01-01-2010
21-07-2010
N
2
Cust_1
Corporate
Other
22-07-2010
17-05-2012
N
3
Cust_1
Corporate
Corporate
18-05-2012
31-12-9999
Y

Tuesday, July 9, 2019

HOW TO GET ALL ROWS DATA OF A COLUMN IN MATLAB

How to get all rows data of a particular column:
 Ex: Daily temperature and humidity data=>data=[256 60
                                                                                 270 80
                                                                                 269 70
                                                                                 265 65]
data(:,1)==>gives the temperature data which presents in the 1st column
        ↓ ↳ 1st column
      all
     rows

data(:,2)==>gives the humidity data which present in the 2nd column
         ↓ ↳ 2nd column
      all
     rows

Monday, July 1, 2019

SQL QUERY TO REPLACE HTML TAGS FROM A STRING USING REGEXP_REPLACE


1.      Below query is used to eliminate html tags and other entities like &amp ,&nbsp etc. 

SELECT trim(regexp_replace('<p style="margin-left:30px;">Replacing html tags &amp; entities with space using regular expresion&nbsp;.</p>',
'<.+?>|\&(nbsp;)|(amp;)|(quot;)|(lt;)|(gt;)', ' ')) as plain_col
FROM dual ;

Result:

Replacing html tags & entities with space using regular expression.

2.    If you want to add new entity like font-size:xx-large; add the code in the above expression as shown below.


SELECT trim(regexp_replace(column_name,
'<.+?>|\&(nbsp;)|(amp;)|(quot;)|(lt;)|(gt;) |
(font-size:xx-large;)', ' ')) as plain_col
FROM Table_Name ;

3