• hive之managed table创建


    Welcome to the world of Hive-0.10.0, now we will use Managed Tables:

    1. hive> create database if not exists dataprocess

               >  comment 'analyze cluster data'

               >  location '/home/landen/UntarFile/hive-0.10.0/user/hive/warehouse';

    Notice: you can optionally specify a location for the table data(as opposed to metadata, which the metastore will always hold). By default, hive always creates the table's directory under the directory for the enclosing database. The exception is the default database. It doesn't have a directory under /user/hive/warehouse(unless explicitly overridden).

    2. hive> describe database financials;

        financials   analyze cluster data 

        hdfs://localhost:9000/home/landen/UntarFile/hive-0.10.0/user/hive/warehouse/dataprocess.db

    3. hive> use dataprocess;

        and you can set a property to print the current database as part of the prompt

        hive> set hive.cli.print.current.db=true;

       hive(dataprocess)> ......

    4. hive> drop database if exists dataprocess;

        Notice: By default, Hive won't permit you to drop a database if it contains tables. You can either drop the tables first or append the 'CASCADE' keyword to the command.

        hive> drop database if exists dataprocess CASCADE;

    Using the 'RESTRICT' keyword instead of CASCADE is equivalent to the default behavior, where a database is dropped, it's directory is also deleted.

    5. hive> alter database dataprocess

               > set dbproperties('edited-by' = 'kevin');

    Now let's create a emplyees in the database of human_resources:

    6. hive> use human_resources;

        hive> set hive.cli.print.current.db=true;

        hive(human_resources)> create table if not exists employees(

                                               > name string comment 'employee name',

                                               > number string comment 'employee work number')

                                               > comment 'describe the employee table'

                                               > tblproperies('creator'='landen', 'created_at'='2013-03-25 20:02');

        hive(human_resources)>  show tblproperties employees;

    Notice: you can also copy the schema(but the data) of an existing table:

    7. hive> create table if not exists mydb.employees

               >  like employees;

    8. hive> use default;

        hive> show tables in mydb;

    employees

    9. hive> use mydb;

        hive> show tables 'empl.*';

    Notice: if you only want to see the schema for a particular column, append the column to the table name,such as

    10.  hive> describe mydb.employees.name

    name string Employee name

          Now the tables we have created so far are called managed tables or sometimes called internal tables, because Hive controls the lifecycle of their data(more or less). As we've seen, Hive stores the data for these tables in a subdirectory under the directory defined by hive.metastore.warehouse.dir by default.

          However, managed tables are less convinent for sharing with other tools. For example, suppose we have data that is created and used primarily by Pig or other tools, but we want to run some quries against it, but not give Hive ownership of the data. So we can define an external table that points to that data, but doesn't take ownership of it.

      

  • 相关阅读:
    html基础教程2
    HTML的基础教程
    JS中响应函数和for循环执行问题
    Cookie显示上次访问时间出现错误的问题
    完全卸载VSCode--解决卸载重新安装后还有原来配置的问题
    servlet中输出HTML标签浏览器不能正常显示
    Java中Servlet输出中文乱码问题
    eclipse下配置Tomcat(没有Tomcat8及以上版本问题)
    Java多线程通信之wait()和notify()方法
    Java中synchronize关键字
  • 原文地址:https://www.cnblogs.com/likai198981/p/2981579.html
Copyright © 2020-2023  润新知