const member function

const member function does not allow to modify nonstatic data member value of an object. Below is the prototype for const function: <return-value> function() const;const function with empty definition look like: <return-value> <className>::function() const {}From the above you can see that with the const keyword, we can make function a const function. const function makes this pointer as pointer to a const because of this reason, we cannot modify object data i.e. nonstatic data member of an object. const function can be called from const object as well as non-const…

Mutable storage class specifier

mutable is the one of the storage specifier in C++. In general, const function does not allow to modify data members of an object who called it. However, with the help of mutable specifier, we can achieve it.Simple example shows use of mutable specifier. #include <iostream>using namespace std;class base { unsigned int m_int; mutable unsigned int m_mutableInt;public: base(unsigned int x, unsigned int y) { m_int = x; m_mutableInt = y; } void read() const { //const function m_int = 40; // Error: This is not allowed. m_mutableInt = 10; //…

Static function

Static function is used to access static data members of a class.Static function is called using class name and scope resolution operator. We do not need an object to call static function. //Header fileclass singleton {    static singleton* m_instance;    singleton() {}    singleton& operator=(const singleton& );    singleton(const singleton& );     public:    ~singleton() {}    static singleton* getInstance(); }; //Source file singleton* singleton::m_instance = NULL;singleton* singleton::getInstance() {  //static function accessing static data member m_instance    if (NULL == m_instance) {        return new singleton;  …

Data validation across environments using HASH

Today i will discuss about data validation across environments using HASH function. There are times we need to validate the data of same table in different environments which is very monotonous and time consuming task while doing manually. Its better to automate the process. Here , I am considering the three environments Hive,IBM DB2,Snowflake Database.HIVE:md5(concatenated_columns)SNOWFLAKE:MD5_HEX (concatenated_columns)IBM DB2:HEX(HASH_MD5( concatenated_columns) Here, you need to take care of below things.1. Hexadecimal Output may in uppercase or lowercase, so handle with UPPER or LOWER function across environments.2. You need to take care of nulls…

Count the number of nulls using left join

Today, I will discuss about How to calculate the number of nulls that gets populated with left join or %age of matched data or count of not nulls using left join. CASE 1:Calculate the number of nulls that gets populated from right hand table using left join.Assume , I have two employee table EMP_TBL1 and EMP_TBL2. See the data for the same. EMP_TBL1 EMP_TBL2 below is the code used to get number of nulls that comes from right side table using left join. select count(*)-count(y_empid) from ( select x.emp_id ,y.emp_id…

Internal and External tables in Hive

Today, I will present types of tables that can be created in hive in a different way. I created three tables in hive.create table empdtls (emp_id int ); { This is called Internal or Managed table} create external table empdtls_ext (emp_id int ); { This is External table } create external table empdtls_ext_v2 ( emp_id int ) location ‘/user/demo/hivetesting/’ { This is also called External table} Now, we will check the TABLE_TYPE of all above tables using command DESCRIBE FORMATTED table_name Internal Or Managed Table/user/hive/warehouse/ is the location where all…

call macro present in another SAS code

Today, I will discuss about How to call macro whose code is present in another SAS script. First, we need to understand why another SAS script is required. Answer to this is very simple that is redundant code. Many a times, particular portion of code is used in many SAS scripts like getting today’s date or yesterday’s date or yesterday’s month or year. For this , It is recommended to write a separate code and call that code in the existing script.Here, I have created two SAS Scripts. FIRST SCRIPT…

get position of all delimiter values in a string

Today, I will explain about “How to get position and values separated by delimiter in a string”. Delimiter may be comma,pipe,colon etc. STEP1 : Get position of all delimiters in a string. I am explaining with SQL-server as Database. ;with T as ( select 0 as row_id, charindex(‘,’, @string) pos union all select pos + 1, charindex(‘,’, @string, pos + 1) from T where pos > 0)select * from T For example , consider a string “Harsimran,Kaur,91-123-456-7890” . So, it has first name and last name and dummy mobile number.…

Check duplicate record in Hive

Today, I will discuss about ” How to automate the process where in you can check entire row duplicate record in hive”. As I have mentioned in all Automation blogs, I will share the pseudo code.STEP1: In hive , use “desc table_name” , this command will give you column names along with datatype and data length. Store the output of this command in a file , say HIVE_TABLE_DDL.txt STEP2 : Read the file HIVE_TABLE_DDL.txt using “cat” command. cat HIVE_TABLE_DDL.txt | awk ‘{print $1}’ ORS=’,’ | sed ‘s/,$//’ * awk'{print $1}’…

equivalent of sum of columns in SAS

Today, I will discuss about “How to design SAS code which is equivalent of sum of columns in database. Consider the below employee details. In order to get sum of Year-2019 and Year-2020, we need to use add (+) operator to achieve the same. See the below Query and data for the same. Here, i applied ,normal addition, sum using ISNULL function, difference using absolute(ABS) function. In order to achieve the same in SAS . Create the same Datasets . See the below Screen Shot for the same. Now, create…