h3c配置snmp配置命令_配置单元命令

h3c配置snmp配置命令

In this lesson on Apache Hive commands, we will go through the most common commands in Hive in HQL and perform most basic operations like creating tables, altering their schema and much more.

在关于Apache Hive命令的这一课中,我们将介绍HQL中Hive中最常见的命令,并执行最基本的操作,例如创建表,更改其模式等。

In this guide, we will make use of Ubuntu 17.10 (GNU/Linux 4.13.0-37-generic x86_64) machine:

在本指南中,我们将使用Ubuntu 17.10(GNU / Linux 4.13.0-37-generic x86_64)计算机:

hive commands ubuntu version

Ubuntu Version

Ubuntu版本

运行Hive命令的先决条件 (Prerequisites for running Hive Commands)

Before we can proceed to run Hive queries on our machine, we need to have some other things too:

在继续在计算机上运行Hive查询之前,我们还需要做一些其他事情:

Once these things are ready, continue with the lesson to learn about running hive commands.

这些准备就绪后,请继续学习本单元,以了解有关运行配置单元命令的信息。

启动Hive外壳 (Launching Hive shell)

With a simple command, you should be able to start the hive shell:

使用简单的命令,您应该能够启动配置单元外壳程序:

hive

The Hive shell will open as:

Hive外壳将打开为:

Launch Hive shell

Launch Hive shell

启动Hive外壳

运行数据库命令 (Running Database commands)

We will start by mainly executing database commands. In a later section, we will move to DDL commands which manages the table schema and data.

我们将从主要执行数据库命令开始。 在下一节中,我们将转到管理表模式和数据的DDL命令。

使用元数据创建和描述数据库 (Creating and Describe Database with metadata)

With Hive, when you create a database, it is easy to assign useful metadata to a database as description, author and much more options. Let’s try some of these options here:

使用Hive,在创建数据库时,可以轻松地将有用的元数据分配给数据库作为描述,作者和更多选项。 让我们在这里尝试其中一些选项:

CREATE DATABASE IF NOT EXISTS journaldev
COMMENT "Study BigData at JournalDev"
LOCATION '/opt/hive/warehouse/jd_db'
with DBPROPERTIES ('createdby'='shubham', 'createdfor'='JournalDev');

Now that the database is created, we can see the metadata information by describing the database:

现在已经创建了数据库,我们可以通过描述数据库来查看元数据信息:

DESCRIBE DATABASE extended journaldev;

Let’s see the output for this command:

让我们看一下该命令的输出:

Describe Metadata for Database

Describe Metadata for Database

描述数据库的元数据

修改数据库 (Altering Database)

The metadata assigned to the database is not permanent. We can change it with simple Alter Database command with the following syntax:

分配给数据库的元数据不是永久的。 我们可以使用以下语法通过简单的Alter Database命令更改它:

ALTER (DATABASE) database_name SET DBPROPERTIES 
(property_name=property_value, ...);

We can also modify the owner of a Hive Database with similar command:

我们还可以使用类似的命令修改Hive数据库的所有者:

ALTER (DATABASE) database_name SET OWNER [USER|ROLE] user_or_role;

Let’s try this here now:

让我们现在在这里尝试:

ALTER DATABASE journaldev
SET OWNER ROLE admin;

Now when we describe the database, we can see that owner data has been changed:

现在,当我们描述数据库时,我们可以看到所有者数据已更改:

Alter Database role

Alter Database role

更改数据库角色


Please note that we are writing Hive commands in capital letters just for easy differentiation. The commands are case insensitive.
请注意,为了易于区分,我们使用大写字母编写Hive命令。 这些命令不区分大小写。

显示所有数据库 (Display all Databases)

Just like SQL, we can all databases which exist in Hive till now:

就像SQL一样,我们可以使用Hive到目前为止存在的所有数据库:

SHOW DATABASES;
Show Databases

Show Databases

显示数据库

使用数据库 (Using a Database)

When we want to run some DDL commands in a particular database, we must select it using the following command:

当我们要在特定数据库中运行某些DDL命令时,必须使用以下命令选择它:

