A Loop is an Iterative Control Structure that involves executing the same number of code a number of times until a certain condition is met.

PHP For Loop

The above code outputs “21 is greater than 7” For loops For... loops execute the block of code a specifiednumber of times. There are basically two types of for loops;

  • for
  • for… each.

Let’s now look at them separately. For loop It has the following basic syntax

<?php
for (initialize; condition; increment){

//code to be executed

}
?>

 

What is a View?

Views are similar to tables, which are generated based on the requirements.

  • We can save any result set data as a view in Hive
  • Usage is similar to as views used in SQL
  • All type of DML operations can be performed on a view

Creation of View:

Syntax:

Create VIEW < VIEWNAME> AS SELECT

Example:

Hive>Create VIEW Sample_ViewAS SELECT * FROM employees WHERE salary>25000

In this example, we are creating view Sample_View where it will display all the row values with salary field greater than 25000.

 

Tables, Partitions, and Buckets are the parts of Hive data modeling.

What is Partitions?

Hive Partitions is a way to organizes tables into partitions by dividing tables into different parts based on partition keys.

Partition is helpful when the table has one or more Partition keys. Partition keys are basic elements for determining how the data is stored in the table.

For Example: -

"Client having Some E –commerce data which belongs to India operations in which each state (38 states) operations mentioned in as a whole. If we take state column as partition key and perform partitions on that India data as a whole, we can able to get Number of partitions (38 partitions) which is equal to number of states (38) present in India. Such that each state data can be viewed separately in partitions tables.

Sample Code Snippet for partitions

  1. Creation of Table all states
create table all states(state string, District string,Enrolments string)

row format delimited

fields terminated by ',';
  1. Loading data into created table all states
Load data local inpath '/home/hduser/Desktop/AllStates.csv' into table allstates;
  1. Creation of partition table
create table state_part(District string,Enrolments string) PARTITIONED BY(state string);
  1. For partition we have to set this property

    set hive.exec.dynamic.partition.mode=nonstrict
  2. Loading data into partition table
INSERT OVERWRITE TABLE state_part PARTITION(state)

SELECT district,enrolments,state from allstates;
  1. Actual processing and formation of partition tables based on state as partition key
  2. There are going to be 38 partition outputs in HDFS storage with the file name as state name. We will check this in this step

The following screen shots will show u the execution of above mentioned code

Data operations in Hive

Data operations in Hive

Data operations in Hive

Data operations in Hive

From the above code, we do following things

  1. Creation of table all states with 3 column names such as state, district, and enrollment
  2. Loading data into table all states
  3. Creation of partition table with state as partition key
  4. In this step Setting partition mode as non-strict( This mode will activate dynamic partition mode)
  5. Loading data into partition tablestate_part
  6. Actual processing and formation of partition tables based on state as partition key
  7. There is going to 38 partition outputs in HDFS storage with the file name as state name. We will check this in this step. In This step, we seeing the 38 partition outputs in HDFS

What is Buckets?

Buckets in hive is used in segregating of hive table-data into multiple files or directories. it is used for efficient querying.

  • The data i.e. present in that partitions can be divided further into Buckets
  • The division is performed based on Hash of particular columns that we selected in the table.
  • Buckets use some form of Hashing algorithm at back end to read each record and place it into buckets
  • In Hive, we have to enable buckets by using the set.hive.enforce.bucketing=true;

Step 1) Creating Bucket as shown below.

Data operations in Hive

From the above screen shot

  • We are creating sample_bucket with column names such as first_name, job_id, department, salary and country
  • We are creating 4 buckets overhere.
  • Once the data get loaded it automatically, place the data into 4 buckets

Step 2) Loading Data into table sample bucket

Assuming that"Employees table" already created in Hive system. In this step, we will see the loading of Data from employees table into table sample bucket.

Before we start moving employees data into buckets, make sure that it consist of column names such as first_name, job_id, department, salary and country.

Here we are loading data into sample bucket from employees table.

Data operations in Hive

Step 3)Displaying 4 buckets that created in Step 1

Data operations in Hive

From the above screenshot, we can see that the data from the employees table is transferred into 4 buckets created in step 1.

 

Table Operations such as Creation, Altering, and Dropping tables in Hive can be observed in this tutorial.

In the Below screenshot, we are creating a table with columns and altering the table name.

1. Creating table guru_sample with two column names such as "empid" and "empname"

2. Displaying tables present in guru99 database

3. Guru_sample displaying under tables

4. Altering table "guru_sample" as "guru_sampleNew"

5. Again when you execute "show" command, it will display the new name Guru_sampleNew

Data operations in Hive

Dropping table guru_sampleNew:

Data operations in Hive

 

In this tutorial, you will learn-

 

Functions are built for a specific purpose to perform operations like Mathematical, arithmetic, logical and relational on the operands of table column names.

Built-in functions

These are functions that already available in Hive. First, we have to check the application requirement, and then we can use this built in functions in our applications. We can call these functions directly in our application.

The syntax and types are mentioned in the following section.

Types of Built-in Functions in HIVE

  • Collection Functions
  • Date Functions
  • Mathematical Functions
  • Conditional Functions
  • String Functions
  • Misc. Functions

 

To understand Requirement Based testing, let’s first understand what is a requirement & who creates them-

What are Requirements?

Oxford dictionary defines requirement as a need, wish, demand, and want, necessity, prerequisite, required and essential. Simply, in product development, we can say that requirements are users need or customers need (business people need, or stake holders need, or any users need) to solve a problem or achieve a task. It should be defined clear, precise, accurate, what should be covered, what should not be covered, meaningful, covered all information and should achieve some objective.