zoukankan      html  css  js  c++  java
  • Hadoop Hive sql 语法详解

    Hive 最适合应用在基于大量不可变数据的批处理作业。

    1. 建表

     CREATE ATBEL [IF NOT EXISTS] table_name

    (col_name data_type)

    CREATE TABLE 创建一个表,如果相同名字的表已经存在,则抛出异常。用IF NOT EXISTS来忽略这个异常。

    如:CRETAE TABLE BCUSTOMER(

    CST_ID Integer,

    CST_NAME STRING

    );

    创建外部表:

    CREATE EXTERNAL TABLE page_view(viewTime INT, userid BIGINT,
         page_url STRING, referrer_url STRING,
         ip STRING COMMENT 'IP Address of the User',
         country STRING COMMENT 'country of origination')
     COMMENT 'This is the staging page view table'
     ROW FORMAT DELIMITED FIELDS TERMINATED BY '54'
     STORED AS TEXTFILE
     LOCATION '<hdfs_location>';

    建分区表

    CREATE TABLE par_table(viewTime INT, userid BIGINT,
         page_url STRING, referrer_url STRING,
         ip STRING COMMENT 'IP Address of the User')
     COMMENT 'This is the page view table'
     PARTITIONED BY(date STRING, pos STRING)
    ROW FORMAT DELIMITED ‘ ’
       FIELDS TERMINATED BY ' '
    STORED AS SEQUENCEFILE;

    建Bucket表

    CREATE TABLE par_table(viewTime INT, userid BIGINT,
         page_url STRING, referrer_url STRING,
         ip STRING COMMENT 'IP Address of the User')
     COMMENT 'This is the page view table'
     PARTITIONED BY(date STRING, pos STRING)
     CLUSTERED BY(userid) SORTED BY(viewTime) INTO 32 BUCKETS
     ROW FORMAT DELIMITED ‘ ’
       FIELDS TERMINATED BY ' '
    STORED AS SEQUENCEFILE;

    创建表并创建索引字段ds

    hive> CREATE TABLE invites (foo INT, bar STRING) PARTITIONED BY (ds STRING);

    复制一个空表 (允许复制现有的表结构,但不复制数据)

    CREATE TABLE empty_key_value_store
    LIKE key_value_store;
     
    显示所有表: SHOW TABLES;
     
    表添加一列/更新列:
    ALTER TABLE BCUSTOMER ADD/REPLACE COLUMNS (new_col INT)
     
    添加一列并增加列字段注释:
    ALTER TABLE BCUSTOMER ADD COLUMNS (new_col INT COMMENT 'a comment')
     
    更改表名:
    ALTER TABLE BCUSTOMER  RENAME TO NEWNAME;
     
    删除表:
    DROP TABLE IF EXISTS IKEA.TEMP_IF_REPORT_CHECK_CHERXU;
     
    删除列:
    ALTER TABLE table_name DROP column_name;
     
    Hive SQL中没有delete 和update功能,可以用OVERWRITE代替
    假如你要删除CST_ID=1的人
    INSERT INTO TABLE BCUSTOMER
    SELECT * FROM BCUSTOMER  WHERE CST_ID !=1
     
     
    HIVE中不支持等值连接
    select * from a,b where a.key=b.key (不可以)
    应该写为:
    select * from a join b on a.key=b.key
  • 相关阅读:
    asp.net发布到IIS中出现错误:处理程序“PageHandlerFactory-Integrated”在其模块列表中有一个错误模块“ManagedPipelineHandler”
    System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes”
    禁止tableview 像上滑动
    IOS 贝塞尔曲线切割圆角
    头像图片裁剪
    iOS 限制TextField输入长度
    根据经纬度反向地理编译出地址信息(如果报错:Error Domain=kCLErrorDomain Code=8 "(null)")
    空白页界面
    NSPhotoLibraryAddUsageDescription解决办法
    IOS字符串截取保留小数点后两位
  • 原文地址:https://www.cnblogs.com/cherxu/p/6879822.html
Copyright © 2011-2022 走看看