zoukankan      html  css  js  c++  java
  • hive之external table创建

    External Tables

         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.

        Suppose we are analyzing data from the stock markets. Periodically, we ingest the data for NASDAQ and the NYSE from a source like Infochimps(http://infochimps.com/datasets).

        Now the following table declaration creates an external table that can read all the data files for this comma-delimited data in /data/stocks:

    hive(Economy)> create external table if not exists stocks(

                          > exchange string, symbol string, ymd string, price_open float, price_high float, price_low float,

                          > price_close float, volume int, price_adj_close float)

                          > row format delimited fields terminated by ','

                          > location '/data/stocks';

         Because it's external, Hive doesn't assume it owns the data. Therefore, dropping the table doesn't delete the data, although the metadata for the table will be deleted.(sometimes permit denied);

        In addtion, you can judge the table type between managed and external table using the output of 'hive>describe extended tablename'.

        As for managed tables, you can also copy the schema(but the data) of an existign table:

        hive> create external table if not  exists Economy1

              > like Economy

              > location '/data/stocks/path';

        What's more, if you omit the 'external' keyword and the original table is external, the new table will also be external; if you omit 'external' and the original table is managed, the new table will also be managed. However, if you include the external keyword and the original table is managed, the new table will be external.

  • 相关阅读:
    leetcode(85)最大矩形
    红黑树
    查询学生成绩表中大于60分的每一个成绩的人数
    聚合函数以及SQL中的一些小知识
    Oracle的JDBC
    StringBuffer的reverse方法
    查询时报第一页没有数据,第二页有数据的异常
    普通人如何从平庸到优秀,在到卓越
    HDMI、DVI、VGA等这些接口
    显卡上的VGA接口和高清接口有什么区别?
  • 原文地址:https://www.cnblogs.com/likai198981/p/2982427.html
Copyright © 2011-2022 走看看