Hive

3 / 18

Hive - Getting Started - Hands-on




Not able to play video? Try with youtube

We can access hive from the command line Let's connect to hive from the command line Login into CloudxLab Linux console Type hive and wait for hive prompt to appear this is called hive CLI or hive command-line interface. By default the database with the name default is the current database in the hive shell, to see the list of all databases type show databases;. As you can see there are 1557 databases in hive as of now, to see the list of all tables type show tables; .There are 887 tables in the default database, please create your database with the name same as your username. Make sure to create all the tables in your database instead of polluting the default database. Let's make a database with your username here our username is mayank8645, type create database ${env:USER}; to create database with your own name, the string ${env:USER} is replaced by your username automatically. Type describe database followed by your username or described database followed by the environment variable for user to see the metadata of the database. As you can see the database is located in the apps hive warehouse directory. To change the current database the use command is used. Type use followed by the database name or the variable that represents the user because the username is same as the database name for us and press enter, as you can see the current database had changed to your database. Now let's create a table with the name x inside your database. Type create table x press enter and wait till the table is created. The describe command displays metadata or information about a table such as names of columns and their data types. To see the metadata of the table x type describe x and press enter there is only one column a with int data type. To see the metadata and low label details type describe formatted x;. We can see the column names, their data types, database name, owner name, created time, hive warehouse location and the table type.

INSTRUCTIONS

Steps:

  • Login to the web console using your cloudxlab username and password
  • Launch Hive by typing hive in the web console
  • To see the list of all databases type command:

    show databases;
    
  • To see the list of all tables type command:

    show tables;
    
  • To create your own database run below commands. ${env:USER} gets replaced by your username automatically:

    create database ${env:USER};
    
  • To see the metadata of your database run below commands. ${env:USER} gets replaced by your username automatically:

    describe database ${env:USER};
    
  • To use your database run below commands. ${env:USER} gets replaced by your username automatically:

    use ${env:USER};
    
  • To create a table x in your database type command:

    create table x (a int);
    
  • To view the data of table x type command:

    select * from x;
    
  • To view the metadata(structure) of the table type command:

    describe x;
    
  • To see the metadata and low-level details type command:

    describe formatted x;
    

Please login to comment

12 Comments

@Cloudxlab team , Getting permission issues, Could you please help me with this?

  Upvote    Share

Hi Sandeep,

Our team is actively investigating the issue, and we are working diligently to resolve it as soon as possible. We appreciate your patience during this process and will notify you once the error has been addressed.

 1  Upvote    Share

This comment has been removed.

Hi Shubh, thank you for the reply, pls do let me know once its resolved as my learning is stalled currently.

  Upvote    Share

Hi Sandeep,

The Hive issue has been fixed.

 1  Upvote    Share

Thank you so much Shubh. Have a great day :)

  Upvote    Share

Pl check my permisson!

FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. MetaException(message:java.security.AccessControlException: Permission denied: user=blackpulsar10009286, access=WRITE, inode="/apps/hive":hdfs:hdfs:drwxr-xr-x at org.apache.hadoop.hdfs.server.namenode.FSPermissionChecker.check(FSPermissionChecker.java:319) at org.apache.hadoop.hdfs.server.namenode.FSPermissionChecker.checkPermission(FSPermissionChecker.java:219) at org.apache.hadoop.hdfs.server.namenode.FSPermissionChecker.checkPermission(FSPermissionChecker.java:190) at org.apache.hadoop.hdfs.server.namenode.FSDirectory.checkPermission(FSDirectory.java:1955) at org.apache.hadoop.hdfs.server.namenode.FSDirectory.checkPermission(FSDirectory.java:1939) at org.apache.hadoop.hdfs.server.namenode.FSDirectory.checkPathAccess(FSDirectory.java:1913) at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.checkAccess(FSNamesystem.java:8750) at org.apache.hadoop.hdfs.server.namenode.NameNodeRpcServer.checkAccess(NameNodeRpcServer.java:2089) at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolServerSideTranslatorPB.checkAccess(ClientNamenodeProtocolServerSideTranslatorPB.java:1466) at org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos$ClientNamenodeProtocol$2.callBlockingMethod(ClientNamenodeProtocolProtos.java) at org.apache.hadoop.ipc.ProtobufRpcEngine$Server$ProtoBufRpcInvoker.call(ProtobufRpcEngine.java:640) at org.apache.hadoop.ipc.RPC$Server.call(RPC.java:982) at org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:2351) at org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:2347) at java.security.AccessController.doPrivileged(Native Method) at javax.security.auth.Subject.doAs(Subject.java:422) at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1866) at org.apache.hadoop.ipc.Server$Handler.run(Server.java:2345)

  Upvote    Share

Hi Bala,

Our team is actively investigating the issue, and we are working diligently to resolve it as soon as possible. We appreciate your patience during this process and will notify you once the error has been addressed.

  Upvote    Share

Hi Bala,

The Hive issue has been fixed.

  Upvote    Share

Useless

  Upvote    Share

There is a problem none of the commands given here work. Am I not doing something right?

 

  Upvote    Share

bash-4.2$ hive
log4j:WARN No such property [maxFileSize] in org.apache.log4j.DailyRollingFileAppender.

Logging initialized using configuration in file:/etc/hive/2.6.2.0-205/0/hive-log4j.properties
hive> show databases
    > show tables
    > create database ${env:USER};
FAILED: ParseException line 2:0 missing EOF at 'show' near 'databases'

  Upvote    Share