嗨,我正在尝试将多个表从 Redshift 卸载到特定的 S3 存储桶,但出现以下错误:
psycopg2.InternalError: Specified unload destination on S3 is not empty. Consider using a different bucket / prefix, manually removing the target files in S3, or using the ALLOWOVERWRITE option.
Run Code Online (Sandbox Code Playgroud)
如果我在 unload_function 上添加 'allowoverwrite' 选项,它会在表之前覆盖并卸载 S3 中的最后一个表。
这是我给出的代码:
import psycopg2
def unload_data(r_conn, aws_iam_role, datastoring_path, region, table_name):
unload = '''unload ('select * from {}')
to '{}'
credentials 'aws_iam_role={}'
manifest
gzip
delimiter ',' addquotes escape parallel off '''.format(table_name, datastoring_path, aws_iam_role)
print ("Exporting table to datastoring_path")
cur = r_conn.cursor()
cur.execute(unload) …Run Code Online (Sandbox Code Playgroud) amazon-s3 python-3.x amazon-redshift amazon-redshift-spectrum
我正在尝试从 csv 中创建一个 Redshift 外部表,其中包含转义引号,如rfc4180中所述:
如果使用双引号括住字段,则必须通过在字段前添加另一个双引号来转义出现在字段内的双引号。
例如:“aaa”、“b”、“bb”、“ccc”
我没有收到任何错误,但最终表的null值是我的字符串应该在的位置。
有没有办法让 Redshift 在创建外部表时理解这种 csv 格式?
我不想更改 csv 文件的格式。
示例 csv:
"some ""text""",some more text,"more, text",and more
Run Code Online (Sandbox Code Playgroud)
外部表创建示例:
create external table spectrum.spectrum_test_quote(
a varchar(32),
b varchar(32),
c varchar(32),
d varchar(32)
)
row format serde 'org.apache.hadoop.hive.serde2.OpenCSVSerde'
with serdeproperties (
'separatorChar' = ',',
'quoteChar' = '\"',
'escapeChar' = '\\'
)
stored as textfile
location 's3://';
Run Code Online (Sandbox Code Playgroud)
预期成绩:
实际结果:
null我试图创建一个爬行红移表的胶水爬虫。胶水爬虫执行成功并创建了一个外部表。但是当我查看表的元数据时,我发现了“输入格式”、“输出格式”、“Serde 名称”和“Serde 序列化库”为空。因此,当我尝试使用爬虫表从 Athena 或 spark 读取数据时,出现异常。以下是我使用 spark 读取表时遇到的异常。
Caused by: org.apache.hadoop.hive.ql.metadata.HiveException: Unable to fetch table redshift_table. StorageDescriptor#InputFormat cannot be null for table: redshift_table (Service: null; Status Code: 0; Error Code: null;Request ID: null)
以下是胶水爬虫表属性的屏幕截图。
请帮助我解决上述问题。
amazon-web-services amazon-redshift amazon-redshift-spectrum aws-glue
给定 S3 上由时间戳字段分区的 1.4 TB Parquet 数据的数据源(因此分区为year- month- day),我正在查询特定日期的数据(2.6 GB 数据)并通过 Redshift 检索 Parquet 文件中的所有可用字段此查询的频谱:
SELECT *
FROM my_external_schema.my_external_table
WHERE year = '2020' and month = '01' and day = '01'
Run Code Online (Sandbox Code Playgroud)
该表可通过Glue Crawler访问,该 Glue Crawler 指向 S3 中的顶层“文件夹”;这将创建一个数据库,然后通过此命令将数据库链接到新的外部架构:
create external schema my_external_schema from data catalog
database 'my_external_schema'
iam_role 'arn:aws:iam::123456789:role/my_role'
region 'my-region-9';
Run Code Online (Sandbox Code Playgroud)
在我的 IDE 中分析该表,我可以看到该表是由以下语句生成的:
create external table my_external_schema.my_external_table
(
id string,
my_value string,
my_nice_value string
)
partitioned by (year string, month string, …Run Code Online (Sandbox Code Playgroud) amazon-s3 amazon-web-services amazon-redshift amazon-redshift-spectrum aws-glue-data-catalog
我在 AWS 频谱中创建了外部表来查询 s3 数据,但是我无法识别记录所属的文件名(我在一个存储桶下有数千个文件)
在 AWS Athena 中,我们有一个伪列“$PATH”,它将显示 s3 文件名在使用频谱时是否有任何类似的方法可用?
amazon-s3 amazon-web-services amazon-redshift amazon-athena amazon-redshift-spectrum
我在S3中有一个文件,其中包含以下数据:
name,age,gender
jill,30,f
jack,32,m
Run Code Online (Sandbox Code Playgroud)
create external table spectrum.customers (
"name" varchar(50),
"age" int,
"gender" varchar(1))
row format delimited
fields terminated by ','
lines terminated by \n'
stored as textfile
location 's3://...';
Run Code Online (Sandbox Code Playgroud)
查询数据时,我得到以下结果:
select * from spectrum.customers;
name,age,g
jill,30,f
jack,32,m
Run Code Online (Sandbox Code Playgroud)
是否有一种优雅的方法可以跳过标题行作为外部表定义的一部分,类似于tblproperties ("skip.header.line.count"="1")Hive中的选项?或者是我唯一的选择(至少现在)过滤掉标题行作为select语句的一部分?
amazon-web-services amazon-redshift amazon-redshift-spectrum
我正在一个包含多个具有不同架构的文件的文件夹上运行爬网程序。我希望为每个文件找到一个表。
发生的情况是,在 Glue Catalog 中,我实际上可以看到每个文件的一个表,以及它自己的架构。但是当我尝试通过 Redshift Spectrum 查询它时(创建外部架构等之后),我得到了这个异常:
[XX000][500310] [Amazon](500310) Invalid operation: Parsed manifest is not a valid JSON object.
Run Code Online (Sandbox Code Playgroud)
如何修复它?
amazon-s3 amazon-web-services amazon-redshift amazon-redshift-spectrum aws-glue
我在红移谱中创建了一个外部表。运行 select * from table_name 后,我收到以下错误
SQL Error [XX000]: ERROR: Spectrum Scan Error
Detail:
-----------------------------------------------
error: Spectrum Scan Error
code: 15007
context: Forbidden: HTTP response error code: 403 Message: AccessDenied Access Denied
Run Code Online (Sandbox Code Playgroud)
请让我知道可能出现什么问题。我可以在同一 s3 位置执行 aws s3 ls 和 aws s3 cp 命令。
amazon-web-services amazon-redshift amazon-redshift-spectrum
Athena有一些默认服务限制,可以帮助 ~限制S3 中大型数据湖上意外“失控”查询的成本。它们不是很好(基于 ~ 时间,而不是扫描的数据量),但它仍然有帮助。

红移光谱怎么样?它提供的哪些机制可以轻松用于限制成本或降低在针对 S3 的单个失控查询中“意外”扫描过多数据的风险?解决这个问题的好方法是什么?
这篇文章对于显示 Redshift GRANTS 很有用,但不会显示外部表/架构上的 GRANTS。
如何显示外部架构(和相关表)权限?
amazon-web-services amazon-redshift amazon-redshift-spectrum