在 athena 上正常工作时,数据在 redshift external table 上显示为 null
data appears as null on redshift external table while working right on athena
所以我正在尝试运行以下关于红移光谱的简单查询:
select * from company.vehicles where vehicle_id is not null
并且 return 0 行(table 中的所有行均为空)。但是,当我 运行 在 athena 上执行相同的查询时,它工作正常并且 return 结果。尝试过 msck repair 但 athena 和 redshift 都使用相同的 metastore,所以这无关紧要。
我也没有看到任何错误。
文件格式为orc。
创建 table 查询是:
CREATE EXTERNAL TABLE 'vehicles'(
'vehicle_id' bigint,
'parent_id' bigint,
'client_id' bigint,
'assets_group' int,
'drivers_group' int)
PARTITIONED BY (
'dt' string,
'datacenter' string)
ROW FORMAT SERDE
'org.apache.hadoop.hive.ql.io.orc.OrcSerde'
STORED AS INPUTFORMAT
'org.apache.hadoop.hive.ql.io.orc.OrcInputFormat'
OUTPUTFORMAT
'org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat'
LOCATION
's3://company-rt-data/metadata/out/vehicles/'
TBLPROPERTIES (
'CrawlerSchemaDeserializerVersion'='1.0',
'CrawlerSchemaSerializerVersion'='1.0',
'classification'='orc',
'compressionType'='none')
有什么想法吗?
您是如何创建外部 table 的?
对于 Spectrum,您必须显式设置参数以将应视为 null
在 TABLE PROPERTIES 中添加参数 'serialization.null.format'='' 这样所有带有 '' 的列都将被视为 NULL 到您的外部 table 光谱
**
CREATE EXTERNAL TABLE external_schema.your_table_name(
)
row format delimited
fields terminated by ','
stored as textfile
LOCATION [filelocation]
TABLE PROPERTIES('numRows'='100', 'skip.header.line.count'='1','serialization.null.format'='');
**
或者,您可以在创建外部 table 时设置 SERDE-PROPERTIES,它将自动识别 NULL 值
最后发现是redshift的bug。为了修复它,我们需要 运行 以下命令:
ALTER TABLE table_name SET TABLE properties(‘orc.schema.resolution’=‘position’);
我遇到了类似的问题并找到了这个问题。
在我的例子中,我使用 Athena 创建的外部表指向包含大量嵌套 JSON 数据的 S3 存储桶。为了使用 Redshift 访问它们,我在查询之前使用 json_serialization_enable to true;
使嵌套的 JSON 列可查询。当 JSON 超出大小限制时,这会导致某些列为 NULL
,请参阅 here:
If the serialization overflows the maximum VARCHAR size of 65535, the cell is set to NULL.
为了解决这个问题,我使用了 Amazon Redshift Spectrum 而不是序列化:https://docs.aws.amazon.com/redshift/latest/dg/tutorial-query-nested-data.html。
所以我正在尝试运行以下关于红移光谱的简单查询:
select * from company.vehicles where vehicle_id is not null
并且 return 0 行(table 中的所有行均为空)。但是,当我 运行 在 athena 上执行相同的查询时,它工作正常并且 return 结果。尝试过 msck repair 但 athena 和 redshift 都使用相同的 metastore,所以这无关紧要。 我也没有看到任何错误。
文件格式为orc。
创建 table 查询是:
CREATE EXTERNAL TABLE 'vehicles'(
'vehicle_id' bigint,
'parent_id' bigint,
'client_id' bigint,
'assets_group' int,
'drivers_group' int)
PARTITIONED BY (
'dt' string,
'datacenter' string)
ROW FORMAT SERDE
'org.apache.hadoop.hive.ql.io.orc.OrcSerde'
STORED AS INPUTFORMAT
'org.apache.hadoop.hive.ql.io.orc.OrcInputFormat'
OUTPUTFORMAT
'org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat'
LOCATION
's3://company-rt-data/metadata/out/vehicles/'
TBLPROPERTIES (
'CrawlerSchemaDeserializerVersion'='1.0',
'CrawlerSchemaSerializerVersion'='1.0',
'classification'='orc',
'compressionType'='none')
有什么想法吗?
您是如何创建外部 table 的? 对于 Spectrum,您必须显式设置参数以将应视为 null
在 TABLE PROPERTIES 中添加参数 'serialization.null.format'='' 这样所有带有 '' 的列都将被视为 NULL 到您的外部 table 光谱
**
CREATE EXTERNAL TABLE external_schema.your_table_name(
)
row format delimited
fields terminated by ','
stored as textfile
LOCATION [filelocation]
TABLE PROPERTIES('numRows'='100', 'skip.header.line.count'='1','serialization.null.format'='');
**
或者,您可以在创建外部 table 时设置 SERDE-PROPERTIES,它将自动识别 NULL 值
最后发现是redshift的bug。为了修复它,我们需要 运行 以下命令:
ALTER TABLE table_name SET TABLE properties(‘orc.schema.resolution’=‘position’);
我遇到了类似的问题并找到了这个问题。
在我的例子中,我使用 Athena 创建的外部表指向包含大量嵌套 JSON 数据的 S3 存储桶。为了使用 Redshift 访问它们,我在查询之前使用 json_serialization_enable to true;
使嵌套的 JSON 列可查询。当 JSON 超出大小限制时,这会导致某些列为 NULL
,请参阅 here:
If the serialization overflows the maximum VARCHAR size of 65535, the cell is set to NULL.
为了解决这个问题,我使用了 Amazon Redshift Spectrum 而不是序列化:https://docs.aws.amazon.com/redshift/latest/dg/tutorial-query-nested-data.html。