将数据添加到Hive外部表中

时间:2014-10-02 15:45:00

标签: hadoop hive amazon amazon-kinesis

我正在关注Amazon EMR上从Amazon Kinesis到Hive的流数据教程。我成功地使用Hive内部表执行此操作,但是当我尝试使用外部表时,我遇到了一个奇怪的EOF错误。我之前没有使用过STORED BY和STORED AS,我认为这可能是个问题。我使用IBM指南(http://www-01.ibm.com/support/knowledgecenter/SSPT3X_2.1.1/com.ibm.swg.im.infosphere.biginsights.bigsql.doc/doc/bsql_create_table.html)来验证它们是否可以一起使用。

以下是我用来构建hive外部表的代码。

DROP TABLE apachelog;

CREATE EXTERNAL TABLE apachelog (
  host STRING,
  IDENTITY STRING,
  USER STRING,
  TIME STRING,
  request STRING,
  STATUS STRING,
  SIZE STRING,
  referrer STRING,
  agent STRING
)
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.RegexSerDe'
WITH SERDEPROPERTIES (
  "input.regex" = "([^ ]*) ([^ ]*) ([^ ]*) (-|\\[[^\\]]*\\]) ([^ \"]*|\"[^\"]*\") ([0-9]*) ([0-9]*) ([^ \"]*|\"[^\"]*\") ([^ \"]*|\"[^\"]*\")"
)
STORED AS TEXTFILE
STORED BY
'com.amazon.emr.kinesis.hive.KinesisStorageHandler'
TBLPROPERTIES("kinesis.stream.name"="AccessLogStream")
LOCATION 's3://<bucket-name>/AccessLogStreamOP/';

这是错误:

hive> source create_access_log.hql;
OK
Time taken: 0.464 seconds
FAILED: ParseException line 19:0 missing EOF at 'STORED' near 'TEXTFILE'

1 个答案:

答案 0 :(得分:1)

根据Hive LangaugeManual DDL

  [
    [ROW FORMAT row_format] [STORED AS file_format]
    | STORED BY 'storage.handler.class.name' [WITH SERDEPROPERTIES (...)]  
  ]

您可以使用ROW FORMAT或STORED BY子句,WITH SERDEPROPERTIES应该遵循STORED BY