Hive interview questions - 5

25. What are the three different modes in which hive can be run ?
Local mode
Distributed mode
Pseudodistributed mode

26. Is there a date data type in Hive ?
Yes. The TIMESTAMP data types stores date in java.sql.timestamp format
Strings: JDBC compliant java.sql.Timestamp format "YYYY-MM-DD HH:MM:SS.fffffffff" (9 decimal place precision)

27. What are collection data types in Hive ?
There are three collection data types in Hive.
ARRAY
MAP
STRUCT
example :
CREATE TABLE employees (
name STRING,
salary FLOAT,
subordinates ARRAY<STRING>,
deductions MAP<STRING, FLOAT>,
address STRUCT<street:STRING, city:STRING, state:STRING, zip:INT>
)
ROW FORMAT DELIMITED

28. Can we run unix shell commands from hive ? Give example
Yes, using the ! mark just before the command.
For example !pwd at hive prompt will list the current directory.

29. What is a Hive variable? What for we use it ?
The hive variable is variable created in the Hive environment that can be referenced by Hive scripts. It is used to pass some values to the hive queries when the query starts executing.
You need to use the special hiveconf for variable substitution.
e.g.
hive> set CURRENT_DATE='2012-09-16'; 
hive> select * from foo where day >= '${hiveconf:CURRENT_DATE}'
Note that there are env and system variables as well, so you can reference ${env:USER} for example. To see all the available variables, from the command line, run
% hive -e 'set;'

30. Can hive queries be executed from script files ? How ?
Using the source command.
Example −
Hive> source /path/to/file/file_with_query.hql

12345678910