2015-04-17 129 views
1

完全停留在從配置單元外部表中讀取數據。到現在爲止我已經完成了。無法查詢Hive外部表中的日期字段

  1. 我有一個託管表,其日期字段的值爲2014-10-23。
  2. 我創建的外部表來存儲彈性搜索數據像下面

    創建外部表的ext3( run_date日期) 行格式SERDE「org.elasticsearch.hadoop.hive.EsSerDe」 存儲在由「組織。 elasticsearch.hadoop.hive.EsStorageHandler' TBLPROPERTIES('es.resource'='dfs/ext3','es.field.read.empty.as.null'='true','es.nodes'=);

  3. 在外部表格中插入一行以創建彈性搜索索引和映射。

問題1: 我的彈性搜索字段被作爲字符串創建。

  1. 後來我改變了彈性搜索到日期的映射。

    「run_date」:{ 「類型」: 「日期」, 「格式」: 「YYYY-MM-DDZ」, 「索引」: 「not_analyzed」}

  2. 重新插在外部表中的數據。當我查詢彈性搜索它非常好。值顯示爲 '2014年10月23日+ 08:00'

問題2 當我查詢像從EXT3我得到以下錯誤SELECT COUNT(*)外部的表數據。

2015-04-17 18:45:34,254 FATAL [main] org.apache.hadoop.hive.ql.exec.tez.MapRecordProcessor: org.apache.hadoop.hive.ql.metadata.HiveException: Hive Runtime Error while processing row [Error getting row data with exception java.lang.ClassCastException: org.apache.hadoop.hive.serde2.io.TimestampWritable cannot be cast to org.apache.hadoop.hive.serde2.io.DateWritable 
    at org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableDateObjectInspector.getPrimitiveWritableObject(WritableDateObjectInspector.java:38) 
    at org.apache.hadoop.hive.serde2.SerDeUtils.buildJSONString(SerDeUtils.java:259) 
    at org.apache.hadoop.hive.serde2.SerDeUtils.buildJSONString(SerDeUtils.java:349) 
    at org.apache.hadoop.hive.serde2.SerDeUtils.getJSONString(SerDeUtils.java:193) 
    at org.apache.hadoop.hive.serde2.SerDeUtils.getJSONString(SerDeUtils.java:179) 
    at org.apache.hadoop.hive.ql.exec.MapOperator.process(MapOperator.java:545) 

夥計們請幫我這個,整天都浪費了。我有另外一個包含更多數據的外部表,我需要加入這兩個表並創建一個視圖,以便我的統一數據可供分析。

回答

0

我認爲錯誤出線問題的方法:

Error getting row data with exception java.lang.ClassCastException: 
    org.apache.hadoop.hive.serde2.io.TimestampWritable cannot be cast to 
    org.apache.hadoop.hive.serde2.io.DateWritable 

你在你的蜂巢表有date場,但你插入的數據類型timestamp的。

重新創建表(或一個新的,如果你不想更換)

CREATE EXTERNAL TABLE ext3 (run_date timestamp) 
ROW FORMAT SERDE 'org.elasticsearch.hadoop.hive.EsSerDe' 
STORED BY 'org.elasticsearch.hadoop.hive.EsStorageHandler' 
TBLPROPERTIES('es.resource' = 'dfs/ext3', 'es.field.read.empty.as.null' = 'true','es.nodes'=); 
+0

偉大的!有效。但是現在我已經在這張桌子上裝載了大約1900萬條記錄。當我查詢彈性搜索,其偉大的,但如果我在我的蜂巢查詢「選擇計數(*)從ext3」它花了很多時間。將近10分鐘,仍然是0%。任何線索? – Raghu

+0

沒有抱歉。林不知道它與這個錯誤有關。我會建議詢問一個提供所有細節和示例數據的新問題。 – while

+0

@Raghu你沒有加載任何數據,你使用的是EXTERNAL表,Hive將elasticsearch HTTP API封裝爲數據倉庫,它不是數據庫。你可以創建一個普通的Hive表,並將elasticsearch導入到它中,下一個查詢應該更快。 –