首页 > 解决方案 > 红移光谱显示所有行的 NULL 值

问题描述

当我在 Athena 查询编辑器中运行此查询时,它按预期工作。

SELECT * FROM "sampledb"."elb_logs" 限制 10;

elb_logs 表已根据官方教程生成。当我尝试在红移中使用光谱时,我可以看到所有列的所有“NULL”值。我正在使用这些命令创建 athena_schema:

drop schema "athena_schema";

create external schema athena_schema from data catalog 
database 'sampledb' 
iam_role 'arn:aws:iam::94331XXXXXXX:role/RedshiftCopyUnload'
region 'ap-south-1';

系统表的输出:

从 svv_external_tables 中选择 *;

schemaname  tablename   location    input_format    output_format   serialization_lib   serde_parameters    compressed  parameters

athena_schema   elb_logs    s3://athena-examples-ap-south-1/elb/plaintext   org.apache.hadoop.mapred.TextInputFormat    org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat  org.apache.hadoop.hive.serde2.RegexSerDe    {"input.regex":"([^ ]*) ([^ ]*) ([^ ]*):([0-9]*) ([^ ]*):([0-9]*) ([.0-9]*) ([.0-9]*) ([.0-9]*) (-|[0-9]*) (-|[0-9]*) ([-0-9]*)     0   {"EXTERNAL":"TRUE","transient_lastDdlTime":"1480278335"}

我不确定为什么 athena 控制台显示所有列的正确值,而 redshift 显示所有 NULL?

标签: amazon-redshift-spectrum

解决方案


这是因为 elb_logs 表使用了频谱无法处理的正则表达式序列化。我使用此命令将表格转换为镶木地板文件格式。

CREATE TABLE elb_logs3
WITH (
      format = 'PARQUET',
      parquet_compression = 'SNAPPY',
      external_location = 's3://elb163/parqfiles'
) AS SELECT * from elb_logs

现在 athena 将有 2 个表“elb_logs”和“elb_logs3”。一旦我使用像这样的标准命令创建外部模式......

drop schema "athena_schema";

create external schema athena_schema from data catalog 
database 'sampledb' 
iam_role 'arn:aws:iam::XXX:role/RedshiftCopyUnload'
region 'us-east-1';

我现在可以像这样从 elb_logs 表中选择记录...

select * from athena_schema.elb_logs3 限制 10;

请注意,从 elb_logs 表中选择仍然显示所有列的 NULL 值。


推荐阅读