//创建数据库
create datebase hive;
//创建表
create table t_emp(
id int,
name string,
age int,
dept_name string,
like array<string>,
tedian map<string,string>
)
row format delimited
fields terminated by ','
collection items terminated by '_'
map keys terminated by ':';

ap: 1,zhangsan,32,xxx,sports_books_travel,sex:man_color:red

导入本地文件
load data local inpath '/root/emp.txt' into table t_emp;

导出表数据到hdfs
export table t_emp to '/home/xx_t_emp.txt';

启动hive服务
启动hive服务之前修改hive-site.xml中的thrift.bind.*为主机名。
./hive --service hiveserver2

java连接hive代码
public static void main(String[] args) throws Exception{
Class.forName("org.apache.hive.jdbc.HiveDriver");
Connection conn = DriverManager.getConnection("jdbc:hive2://192.168.56.101:10000/default","root","");
try {
Statement stat = conn.createStatement();
ResultSet result = stat.executeQuery("select count(*) from t_emp");
if(result.next()){
System.out.println(result.getInt(1));
}
} catch (Exception e) {
e.printStackTrace();
// TODO: handle exception
}finally {
conn.close();
}
}

hive 创建表和导入数据实例的更多相关文章

  1. Hive创建表|数据的导入|数据导出的几种方式

    * Hive创建表的三种方式 1.使用create命令创建一个新表 例如:create table if not exists db_web_data.track_log(字段) partitione ...

  2. GeoMesa,整体架构,创建Schema并导入数据

    GeoMesa,整体架构,创建Schema并导入数据 一.GeoMesa-整体架构 二.GeoMesa-创建Schema并导入数据 2.1 GeoTools Data 模块 2.2 索引管理 2.3 ...

  3. 使用PowerDesigner创建表并导入到数据库

    使用PowerDesigner创建表并导入到数据库 刚刚学习使用PowerDesigner进行数据库的创建,下面我就分享一下如何创建表并导入到数据库. 1.首先到网上下载一下PowerDesigner ...

  4. sql自动创建表并复制数据

    ---------------自动创建表并复制数据sql,需要自己设置主键----------- select * into 新表 from 旧表

  5. PowerDesigner创建表 拷贝创建表语句 SQLSERVER创建数据库 使用查询 创建表 并且添加数据

    PowerDesigner创建表 : 1.双击打开PowerDesigner   2.双击打开Create model 3左键点击Model  types,再点击Physical    Data  m ...

  6. 一起学Hive——创建内部表、外部表、分区表和分桶表及导入数据

    Hive本身并不存储数据,而是将数据存储在Hadoop的HDFS中,表名对应HDFS中的目录/文件.根据数据的不同存储方式,将Hive表分为外部表.内部表.分区表和分桶表四种数据模型.每种数据模型各有 ...

  7. 【HIVE】(1)建表、导入数据、外部表、导出数据

    导入数据 1). 本地 load data local inpath "/root/example/hive/data/dept.txt" into table dept; 2). ...

  8. sqoop:mysql和Hbase/Hive/Hdfs之间相互导入数据

    1.安装sqoop 请参考http://www.cnblogs.com/Richardzhu/p/3322635.html 增加了SQOOP_HOME相关环境变量:source ~/.bashrc  ...

  9. Hbase 学习(十一)使用hive往hbase当中导入数据

    我们可以有很多方式可以把数据导入到hbase当中,比如说用map-reduce,使用TableOutputFormat这个类,但是这种方式不是最优的方式. Bulk的方式直接生成HFiles,写入到文 ...

随机推荐

  1. String类的常见面试题(3)

    1.判断定义为String类型的s1和s2是否相等 String s1 = "abc"; //这个"abc"对象首先会进常量池 String s2 = &quo ...

  2. PHP垃圾回收机制理解

    使用的是"引用计数"方式进行回收.简单地理解的话,就是每个分配的内存区域都有一个计数器,记录有多少个变量指针指向这片内存.当指向该片内存的指针数量为0,那么该片内存区域就可以被回收 ...

  3. foreach循环中为什么不要进行remove/add操作

    先来看一段代码,摘自阿里巴巴的java开发手册 List<String> a = new ArrayList<String>(); a.add("1"); ...

  4. 读Zepto源码之IOS3模块

    IOS3 模块是针对 IOS 的兼容模块,实现了两个常用方法的兼容,这两个方法分别是 trim 和 reduce . 读 Zepto 源码系列文章已经放到了github上,欢迎star: readin ...

  5. Bear and Floodlight 状态压缩DP啊

    Bear and Floodlight Time Limit: 4000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u ...

  6. Crayon 线段树或者树状数组

    Crayon Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) SubmitStatus ...

  7. POJ1083 Moving Tables(模拟)

    The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape is in ...

  8. bzoj3997组合数学(求最长反链的dp)

    组合数学 给出一个网格图,其中某些格子有财宝,每次从左上角出发,只能向下或右走.问至少走多少次才能将财宝捡完.此对此问题变形,假设每个格子中有好多财宝,而每一次经过一个格子至多只能捡走一块财宝,至少走 ...

  9. 利用ASP.netCore自带DI(DependencyInjection)实现批量依赖注入

    ASP.net Core自带DI(依赖注入),用法如下: services.AddScoped(typeof(IProductService), typeof(ProductService)); 如果 ...

  10. 命令行参数处理-getopt()和getopt_long()

    在实际编程当中,自己编写代码处理命令行参数是比较麻烦且易出错的.一般我们会直接使用getopt()和getopt_long()函数,下文将介绍具体的使用方法. getopt() getopt()用于处 ...