Showing posts with label hive. Show all posts
Showing posts with label hive. Show all posts

Hive Interview Question

Wipro :-

1. Write syntax to hive creating a table and explain each part.
2. What is location stands for in that syntax?
3. What is stored as command do? how many type of files are there? what are their difference?
4. What is serde ? Why you use it? What are different format of Serde ?
5. How to process an unbounded XML file with schema defined in hive ?
6. What is UDF and UTDF? what are the difference between them ?
7. What is RC and ORC file ? and why they have been used for?

Common :-
1. How to load bulk data in hive partition?
2. What are the drawbacks of Hive?
3. What hive and hadoop version you have worked on ?
4. How to do update and delete in in Hive?
5. Incremental update in Hive ?

Hive Installation in Ubuntu

Installing Hive from Cloudera is very simple and it needs to follow below simple steps :-

1. sudo apt-get install hive hive-metastore hive-server2 hive-hbase
2. sudo apt-get install hive-jdbc
3. Add /usr/lib/hive/lib/*.jar and /usr/lib/hadoop/*.jar to your classpath.

$sudo gedit .bashrc
export HIVE_HOME=/usr/lib/hive
export PATH=$PATH:$HIVE_HOME/bin
export CLASSPATH=$CLASSPATH:/usr/lib/Hadoop/lib/*:.
export CLASSPATH=$CLASSPATH:/usr/lib/hive/lib/*:.

$ cd $HIVE_HOME/conf
$ sudo cp hive-env.sh.template hive-env.sh

$sudo gedit hive-env.sh
export HADOOP_HOME=/usr/lib/hadoop

Well that will do enough to install hive but you need to do bit more configuration for metastore.

Step 1 :- You first need to install MySql

$ sudo apt-get install mysql-server
$ sudo service mysql start
$ sudo apt-get install libmysql-java
$ sudo ln -s /usr/share/java/libmysql-java.jar /usr/lib/hive/lib/libmysql-java.jar [to be done after installing hive]
$ sudo /usr/bin/mysql_secure_installation
$ sudo apt-get install sysv-rc-conf

Step 2 :- Create metastore database in mysql and user

$ sudo sysv-rc-conf mysql on
$ mysql -u root -p
Enter password:
mysql> CREATE DATABASE metastore;
mysql> USE metastore;
mysql> SOURCE /usr/lib/hive/scripts/metastore/upgrade/mysql/hive-schema-0.12.0.mysql.sql;

mysql> CREATE USER 'hive'@'localhost' IDENTIFIED BY 'mypassword';
...
mysql> REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'hive'@'localhost';
mysql> GRANT SELECT,INSERT,UPDATE,DELETE,LOCK TABLES,EXECUTE ON metastore.* TO 'hive'@'localhost';
mysql> FLUSH PRIVILEGES;
mysql> quit;

Step 3 :- Configure Hive Site xml file to make Hive use the metastore

sudo gedit /usr/lib/hive/conf/hive-site.xml

<property>
  <name>javax.jdo.option.ConnectionURL</name>
  <value>jdbc:mysql://localhost/metastore</value>
  <description>the URL of the MySQL database</description>
</property>

<property>
  <name>javax.jdo.option.ConnectionDriverName</name>
  <value>com.mysql.jdbc.Driver</value>
</property>

<property>
  <name>javax.jdo.option.ConnectionUserName</name>
  <value>hive</value>
</property>

<property>
  <name>javax.jdo.option.ConnectionPassword</name>
  <value>mypassword</value>
</property>

<property>
  <name>datanucleus.autoCreateSchema</name>
  <value>false</value>
</property>

<property>
  <name>datanucleus.fixedDatastore</name>
  <value>true</value>
</property>

<property>
  <name>datanucleus.autoStartMechanism</name>
  <value>SchemaTable</value>
</property>

<property>
  <name>hive.metastore.uris</name>
  <value>thrift://localhost:9083</value>
  <description>IP address (or fully-qualified domain name) and port of the metastore host</description>
</property>


<property>
  <name>hive.support.concurrency</name>
  <description>Enable Hive's Table Lock Manager Service</description>
  <value>true</value>
</property>

<property>
  <name>hive.zookeeper.quorum</name>
  <description>Zookeeper quorum used by Hive's Table Lock Manager</description>
  <value>localhost</value>
</property>



<property>
  <name>hive.zookeeper.client.port</name>
  <value>2181</value>
  <description>
  The port at which the clients will connect.
  </description>
</property>

Step 4 :- Create the below directory for hive to access


sudo -u hdfs hadoop fs -mkdir -p /user/hive/warehouse
sudo -u hdfs hadoop fs -chmod g+w /user/hive/warehouse

Step 5 :- Trouble Shooting Hive

Though the above steps will be enough to run hive successfully but in case it is not running you need to check the log files in /var/log/hive directory
I have faced two problem even after successfully installing it.

1. BOPTM connection failure to use it's metastore.[https://hadooptutorial.info/datastore-driver-was-not-found/]

For this you need to download latest version of mysql connector and install it in the below specified way.

$ cd Downloads/
$ tar -xzf mysql-connector-java-5.1.35.tar.gz
$ cd mysql-connector-java-5.1.35/
$ sudo cp mysql-connector-java-5.1.35-bin.jar $HIVE_HOME/lib/

2. Unknown column 'OWNER_NAME' in 'field list' [https://community.cloudera.com/t5/Interactive-Short-cycle-SQL/CDH-upgrade-from-4-7-to-CDH-5-2-hive-metastore-issue/td-p/20626]

This has happened for the previous step where we have run  SOURCE /usr/lib/hive/scripts/metastore/upgrade/mysql/hive-schema-0.12.0.mysql.sql;. This will only valid for hive version 0.8 but as our new hive version is 1.1.0 so we have to run the code

SOURCE /usr/lib/hive/scripts/metastore/upgrade/mysql/hive-schema-1.1.0.mysql.sql;

but this file will have a reference to txn-0.13.0 schema sql file but the entire path is not mentioned on the schema sql file hence make sure you modify the file hive-schema-1.1.0.mysql.sql and give the full path as /usr/lib/hive/scripts/metastore/upgrade/mysql/txn-0.13.0.mysql.sql

Hive Commands

What is Hive?

Apache Hive is a Data warehouse system which is built to work on Hadoop. It is used to querying and managing large datasets residing in distributed storage. Before becoming a open source project of Apache Hadoop, Hive was originated in Facebook. It provides a mechanism to project structure onto the data in Hadoop and to query that data using a SQL-like language called HiveQL (HQL).
Hive is used because the tables in Hive are similar to tables in a relational database. If you are familiar with SQL, it’s a cakewalk. Many users can simultaneously query the data using Hive-QL.

What is HQL?

Hive defines a simple SQL-like query language to querying and managing large datasets called Hive-QL ( HQL ). It’s easy to use if you’re familiar with SQL Language. Hive allows programmers who are familiar with the language to write the custom MapReduce framework to perform more sophisticated analysis.

Uses of Hive:

1. The Apache Hive distributed storage.
2. Hive provides tools to enable easy data extract/transform/load (ETL)
3. It provides the structure on a variety of data formats.
4. By using Hive, we can access files stored in Hadoop Distributed File System (HDFS is used to querying and managing large datasets residing in) or in other data storage systems such as Apache HBase.

Limitations of Hive:

• Hive is not designed for Online transaction processing (OLTP ), it is only used for the Online Analytical Processing.
• Hive supports overwriting or apprehending data, but not updates and deletes.
• In Hive, sub queries are not supported.

Why Hive is used inspite of Pig?

The following are the reasons why Hive is used in spite of Pig’s availability:
  • Hive-QL is a declarative language line SQL, PigLatin is a data flow language.
  • Pig: a data-flow language and environment for exploring very large datasets.
  • Hive: a distributed data warehouse.

Components of Hive:

Metastore :
Hive stores the schema of the Hive tables in a Hive Metastore. Metastore is used to hold all the information about the tables and partitions that are in the warehouse. By default, the metastore is run in the same process as the Hive service and the default Metastore is DerBy Database.
SerDe :
Serializer, Deserializer gives instructions to hive on how to process a record.

Hive Commands :

Data Definition Language (DDL )
DDL statements are used to build and modify the tables and other objects in the database.
Example :
CREATE, DROP, TRUNCATE, ALTER, SHOW, DESCRIBE Statements.
Go to Hive shell by giving the command sudo hive and enter the command ’create database <data base name>’ to create the new database in the Hive.
Create Hive database using Hive Commands
To list out the databases in Hive warehouse, enter the command ‘show databases’.
List Hive database using Hive Commands
The database creates in a default location of the Hive warehouse. In Cloudera, Hive database store in a /user/hive/warehouse.
List Hive database using Hive Commands
The command to use the database is USE <data base name>
Hive command to use the database
Copy the input data to HDFS from local by using the copy From Local command.
 Input data in Hive
Hive table
When we create a table in hive, it creates in the default location of the hive warehouse. – “/user/hive/warehouse”, after creation of the table we can move the data from HDFS to hive table.
The following command creates a table with in location of “/user/hive/warehouse/retail.db”
Note : retail.db is the database created in the Hive warehouse.
Creating Database in Hive Warehouse.
Describe provides information about the schema of the table.
Describe - Hive Command
Data Manipulation Language (DML )
DML statements are used to retrieve, store, modify, delete, insert and update data in the database.
Example :
LOAD, INSERT Statements.
Syntax :
LOAD data <LOCAL> inpath <file path> into table [tablename]
The Load operation is used to move the data into corresponding Hive table. If the keyword local is specified, then in the load command will give the local file system path. If the keyword local is not specified we have to use the HDFS path of the file.
DML statement - Load Command
DML statement - Load Command
Here are some examples for the LOAD data LOCAL command
DML statement - Load Command
DML statement - Load Command
After loading the data into the Hive table we can apply the Data Manipulation Statements or aggregate functions retrieve the data.
Example to count number of records:
Count aggregate function is used count the total number of the records in a table.
Example to count number of records:
‘create external’ Table :
The create external keyword is used to create a table and provides a location where the table will create, so that Hive does not use a default location for this table. An EXTERNAL table points to any HDFS location for its storage, rather than default storage.
Create External Command in Hive
Create External Command in Hive
Insert Command:
The insert command is used to load the data Hive table. Inserts can be done to a table or a partition.
• INSERT OVERWRITE is used to overwrite the existing data in the table or partition.
• INSERT INTO is used to append the data into existing data in a table. (Note: INSERT INTO syntax is work from the version 0.8)
Insert Command
Insert Command

Example for ‘Partitioned By’ and ‘Clustered By’ Command :

‘Partitioned by‘ is used to divided the table into the Partition and can be divided in to buckets by using the ‘Clustered By‘ command.
Example for 'Partitioned By' and 'Clustered By' Command
Example for 'Partitioned By' and 'Clustered By' Command
When we insert the data Hive throwing errors, the dynamic partition mode is strict and dynamic partition not enabled. So we need to set the following parameters in Hive shell.
set hive.exec.dynamic.partition=true;
To enable dynamic partitions, by default, it’s false
set hive.exec.dynamic.partition.mode=nonstrict;
Dynamic Partitions
Dynamic Partitions
Dynamic Partitions
Partition is done by the category and can be divided in to buckets by using the ‘Clustered By’ command.
Partition
The ‘Drop Table’ statement deletes the data and metadata for a table. In the case of external tables, only the metadata is deleted.
Drop Table statement
Drop Table statement
The ‘Drop Table’ statement deletes the data and metadata for a table. In the case of external tables, only the metadata is deleted.
Load data local inpath ‘aru.txt’ into table tablename and then we check employee1 table by using Select * from table name command
To count the number of records in table by using Select count(*) from txnrecords;
To count the number of records in table by using Select count(*) from txnrecords;
To count the number of records in table by using Select count(*) from txnrecords;

Aggregation :

Select count (DISTINCT category) from tablename;
This command will count the different category of ‘cate’ table. Here there are 3 different categories.
Suppose there is another table cate where f1 is field name of category.
 Count the different category of 'cate' table.
 Count the different category of 'cate' table.

Grouping :

Group command is used to group the result-set by one or more columns.
Select category, sum( amount) from txt records group by category
It calculates the amount of same category.
Group command
The result one table is stored in to another table.
Create table newtablename as select * from oldtablename;
Group command

Join Command :

Here one more table is created in the name ‘mailid’
Join Command
Join Command

Join Operation:

A Join operation is performed to combining fields from two tables by using values common to each.
Join Operation

Left Outer Join:

The result of a left outer join (or simply left join) for tables A and B always contains all records of the “left” table (A), even if the join-condition does not find any matching record in the “right” table (B).
Left Outer Join
Left Outer Join

Right Outer Join:

A right outer join (or right join) closely resembles a left outer join, except with the treatment of the tables reversed. Every row from the “right” table (B) will appear in the joined table at least once.
Right Outer Join
Right Outer Join

Full Join:

The joined table will contain all records from both tables, and fill in NULLs for missing matches on either side.
Full Join
Full Join
Once done with hive we can use quit command to exit from the hive shell.
Exiting from Hive

Hive Data Model



Hive is a data warehouse system for Hadoop that facilitates easy data summarization, ad-hoc queries, and the analysis of large datasets stored in Hadoop compatible file systems. Hive structures data into well-understood database concepts such as tables, rows, columns and partitions. It supports primitive types like Integers, Floats, Doubles, and Strings. Hive also supports Associative Arrays, Lists, Structs, and Serialize and Deserialized API is used to move data in and out of tables.
Let’s look at Hive Data Models in detail;

Hive Data Models:

The Hive data models contain the following components:
  • Databases
  • Tables
  • Partitions
  • Buckets or clusters
Hive Data Models

Partitions:

Partition means dividing a table into a coarse grained parts based on the value of a partition column such as ‘data’. This makes it faster to do queries on slices of data
Hive Data Models
So, what is the function of Partition? The Partition keys determine how data is stored. Here, each unique value of the Partition key defines a Partition of the table. The Partitions are named after dates for convenience. It is similar to ‘Block Splitting’ in HDFS.

Buckets:

Buckets give extra structure to the data that may be used for efficient queries. A join of two tables that are bucketed on the same columns, including the join column can be implemented as a Map-Side Join. Bucketing by used ID means we can quickly evaluate a user-based query by running it on a randomized sample of the total set of users.
Hive Data Models
Got a question for us? Please mention them in the comments section and we will get back to you.

Create Your First Hive Script

As is the case with scripts in other languages such as SQL, Unix Shell etc., Hive scripts are used to execute a set of Hive commands collectively. This helps in reducing the time and effort invested in writing and executing each command manually. This blog is a step by step guide to write your first Hive script and executing it.
Hive supports scripting from Hive 0.10.0 and above versions. Cloudera distribution for hadoop (CDH4) quick VM comes with pre-installed Hive 0.10.0 (CDH3 Demo VM uses Hive 0.90 and hence, cannot run Hive Scripts).
Execute the following steps to create your first Hive Script:

Step1: Writing a script

Open a terminal in your Cloudera CDH4 distribution and give the below command to create a Hive Script.
command: gedit sample.sql
The Hive script file should be saved with .sql extension to enable the execution.
Edit the file and write few Hive commands that will be executed using this script.
In this sample script, we will create a table, describe it, load the data into the table and retrieve the data from this table.
  • Create a table ‘product’ in Hive:

command: create table product ( productid: int, productname: string, price: float, category: string) rows format delimited fields terminated by ‘,’ ;
Here { productid, productname, price, category} are the columns in the ‘product’ table.
Fields terminated by ‘,’ ” indicates that the columns in the input file are separated by the  ‘,’ delimiter.  You can use other delimiters also. For example, the records in an input file can be separated by a new line (‘\n’) character.
  • Describe the Table :

command: describe product;
  • Load the data into the Table:

To load the data into the table, create an input file which contains the records that needs to be inserted into the table.
command: sudo gedit input.txt
Create few records in the input text file as shown in the figure.
input text
Command: load data local inpath ‘/home/cloudera/input.txt’ into table product;
  • Retrieving the data:

To retrieve the data use select command.
command: select * from product;
The above command will retrieve all the records from the table ‘product’.
The script should look like as shown in the following image:
sample sql
Save the sample.sql file and close the editor. You are now ready to execute your first Hive script.

Step 2: Execute the Hive Script

Execute the hive script using the following command:
Command: hive –f /home/cloudera/sample.sql
While executing the script, make sure that you give the entire path of the script location. As the sample script is present in the current directory, I haven’t provided the complete path of the script.
The following image shows that that all the commands were executed successfully.
example
Congratulations on executing your first Hive script successfully!!!!

Beeswax

Introducing Beeswax

The Beeswax application enables you to perform queries on Apache Hive, a data warehousing system designed to work with Hadoop. You can create Hive tables, load data, run and manage Hive queries, and download the results in a Microsoft Office Excel worksheet file or a comma-separated values file.

Beeswax and Hive Installation and Configuration

Beeswax is installed as part of Hue. For more information about installing Hue, see Hue Installation.

Hive Configuration

Beeswax, the Hive user interface in Hue, uses your system's Hive installation and is compatible with Hive 0.7.
Your Hive data is stored in the Hadoop Distributed File System (HDFS), typically in the /user/hive/warehouse directory (or the directory you specify as hive.metastore.warehouse.dir in the hive-site.xml file). Make sure this directory exists and is writable by the users whom you expect to be creating tables. The directory /tmp (on the local file system) must also be world-writable because Hive uses it extensively.

Beeswax Configuration

If there is an existing Hive installation:
In /etc/hue/beeswax.ini, modify the hive_conf_dir property to refer to the directory containing hive-site.xml.
If there is no existing Hive installation:
For information about the configuration options in hive-site.xml, see http://wiki.apache.org/hadoop/Hive/AdminManual/Configuration. The hive-site.xml file is optional but it is often useful, particularly if you want to set up a metastore. You may store the hive-site.xml file in /etc/hue/conf, or instruct Beeswax to locate it using the hive_conf_dir configuration variable (see /etc/hue/beeswax.ini).

Sharing Saved Queries

By default, a Beeswax user can see the saved queries for all users – both his/her own queries and those of other Beeswax users. If this behavior is not desirable, there is a configuration option you can change in the /etc/hue/beeswax.ini file to restrict viewing saved queries to only the query owner and Hue administrators. To change this setting, find and uncomment the share_saved_queries property and set it tofalse.

Starting Beeswax

To start the Beeswax application, click this icon images/image1.jpeg in the application bar at the bottom of the Hue web page. The Beeswax Hive Query window opens in the Hue web page.

Installing the Beeswax Samples

You can install two sample Beeswax tables to use as examples.
To install Beeswax samples:
  1. In the Beeswax window, click Tables.
  2. In the Table List window, click install samples.
    images/image2.jpeg
    After you click install samples, the samples are displayed in the Hive Table List window. Beeswax removes the install samples button after the samples are installed so you can only install the samples once.

Working with Queries

The Hive Query view enables you to enter queries in Hive's Query Language (HQL), which is similar to Structured Query Language (SQL). You can name and save your queries to use later. When you submit a query, the Beeswax Server uses Hive to run the queries. You can either wait for the query to complete, or return later to find the queries in the Beeswax History view. You can also receive an email message after the query is completed.
 
For More Information
For information about HQL syntax, see http://wiki.apache.org/hadoop/Hive/LanguageManual.

Creating and Running Queries

To create and run a query:
  1. In the Beeswax Hive Query window, type the query.For example, to select all data from the sample_08 table, you would type:SELECT * FROM sample_08 
    images/image3.jpeg
  2. To view the Hive and Hadoop default settings for queries, click Settings at the top of the Beeswax window. To return to the Query Editor, click Query Editor.
  3. To override the default Hive and Hadoop settings for the current query, click Advanced.A panel opens on the left side of the window where you can specify the advanced settings.
    images/image4.jpeg
  4. Click the plus sign icon images/image5.jpeg to add a setting for the following options. Click the plus sign icon again to specify multiple settings for a group, such as Hive Settings.
    Option
    Description
    Hive Settings
    Use Hive Settings to override the Hive and Hadoop default settings. For Key, enter a Hive or Hadoop configuration variable name. For Value, enter the value you want to use for the variable. For example, to override the directory where structured hive query logs are created, you would enterhive.querylog.location for Key, and a path for Value. For information about Hive configuration variables, see: http://wiki.apache.org/hadoop/Hive/AdminManual/Configuration. For information about Hadoop configuration variables, see:http://hadoop.apache.org/common/docs/current/mapred-default.html
    File Resources
    Use File Resources to make locally accessible files available at query execution time on the entire Hadoop cluster. Hive uses Hadoop's Distributed Cache to distribute the added files to all machines in the cluster at query execution time.From the Type drop-down menu, choose one of the following:JAR — Adds the resources to the Java classpath. This is required in order to reference objects such as user defined functions.ARCHIVE — Automatically unarchives resources when distributing them.FILE — Adds resources to the distributed cache. Typically, this might be a transform script (or similar) to be executed.For Path, enter the path to the file. You can also clickChoose a File to browse and select the file.Note: It is not necessary to specify files used in a transform script if the files are available in the same path on all machines in the Hadoop cluster.
    User-defined Functions
    You can use user-defined functions in a query. Specify the function name for Name, and specify the class name for Class name. You must specify a JAR file for the user-defined functions in File Resources. To include a user-defined function in a query, add a $ (dollar sign) before the function name in the query. For example, if MyTable is a user-defined function name in the query, you would type: SELECT * $MyTable
    Parameterization
    If you want to display a dialog box for you or other users to enter parameter values when a query is executed, select Parameterization.
    Email Notification
    If you want to receive an email message after a query completes, select Email Notification.
  5. Click the red Close icon images/image6.jpeg to close a group, and click all of the Close icons to close the Advanced panel.
  6. If you want to save your query and advanced settings to use them again later, click Save As, enter a name and description, and then click OK. To save changes to an existing query, click Save.
  7. If you want to view the execution plan for the query, click Explain. For more information, see http://wiki.apache.org/hadoop/Hive/LanguageManual/Explain.
  8. To run the query, click Execute.The Beeswax Query Results window appears with the results of your query.
    images/image7.jpeg
  9. Do any of the following to download or save the query results:
    • Click Download XLS to download the results in a Microsoft Office Excel worksheet file.
    • Click Download CSV to download the results in a comma-separated values file suitable for use in other applications.
    • Click Save. To save the results in a new table, select In a new table, enter a name, and then click Save. To save the results in an HDFS file, select In an HDFS directory, enter a path or Choose File and browse to the directory, and then click Save.
  10. To view a log of the query execution, click Log. You can use the information in this tab to debug your query.
  11. Under MR Jobs, you can view any Map/Reduce jobs that the query started.
  12. To return to the query in the Query Editor, click Unsaved Query or the name of your saved query in the blue box at the top of the panel on the left side of the Beeswax window.

Viewing Query History

Beeswax enables you to view the history of queries that you have previously run. Results for these queries are available for one week or until Hue is restarted.
To view query history:
  1. In the Beeswax window, click History.Beeswax displays a list of your unsaved and saved queries in the Beeswax Query History window.
    images/image8.jpeg
  2. To display the queries for all users, click everyone's. To display your queries only, click mine.
  3. To display the automatically generated actions that Beeswax performed on a user's behalf, click auto actions. To display user queries again, click user queries.

Viewing, Editing, or Deleting Saved Queries

You can view a list of saved queries by clicking Saved Queries in the Beeswax window.If Beeswax is configured for shared queries (the default), you can view the queries from any user, and copy any user's query, but you can only edit, delete, and view the history of your own queries. If sharing is disabled, then you can only view and copy your own queries. 
images/image9.jpeg
To edit a saved query:
  1. In the Beeswax window, click Saved Queries.Beeswax displays the Beeswax Queries window.
  2. Right-click one of your queries and choose Edit from the context menu.
    images/image10.jpeg
    Beeswax displays the query in the Beeswax Query Editor window.
  3. Change the query and then click Save. You can also click Save As, enter a new name, and click OK to save a copy of the query.
To delete a saved query:
  1. In the Beeswax window, click Saved Queries.Beeswax displays the Beeswax Queries window.
  2. Right-click any of your own queries and choose Delete from the context menu.
  3. Click Ok to confirm the deletion.
To copy a saved query:
  1. In the Beeswax window, click Saved Queries.Beeswax displays the Beeswax Queries window.
  2. Right-click any of the queries and choose Clone from the context menu.Beeswax displays the query in the Beeswax Query Editor window.
  3. Change the query as necessary and then click Save. You can also click Save As, enter a new name, and click Ok to save a copy of the query.
To copy a query in the Beeswax Query History window:
  1. In the Beeswax window, click History.Beeswax displays the Beeswax Query History window.
  2. To display the queries for all users, click everyone's.Beeswax displays the queries for all users in the Beeswax Query History window.
    images/image11.jpeg
  3. Click the Clone link next to the query you want to copy.Beeswax displays a copy of the query in the Beeswax Query Editor window.
  4. Change the query, if necessary, and then click Save As, enter a new name, and click OK to save the query.

Working with Tables

When working with Hive tables, you can use Beeswax to:
  • Create tables 
  • Browse tables
  • Import data into tables 
  • Drop tables 
  • View the location of a table 

Creating Tables

Although you can create tables by executing the appropriate HQL DDL query commands, it is easier to create a table using the Beeswax table creation wizard.
To create a table:
  1. In the Beeswax window, click Tables.
    images/image12.jpeg
  2. In the Beeswax Table List window, click new table.The table creation wizard starts.
    images/image13.jpeg
  3. Follow the instructions in the wizard to create the table. For information about an option in the wizard, place your mouse cursor on the help icon 
    images/image14.jpeg
    next to the option.After you click Submit Query at the end of the table creation wizard, a new query to create the table is displayed in the Query Editor window.
    images/image15.jpeg
  4. Click Execute to run the query and create the table.Beeswax displays the new table's metadata on the right side of the Beeswax Table Metadata window.
    images/image16.jpeg

Browsing Tables

To browse the data in a table:
  1. In the Beeswax Table List window, click Tables.
  2. Click the Browse Data link next to the table you want to browse.
    images/image17.jpeg
    Beeswax displays the table's data in the Query Results window.
    images/image18.jpeg
To browse the metadata in a table:
  1. In the Beeswax Table List window, click Tables.
  2. Double-click the table.Beeswax displays the table's metadata on the right side of the Beeswax Table Metadata window.

Importing Data into Tables

When importing data, you can choose to append or overwrite the table's data with data from a file.
To import data into a table:
  1. In the Beeswax Table List window, click Tables.
  2. Double-click the table.Beeswax displays the Beeswax Table Metadata window.
  3. Click Import Data.
  4. Select Overwrite existing data to replace the data in the selected table with the imported data.
  5. For Path, enter the path to the file that contains the data you want to import, or click Choose File to browse to the file.
  6. Click Submit to start importing the data.

Dropping Tables

To drop a table:
  1. In the Beeswax Table List window, click Tables.
  2. Double-click the table.Beeswax displays the Beeswax Table Metadata window.
  3. Click Drop Table.
  4. Click Ok to confirm the deletion.

Viewing a Table's Location

To view a table's location:
  1. In the Beeswax Table List window, click Tables.
  2. Double-click the table.Beeswax displays the Beeswax Table Metadata window.
  3. Click View File Location.Beeswax lists the selected table in its directory in the File Browser window.