hive中建立外部分区表,外部数据格式是json的如何导入呢?

json格式的数据表不必含有分区字段,只需要在hdfs目录结构中体现出分区就可以了

This is all according to this guide: http://blog.cloudera.com/blog/2012/12/how-to-use-a-serde-in-apache-hive/

 hive> ADD JAR /home/hadoop/hive-serdes-1.0-SNAPSHOT.jar;
Added /home/hadoop/hive-serdes-1.0-SNAPSHOT.jar to class path
Added resource: /home/hadoop/hive-serdes-1.0-SNAPSHOT.jar

In /tmp/new I have a file abc.json

The CREATE EXTERNAL TABLE command runs properly, but it doesn't take in any data:

 hive>
> CREATE EXTERNAL TABLE tweets (
> id BIGINT,
> created_at STRING,
> source STRING,
> favorited BOOLEAN,
> retweeted_status STRUCT<
> text:STRING,
> user:STRUCT<screen_name:STRING,name:STRING>,
> retweet_count:INT>,
> entities STRUCT<
> urls:ARRAY<STRUCT<expanded_url:STRING>>,
> user_mentions:ARRAY<STRUCT<screen_name:STRING,name:STRING>>,
> hashtags:ARRAY<STRUCT<text:STRING>>>,
> text STRING,
> user STRUCT<
> screen_name:STRING,
> name:STRING,
> friends_count:INT,
> followers_count:INT,
> statuses_count:INT,
> verified:BOOLEAN,
> utc_offset:INT,
> time_zone:STRING>,
> in_reply_to_screen_name STRING
> )
> PARTITIONED BY (datehour INT)
> ROW FORMAT SERDE 'com.cloudera.hive.serde.JSONSerDe'
> LOCATION '/tmp/new';
OK
Time taken: 0.142 seconds

注意外部分区表需要手工添加分区

具体步骤

.) Run the create table statement.
.) In the directory /tmp/new/ create a sub directory datehour=<some int value>, and then put your .json file inside this.这里就是说只需要在hdfs上建立目录,目录体现分区信息,将数据放到对应目录,然后直接add partiton就好了
.) Run alter table statement adding this partition to metadata:
alter table tweets add partition(datehour=<some int value>);
.) Now run the select statement.

hive中导入json格式的数据(hive分区表)的更多相关文章

  1. asp.net MVC控制器中返回JSON格式的数据时提示下载

    Asp.net mvc在接收的是JSON格式的数据,但是奇怪的是在IE中提示下载文件,其他浏览器中一切正常,下载后,里面的内容就是在控制器中返回的数据.代码如下: 视图中js代码: $("# ...

  2. 在IE中MVC控制器中返回JSON格式的数据时提示下载

    最近做项目时,视图中用jquery.form.js异步提交表单时,接收的是JSON格式的数据,但是奇怪的是在IE中提示下载文件,其他浏览器中一切正常,下载后,里面的内容就是在控制器中返回的数据.代码如 ...

  3. 解决在IE中返回JSON格式的数据时提示下载的问题

    如题,以ASP.NET MVC为例,解决办法如下: 控制器中: public JsonResult Test() { return Json(json, "text/html"); ...

  4. ssm框架中处理json格式的数据步骤

    1.导架包 <!--处理json--> <dependency> <groupId>com.fasterxml.jackson.core</groupId&g ...

  5. Spring拦截器从Request中获取Json格式的数据

    7 package com.newpp.core.interceptor; 8 9 import java.io.BufferedReader; 10 import java.io.ByteArray ...

  6. hive中创建hive-json格式的表及查询

    在hive中对于json的数据格式,可以使用get_json_object或json_tuple先解析然后查询. 也可以直接在hive中创建json格式的表结构,这样就可以直接查询,实战如下(hive ...

  7. JSON(五)——同步请求中使用JSON格式字符串进行交互(不太常见的用法)

    在同步请求中使用JSON格式进行数据交互的场景并不多,同步请求是浏览器直接与服务器进行数据交互的大多是用jsp的标签jstl和el表达式对请求中的数据进行数据的渲染.我也是在一次开发中要从其它服务器提 ...

  8. JSON(四)——异步请求中前后端使用Json格式的数据进行交互

    json格式的数据广泛应用于异步请求中前后端的数据交互,本文主要介绍几种使用场景和使用方法. 一,json格式字符串 <input type="button" id=&quo ...

  9. Hive中导入Oracle数据错误:Listener refused the connection with the following error: ORA-12505

    问题: 今天往Hive中导入Oracle数据的时候碰到了如下错误:Listener refused the connection with the following error: ORA-12505 ...

随机推荐

  1. ICP 算法步骤

    The Iterative Closest Point (ICP) is an algorithm employed to match two surface representations, suc ...

  2. 发送http请求get方法

    //获取网页html NSURL* url = [NSURL URLWithString:@"http://www.baidu.com"]; NSMutableURLRequest ...

  3. dwz中权限的控制

    很多人不明白用dwz要如何在没有登录的时候跳转到登录页面,没有权限的时候弹出提示. 其实,作者在设计的时候,已经完全考虑到了这些需求. 不管是navTab还是dialog,dwz的页面加载最终都是通过 ...

  4. Codeforces Round #369 (Div. 2) C. Coloring Trees DP

    C. Coloring Trees   ZS the Coder and Chris the Baboon has arrived at Udayland! They walked in the pa ...

  5. LoadRunner 脚本学习 -- 动态储存方式和静态储存方式

    我们在定义变量是,根据定义的位置不同,分为全局变量与局部变量.我出生在一个叫“舞阳”的小县城,在这个县城中也有人名“舞阳”,前一个作用于整个县城,后一个只作用于他个人.那么从变量值的存在生存期角度,又 ...

  6. SoapUI接口测试之JDBC(三)

    JDBC(Java Data Base Connectivity,java数据库连接)是一种用于执行SQL语句的Java API,可以为多种关系数据库提供统一访问,它由一组用java语言编写的类和接口 ...

  7. 关于c中 int, float, double转换中存在的精度损失问题

    先看一段代码实验: #include<limits> #include<iostream> using namespace std; int main() { unsigned ...

  8. Uva10328 dp(递推+高精度)

    题目链接:http://vjudge.net/contest/136499#problem/F 题意:给你一个硬币,抛掷n次,问出现连续至少k个正面向上的情况有多少种. 一个比较好理解的题解:原题中问 ...

  9. 《DSP using MATLAB》示例Example4.10

    上代码: b = [1, 0.4*sqrt(2)]; a = [1, -0.8*sqrt(2), 0.64]; % compute the polynomials coefficients given ...

  10. css随记02布局

    布局 二栏布局 利用absolute, margin .container { position: relative; } nav { position: absolute; left: 0px; w ...