Hive and HBase

Source: Internet
Author: User

Hive: Suitable for analytical statistics;

HBase: Used for real-time queries.

The application of hive is equivalent to MySQL:

Switch to the current database: Hive:use;

Create DATABASE command: hive:create databases financials;

When you delete a database, you are not allowed to delete data in the database, and if you have data, you will get an error. This can be deleted with the command with the Cascade keyword added;

Hive:drop database DatabaseName Cascade;

Or: Drop database if exists databasename cascade;

View tables in the current database: hive:show tables in DatabaseName;

Or: hive:show tables like ' h* ';

View all the databases.

hive> show databases;

hive> describe databases DbName; --View database information

TRUNCATE TABLE table_a; Emptying data for a table (hive 0.11.0 support)

? Modifying DB-related information with the ALTER keyword

hive> ALTER DATABASE Financials SET dbproperties (' edited-by ' = ' Joe Dba ');

First, Hive has an internal table, and the External Table external table is the concept of two tables. Internal tables are tables created through hive itself and are managed by the hive itself.

The external table, metadata, provides some data query services, such as some HDFS files, which can be batched and queried through hive, by using hive to create a table.

Use the external table to create EXTERNAL table, increase the EXTERNAL keyword, and specify the location of the data for the external table through the Site keyword.

The internal table specifies the location of the table that is stored in HDFs when it is used.

When you use the Delete Table command, the data for the internal table is deleted along with the table structure, and the external table only removes the table structure.

Unlike RDBMS, Hive supports a variety of data types, often string,bigint,double

Date types are also stored using string.

In addition, hive supports a variety of structures, such as map,array,struct, which are very powerful data types.

CREATE TABLE Choice (userid int,classname string)

Row format delimited fields terminated by ' \ t '

STORED as TEXT FILE

Location '/data/test01/daxingyu930 ';

The STORED as textfile keyword refers to the storage format of the data as a text format, and if the data is compressed, you can use Rcfile or sequence FILE.

You can also insert information from a hive table into a new table, place it on the local file system, or in the HDFs file system.

1. Place the results of the SELECT into one of the tables (create a new table with the creation table first)

Insert Overwrite table test

Select Uid,name from Test2;

2. Place the results of a select on the local file system

INSERT OVERWRITE LOCAL DIRECTORY '/tmp/reg_3 '

SELECT a.* from Events A;

3. Placing the results of a select in the HDFs file system

INSERT OVERWRITE DIRECTORY '/tmp/hdfs_out '

SELECT a.* from invites a WHERE a.ds= ';

Links: http://blog.sina.com.cn/s/blog_72d544900101f1i8.html

Hive and HBase

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.