Chiriri's blog Chiriri's blog
首页
  • Java

    • JavaSE
    • JavaEE
    • 设计模式
  • Python

    • Python
    • Python模块
    • 机器学习
  • Golang

    • Golang
    • gRPC
  • 服务器

    • Linux
    • MySQL
    • NoSQL
    • Kubernetes
  • 项目

    • 传智健康
    • 畅购商城
  • Hadoop生态

    • Hadoop
    • Zookeeper
    • Hive
    • Flume
    • Kafka
    • Azkaban
    • Hbase
    • Scala
    • Spark
    • Flink
  • 大数据项目

    • 离线数仓
  • 青训营

    • 第四届青训营
  • HTML

    • HTML
    • JavaScript
  • Vue

    • Vue2
    • TypeScript
    • Vue3
    • Uni-APP
  • 数据结构与算法
  • C语言
  • 考研数据结构
  • 计算机组成原理
  • 计算机操作系统
  • Java基础

    • Java基础
    • Java集合
    • JUC
    • JVM
  • 框架

    • Spring
    • Dubbo
    • Spring Cloud
  • 数据库

    • MySQL
    • Redis
    • Elasticesearch
  • 消息队列

    • RabbitMQ
    • RocketMQ
  • 408

    • 计算机网络
    • 操作系统
    • 算法
  • 分类
  • 标签
  • 归档
  • 导航站
GitHub (opens new window)

Iekr

苦逼后端开发
首页
  • Java

    • JavaSE
    • JavaEE
    • 设计模式
  • Python

    • Python
    • Python模块
    • 机器学习
  • Golang

    • Golang
    • gRPC
  • 服务器

    • Linux
    • MySQL
    • NoSQL
    • Kubernetes
  • 项目

    • 传智健康
    • 畅购商城
  • Hadoop生态

    • Hadoop
    • Zookeeper
    • Hive
    • Flume
    • Kafka
    • Azkaban
    • Hbase
    • Scala
    • Spark
    • Flink
  • 大数据项目

    • 离线数仓
  • 青训营

    • 第四届青训营
  • HTML

    • HTML
    • JavaScript
  • Vue

    • Vue2
    • TypeScript
    • Vue3
    • Uni-APP
  • 数据结构与算法
  • C语言
  • 考研数据结构
  • 计算机组成原理
  • 计算机操作系统
  • Java基础

    • Java基础
    • Java集合
    • JUC
    • JVM
  • 框架

    • Spring
    • Dubbo
    • Spring Cloud
  • 数据库

    • MySQL
    • Redis
    • Elasticesearch
  • 消息队列

    • RabbitMQ
    • RocketMQ
  • 408

    • 计算机网络
    • 操作系统
    • 算法
  • 分类
  • 标签
  • 归档
  • 导航站
GitHub (opens new window)
  • Hadoop

  • Zookeeper

  • Hive

    • 介绍
    • 环境
    • DBeaver
    • Hive 类型
    • Hive 客户端命令
    • DDL数据定义
    • DML
      • 数据导入
      • 数据导出
        • Insert导出
        • Hive Shell 命令导出
        • Export导出到HDFS上
        • Import数据导入到hive表中
      • 数据删除
    • 查询
    • 函数
    • 自定义函数
    • 压缩和存储
    • 企业优化
    • Hive实战merge
  • Flume

  • Kafka

  • Azkaban

  • Hbase

  • Scala

  • Spark

  • Flink

  • 离线数仓

  • 青训营

  • DolphinScheduler

  • Doris

  • 大数据
  • Hive
Iekr
2021-10-19
目录

DML

# DML

# 数据导入

load data [local] inpath '/opt/module/datas/student.txt' [overwrite] into table student [partition (partcol1=val1,…)];
1
  1. load data: 表示加载数据
  2. local: 表示从本地加载数据到 hive 表;否则从 HDFS 加载数据到 hive 表
  3. inpath: 表示加载数据的路径
  4. overwrite: 表示覆盖表中已有数据,否则表示追加
  5. into table: 表示加载到哪张表
  6. student: 表示具体的表
  7. partition: 表示上传到指定分区
load data local inpath "/opt/module/datas/student.txt" into table stu_par; -- 从宿机加载数据
load data local inpath "/opt/module/datas/student.txt" overwrite into table stu_par; -- 覆盖导入
load data inpath "/opt/module/datas/student.txt" overwrite into table stu_par; -- 从hdfs中加载指定路径文件  HDFS的导入是移动文件,而本地导入是复制上传
1
2
3
  • insert 导入
insert into table  stu_par partition(month='201709') values(1,'wangwu') -- 插入单条 一个括号对应一条
insert into table  stu_par partition(month='201709') values(1,'wangwu'),(2,'zhaoliu'); -- 插入多条指定数据 多行数据用逗号隔开并用括号包裹 要类型一致
insert into table  stu_par select id,name from stu_par2 where class="01";  -- 插入查询后的数据
1
2
3
  • 建表时 as select 导入
create table if not exists student3
as select id, name from student;
1
2
  • 建表时通过 location 加载
create external table if not exists student4
(id int, name string)
row format delimited fields terminated by '\t'
location '/student';
1
2
3
4

# 数据导出

# Insert 导出

  • 将查询的结果导出到本地 默认不带格式
insert overwrite local directory '/opt/module/datas/export/student' select * from student;
1
  • 将查询的结果格式化导出到本地
insert overwrite local directory '/opt/module/datas/export/student1' ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' select * from student;
1

# Hive Shell 命令导出

用 shell 命令查询表并写出本地

如果不指定库 默认为 default 库

hive -e 'select * from default.student;' > /opt/module/datas/export/student4.txt;
1

# Export 导出到 HDFS 上

将表导出到 HDFS 上 元数据和表数据文件

export table default.student to '/user/hive/warehouse/export/student';
1

# Import 数据导入到 hive 表中

要先用 export 导出到 hdfs 中 必须包含元数据和表数据

import table student from '/export/student'; 
1

# 数据删除

清空表 只删除表数据 不删除表本身 Truncate 只能删除管理表,不能删除外部表中数据

truncate table student;
1
编辑 (opens new window)
上次更新: 2023/12/06, 01:31:48
DDL数据定义
查询

← DDL数据定义 查询→

最近更新
01
k8s
06-06
02
进程与线程
03-04
03
计算机操作系统概述
02-26
更多文章>
Theme by Vdoing | Copyright © 2022-2025 Iekr | Blog
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式