GP中外部表例子

来源:互联网 发布:酷骑单车网络连接失败 编辑:程序博客网 时间:2024/05/16 23:49
创建外部表注意事项:
同一台机器上的外部表对应的gpfdist端口号尽量错开,从8081-8088
gpfdist -p 8081 -d /ftp2/interface/data/GPload_home


创建可写外部表:
Greenplum也支持对外部表的写操作。这需要在创建表的时候指定写关键字:
CREATE WRITABLE EXTERNAL TABLE weblogs
( md5 text,
  url text,
  request_date date,
  request_time time,
  ip int
  ) 
LOCATION ('gphdfs://hdfs_host[:port]/path/filename.txt')
FORMAT 'custom' (formatter= 'delimiter_ou_any' ,hex_entry_delim ='80' ,fix_flag= 'FALSE' ,line_delim= '
' ,null= '' ,encoding= 'gbk' )
ENCODING 'UTF8';


--删除可写外部表(不加WRITABLE ):
drop EXTERNAL TABLE a;


创建只读外部表:
-- External Table: tdw_12580_busslist_d
-- DROP EXTERNAL TABLE tdw_12580_busslist_d;
CREATE EXTERNAL TABLE tdw_12580_busslist_d
(
  statis_date numeric(8,0),
  row_number numeric(20,0),
  call_id character varying(25),
  cust_type character varying(12)
)
 LOCATION (
    'gpfdist://10.255.235.39:8081/day/tdw_12580_busslist_d.gpload'
)
FORMAT 'custom' (formatter= 'delimiter_in' ,hex_entry_delim ='80' ,fix_flag= 'FALSE' ,line_delim= '
' ,null= '' ,encoding= 'gbk' )
ENCODING 'UTF8';
ALTER TABLE tdw_12580_busslist_d OWNER TO gpmon;
--注意:若报编码错误,可以考虑将外层的ENCODING 'UTF8'改为ENCODING 'GBK';
1:Formats are restricted, as follows:
 - TEXT format is allowed for readable and writable external tables.
 - Only the gphdfs_import formatter is allowed for readable external tables with a custom format.
   custom格式的可读外部表只能是 gphdfs_import formatter 
 - Only the gphdfs_export formatter is allowed for writable external tables with a custom format.
   custom格式的可写外部表只能是 gphdfs_export formatter 
Compression is only applicable for writable external tables. Compression settings are determined automatically
 for readable external tables and cannot be set.
只有可写的外部表才可以进行压缩设置;对于可读外部表,压缩是自动设置的,不能人为设置。
2:-- delimiter must be a single ASCII character, or 'off'
    分隔符必须为单字节的符号,可以使用的分隔符:text csv custom


修改外部表的表结构:
alter external TABLE dw.exter_tb_det_music_serv_info_tab_d alter column author type character varying(90);

alter external table dc.exter_tkr_tool_game_rk3_m alter up_rate type numeric(20,6);





0 0
原创粉丝点击