代码之家  ›  专栏  ›  技术社区  ›  Learn Hadoop

配置单元-SQL插入记录

  •  -1
  • Learn Hadoop  · 技术社区  · 6 年前

    在HIVE SQL中,我在两个不同的cloudera版本中运行了相同的查询。Cloudera VM 5.10未导致任何问题。但另一个版本cloudera-CDH-5.1.0-1。cdh5.1.0。p0.53为投掷误差。

    hive> select * from t;
    OK
    Time taken: 1.803 seconds
    hive> insert into table t values (1);
    NoViableAltException(26@[])
            at org.apache.hadoop.hive.ql.parse.HiveParser_SelectClauseParser.selectClause(HiveParser_SelectClauseParser.java:713)
            at org.apache.hadoop.hive.ql.parse.HiveParser.selectClause(HiveParser.java:35992)
            at org.apache.hadoop.hive.ql.parse.HiveParser.regular_body(HiveParser.java:33510)
            at org.apache.hadoop.hive.ql.parse.HiveParser.queryStatement(HiveParser.java:33389)
            at org.apache.hadoop.hive.ql.parse.HiveParser.queryStatementExpression(HiveParser.java:33169)
            at org.apache.hadoop.hive.ql.parse.HiveParser.execStatement(HiveParser.java:1284)
            at org.apache.hadoop.hive.ql.parse.HiveParser.statement(HiveParser.java:983)
            at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:190)
            at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:434)
            at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:352)
            at org.apache.hadoop.hive.ql.Driver.compileInternal(Driver.java:995)
            at org.apache.hadoop.hive.ql.Driver.runInternal(Driver.java:1038)
            at org.apache.hadoop.hive.ql.Driver.run(Driver.java:931)
            at org.apache.hadoop.hive.ql.Driver.run(Driver.java:921)
            at org.apache.hadoop.hive.cli.CliDriver.processLocalCmd(CliDriver.java:268)
            at org.apache.hadoop.hive.cli.CliDriver.processCmd(CliDriver.java:220)
            at org.apache.hadoop.hive.cli.CliDriver.processLine(CliDriver.java:422)
            at org.apache.hadoop.hive.cli.CliDriver.executeDriver(CliDriver.java:790)
            at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:684)
            at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:623)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            at java.lang.reflect.Method.invoke(Method.java:606)
            at org.apache.hadoop.util.RunJar.main(RunJar.java:212)
    FAILED: ParseException line 1:20 cannot recognize input near 'values' '(' '1' in select clause
    hive>
    

    有什么想法吗?我必须选择哪个版本来学习。请告知。

    3 回复  |  直到 6 年前
        1
  •  1
  •   notNull    6 年前

    在旧版本的CDH(如CDH-5.1)中,不支持插入记录,但在新版本的CDH中,它是受支持的功能。 因此,与其尝试插入值,不如尝试使用Load data语句

    如果您的文件是本地文件,则

    hive> LOAD DATA LOCAL INPATH '<local-path-tofile>' INTO TABLE t;
    

    如果文件在HDFS中,则

    hive> LOAD DATA INPATH 'hdfs_file_or_directory_path'  INTO TABLE t;
    

    有关更多详细信息,请参阅:- https://cwiki.apache.org/confluence/display/Hive/GettingStarted#GettingStarted-DMLOperations

        2
  •  0
  •   roh    6 年前

    您所尝试的是正确的,请确保表中有一列。如果有多个列,则需要所有字段的值。签出下图 enter image description here

    我尝试的版本:

    [cloudera@quickstart ~]$ hadoop version
    Hadoop 2.6.0-cdh5.5.0
    Subversion http://github.com/cloudera/hadoop -r fd21232cef7b8c1f536965897ce20f50b83ee7b2
    Compiled by jenkins on 2015-11-09T20:37Z
    Compiled with protoc 2.5.0
    From source with checksum 98e07176d1787150a6a9c087627562c
    This command was run using /usr/jars/hadoop-common-2.6.0-cdh5.5.0.jar
    
        3
  •  0
  •   Learn Hadoop    6 年前

    @roh公司

     hive> describe formatted t;
        OK
        # col_name              data_type               comment
        id                      int                     None
        # Detailed Table Information
        Database:               default
        Owner:                  learnhadoop
        CreateTime:             Fri Feb 23 21:25:15 IST 2018
        LastAccessTime:         UNKNOWN
        Protect Mode:           None
        Retention:              0
        Location:               hdfs://hadoopmasters:8020/user/hive/warehouse/t
        Table Type:             MANAGED_TABLE
        Table Parameters:
                transient_lastDdlTime   1519401315\
        # Storage Information
        SerDe Library:          org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
        InputFormat:            org.apache.hadoop.mapred.TextInputFormat
        OutputFormat:           org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputForm                                                                             at
        Compressed:             No
        Num Buckets:            -1
        Bucket Columns:         []
        Sort Columns:           []
        Storage Desc Params:
                serialization.format    1
        Time taken: 0.111 seconds, Fetched: 26 row(s)
        hive>