Hive ParseException - cannot recognize input near 'end' 'string'

后端 未结 4 1200
终归单人心
终归单人心 2021-02-14 02:41

I am getting the following error when trying to create a Hive table from an existing DynamoDB table:

NoViableAltException(88@[])
at org.apache.hadoop.hive.ql.par         


        
相关标签:
4条回答
  • 2021-02-14 03:29

    The issue isn't actually a syntax error, the Hive ParseException is just caused by a reserved keyword in Hive (in this case, end).

    The solution: use backticks around the offending column name:

    CREATE EXTERNAL TABLE moveProjects (cid string, `end` string, category string)
    STORED BY 'org.apache.hadoop.hive.dynamodb.DynamoDBStorageHandler'
    TBLPROPERTIES ("dynamodb.table.name" = "Projects",
        "dynamodb.column.mapping" = "cid:cid,end:end,category:category");
    

    With the added backticks around end, the query works as expected.

    Reserved words in Amazon Hive (as of February 2013):

    IF, HAVING, WHERE, SELECT, UNIQUEJOIN, JOIN, ON, TRANSFORM, MAP, REDUCE, TABLESAMPLE, CAST, FUNCTION, EXTENDED, CASE, WHEN, THEN, ELSE, END, DATABASE, CROSS

    Source: This Hive ticket from the Facebook Phabricator tracker

    0 讨论(0)
  • 2021-02-14 03:32

    You can always escape the reserved keyword if you still want to make your query work!!

    Just replace end with `end`

    Here is the list of reserved keywords https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL

    CREATE EXTERNAL TABLE moveProjects (cid string, `end` string, category string)
    STORED BY 'org.apache.hadoop.hive.dynamodb.DynamoDBStorageHandler'
    TBLPROPERTIES ("dynamodb.table.name" = "Projects",
        "dynamodb.column.mapping" = "cid:cid,end:end,category:category");
    
    0 讨论(0)
  • 2021-02-14 03:34

    I was using /Date=20161003 in the folder path while doing an insert overwrite and it was failing. I changed it to /Dt=20161003 and it worked

    0 讨论(0)
  • 2021-02-14 03:35

    I solved this issue by doing like that:

    insert into my_table(my_field_0, ..., my_field_n) values(my_value_0, ..., my_value_n)

    0 讨论(0)
提交回复
热议问题