Vous êtes sur la page 1sur 5

ASSIGNMENT 7 - AGoyal

ANSWER 1
CREATE external TABLE salesrecords2
(
Region varchar(30), Country varchar(30), ItemType varchar(30),
SalesChannel varchar(30), OrderPriority char(2), OrderDate date,
OrderID int, ShipDate date, UnitsSold int, UnitPrice float,
UnitCost float, TotalRevenue float, TotalCost float,
TotalProfit float
)
row format delimited
fields terminated by ','
stored as textfile
location '/user/hive/AGoyal/salesrecords_hive_table'
TBLPROPERTIES("skip.header.line.count"="1") ;

ANSWER 2
The number of blocks is 2, namely as, Block 0 and Block 1.
The Block Information of Block 0: -
Block ID: 1073741852,
Block Pool ID: - BP-450056922-127.0.1.1-1534560470572
Generation Stamp: - 1028
Size: 134217728
Availability: virtual machine
The Block Information of Block 1: -
Block ID: 1073741853,
Block Pool ID: - BP-450056922-127.0.1.1-1534560470572
Generation Stamp: - 1029
Size: 123469824
Availability: virtual machine
ANSWER 3a
SELECT region,count(1) as cnt FROM salesrecords2 GROUP BY region ORDER BY cnt
DESC;

ANSWER 3b
SELECT ItemType, SalesChannel,count(1) as cnt FROM salesrecords2 GROUP BY
ItemType,SalesChannel ORDER BY cnt DESC;
ANSWER 3c
SELECT itemtype, count(itemtype) FROM salesrecords2 WHERE TotalCost < TotalProfit
GROUP BY itemtype;

ANSWER 3d
SELECT country, find_in_set('Europe', region) FROM salesrecords2 WHERE totalcost<7;
ANSWER 3e
SELECT country, CASE country
when ‘Bhutan’ then ‘Yes’
when ‘Malawi’ then ‘Yes’
when ‘Qatar’ then ‘Yes’
else ‘No’
END from salesrecords2 where totalcost<7;