10 工作中常见知识汇总

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xfg0218/article/details/86473788

10 工作中常见知识汇总

10.1在使用外表时注意的问题

10.1.1 注意\线的转义问题

10.1.1.1 问题示例

 

在以上的结果中可以看出GP把\给转义了

10.1.1.2 解答方法

drop external table if exists  main.t_ent_baseinfo_external_20181214;

create external table  main.t_ent_baseinfo_external_20181214(

*******

)

LOCATION ('gphdfs://nameservice1/tmp/chinadaas-oracle-gp/batchDate/t-ent-baseinfo/*') format 'text' (delimiter E'\u0001' NULL as 'null string'  ESCAPE as 'OFF' FILL MISSING FIELDS)

LOG ERRORS SEGMENT REJECT LIMIT 8000 ROWS;

 

使用ESCAPE as 'OFF' 即可关闭转义,默认的是打开的

 

详细信息请查看:https://gpdb.docs.pivotal.io/5140/ref_guide/sql_commands/COPY.html

 

10.1.2 \1转特殊字符的问题

10.1.2.1 问题示例

以下是HDFS上展示的效果

13529225049\18088249

 

以下是GP中显示的效果

select tel from main.t_ent_baseinfo_xiaoxu_20181129 where s_ext_sequence='1949100100000041387873';

 

原因是GP加载外表时没有进行转义特殊字符,导致GP中把\1转换成\U001即为16进制的SOH 特殊字符

10.1.2.2 解答方法

drop external table if exists  main.t_ent_baseinfo_external_20181214;

create external table  main.t_ent_baseinfo_external_20181214(

*******

)

LOCATION ('gphdfs://nameservice1/tmp/chinadaas-oracle-gp/batchDate/t-ent-baseinfo/*') format 'text' (delimiter E'\u0001' NULL as 'null string'  ESCAPE as 'OFF' FILL MISSING FIELDS)

LOG ERRORS SEGMENT REJECT LIMIT 8000 ROWS;

 

使用ESCAPE as 'OFF' 即可关闭转义,默认的是打开的

 

详细信息请查看:https://gpdb.docs.pivotal.io/5140/ref_guide/sql_commands/COPY.html

 

10.2 COPY命令常见错误汇总

10.2.1数据中有双引字符

10.2.1.1 问题示例

$ psql -d chinadaas  -h 192.168.209.11 -p 5432 -U gpadmin -c "COPY main.t_ent_casebaseinfo_internal_20181214  FROM '/home/xiaoxu/hdfs-to-greenplum/error-data/t_ent_casebaseinfo_internal_error_20181214.csv' WITH csv DELIMITER E'\001'";

ERROR:  unterminated CSV quoted field  (seg1 192.168.209.12:40001 pid=336648)

 

在以上可以看出数据中有双引号导致了不能正确的入库

10.2.1.2 解答方法

解决方式使用sed命令替换掉即可:#  sed  -i ‘s/”//g’ filename  或手动去掉即可

 

10.3 查看字段中有特殊字符SQL

10.3.1 先把表字段获取出来

select col.column_name from information_schema.columns col where col.table_schema='schemaName' and col.table_name ='tableName' order by col.ordinal_position

 

schemaName : schema的名字

tableName: 表的名字

10.3.2 查询表中的错误数据

select filedname from schemaname.tablename where filedname~'[\u0000-\u001f]';

 

filedname:字段的名字

schemaName : schema的名字

tableName: 表的名字

[\u0000-\u001f] : 是匹配的隐藏特殊字符,详情请查看:

https://blog.csdn.net/xfg0218/article/details/80901752

10.3.3 注意分布键的问题

10.3.3.1 现象说明

在下图可以看出在使用分布键是直接写成by就会把字段进行了起别名,现象如下

10.3.3.2 现象解答说明

此现象说明:https://github.com/greenplum-db/gpdb/issues/6539

猜你喜欢

转载自blog.csdn.net/xfg0218/article/details/86473788