USE journaldev;

Once we use a specific database, only then we can run Table related commands in it.

一旦使用了特定的数据库,就只能在其中运行与Table相关的命令。

Hive DDL命令 (Hive DDL Commands)

Now that we have selected a specific database, we are ready to run Table related commands in the database. Our first example will be to define a schema for our table.

既然我们已经选择了一个特定的数据库,就可以在数据库中运行与Table相关的命令了。 我们的第一个示例将是为表定义模式。

定义表架构 (Defining Table schema)

Let’s start working with Tables in Hive by defining the schema for our first table. Basic syntax looks almost something like SQL here too:

让我们通过定义第一个表的架构开始使用Hive中的表。 基本语法在这里也几乎类似于SQL:

CREATE  TABLE [IF NOT EXISTS] [db_name.]table_name    --
  [(col_name data_type [COMMENT col_comment], ...)]
  [COMMENT table_comment]
  [LOCATION hdfs_path]

Let’s put above syntax to use by defining a new table:

让我们通过定义一个新表来使用上面的语法:

CREATE TABLE IF NOT EXISTS journaldev.lessons (
ID BIGINT COMMENT 'ID for each lesson contributed',
title STRING COMMENT 'title which will be shown to users',
link STRING COMMENT 'link to access the lesson')
COMMENT 'This table stores data related to lessons'
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '|'
LINES TERMINATED BY '\n'
STORED AS TEXTFILE
LOCATION '/opt/hive/warehouse/journaldev.db/lessons';

We will receive an OK response here as well:

我们也会在这里收到OK回应:

Create table hive command

Create table

建立表格


Here, we defined a very simple schema for the Hive Table with metadata with comments and delimiters.
在这里,我们为Hive Table定义了一个非常简单的架构,其中带有带有注释和定界符的元数据。

截断表中的所有数据 (Truncate all Data in Table)

We can easily empty a Hive Table by running a simple truncate command:

我们可以通过运行简单的truncate命令轻松清空Hive表:

TRUNCATE TABLE db_name.table_name;

删除表格 (Delete table)

If we wish to delete an entire table with its data, we can simply delete it:

如果我们希望删除整个表及其数据,则可以简单地将其删除:

DROP TABLE [IF EXISTS] table_name [PURGE];

Note that PURGE is an important option here. If PURGE is used, data cannot be retrieved back as without this option, data of the table will go to the .Trash/current-directory. When this option is used, data will completely deleted.

请注意, PURGE是此处的重要选项。 如果使用PURGE ,则无法检索数据,因为没有此选项,表的数据将进入.Trash/current-directory 。 使用此选项时,数据将被完全删除。

Hive DML命令 (Hive DML Command)

Inserting data into a Hive table is easy as well. We can use the following Insert command:

将数据插入Hive表也很容易。 我们可以使用以下插入命令:

INSERT INTO TABLE journaldev.lessons
VALUES (20353, 'Installing Hive on Ubuntu', 'journaldev.com/20353/install-apache-hive-ubuntu-hql-queries'), (20358, 'Installing Hadoop on Ubuntu', 'journaldev.com/20358/install-hadoop-on-ubuntu');

We can see the data we inserted as:

我们可以看到插入的数据为:

SELECT * FROM journaldev.lessons;

Or we can limit the data to just 1 row:

或者我们可以将数据限制为仅1行:

SELECT * FROM journaldev.lessons LIMIT 1;

结论 (Conclusion)

In this lesson, we learned various Apache Hive commands and ran them on our Ubuntu machine. We saw how similar Hive commands are to SQL and fast as well. Real power of Hive comes in when it is run as a cluster, just like Hadoop.

在本课程中,我们学习了各种Apache Hive命令,并将其在我们的Ubuntu计算机上运行。 我们看到了Hive命令与SQL的相似性以及快速性。 当Hive像Hadoop一样作为群集运行时,它才具有真正的功能。

Read more Big Data posts here.

在此处阅读更多大数据文章。

翻译自: https://www.journaldev.com/20606/hive-commands

h3c配置snmp配置命令

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值