语法无效:使用初始排序键创建 table 自动排序键
nvalid syntax: Create table sortkey auto with initial sortkeys
我正在尝试使用 target-redshift
将数据推送到 aws-redshift
https://pypi.org/project/target-redshift/
我正在使用 airflow
来监控 etl 状态
这是错误日志,我不知道它是什么意思。 target-redshift 的在线文档几乎不存在。有什么办法可以解决这个错误吗?
[2021-03-07 15:04:11,841] {bash_operator.py:126} INFO - ERROR Exception writing records
[2021-03-07 15:04:11,841] {bash_operator.py:126} INFO - Traceback (most recent call last):
[2021-03-07 15:04:11,841] {bash_operator.py:126} INFO - File "/usr/local/airflow/.virtualenvs/target-redshift/lib/python3.7/site-packages/target_postgres/postgres.py", line 300, in write_batch
[2021-03-07 15:04:11,841] {bash_operator.py:126} INFO - {'version': target_table_version})
[2021-03-07 15:04:11,841] {bash_operator.py:126} INFO - File "/usr/local/airflow/.virtualenvs/target-redshift/lib/python3.7/site-packages/target_postgres/sql_base.py", line 840, in write_batch_helper
[2021-03-07 15:04:11,841] {bash_operator.py:126} INFO - metadata)
[2021-03-07 15:04:11,841] {bash_operator.py:126} INFO - File "/usr/local/airflow/.virtualenvs/target-redshift/lib/python3.7/site-packages/target_postgres/postgres.py", line 588, in write_table_batch
[2021-03-07 15:04:11,841] {bash_operator.py:126} INFO - table=sql.Identifier(remote_schema['name'])
[2021-03-07 15:04:11,841] {bash_operator.py:126} INFO - File "/usr/local/airflow/.virtualenvs/target-redshift/lib/python3.7/site-packages/target_postgres/postgres.py", line 65, in execute
[2021-03-07 15:04:11,841] {bash_operator.py:126} INFO - return super(_MillisLoggingCursor, self).execute(query, vars)
[2021-03-07 15:04:11,841] {bash_operator.py:126} INFO - File "/usr/local/airflow/.virtualenvs/target-redshift/lib/python3.7/site-packages/psycopg2/extras.py", line 461, in execute
[2021-03-07 15:04:11,841] {bash_operator.py:126} INFO - return super(LoggingCursor, self).execute(query, vars)
[2021-03-07 15:04:11,842] {bash_operator.py:126} INFO - psycopg2.errors.InternalError_: Invalid syntax: Create table sortkey auto with initial sortkeys.
[2021-03-07 15:04:11,842] {bash_operator.py:126} INFO -
[2021-03-07 15:04:11,842] {bash_operator.py:126} INFO - CRITICAL ('Exception writing records', InternalError_('Invalid syntax: Create table sortkey auto with initial sortkeys.\n'))
在您的任务下面某处正在查询此表单 运行。
CREATE TABLE schema.tablename_copy
(LIKE schema.tablename)
这就是抛出错误的原因Invalid syntax: Create table sortkey auto with initial sortkeys.
修复或删除来源 table 的 SORTKEY 和 DISTSTYLE 可解决此问题。例如
ALTER TABLE schema.tablename ALTER SORTKEY NONE;
ALTER TABLE schema.tablename ALTER DISTSTYLE EVEN;
根据您的 table 实际需要(在排序和 distkeys 方面),您可能会做其他事情。然而,这很可能是一些加载 table 并且没有 SORTKEY 等应该不是什么大问题。
其他方法
如果上述方法失败,任何避免 LIKE
的方法也将起作用。因为这个 LIKE
很可能是加载/更新序列的一部分。例如
- 制作目标的临时副本 table(使用 LIKE 语句)
- 将新数据加载到临时文件中 table
- 从目标中删除 ID 在新数据中的 table 行
- 将新数据插入目标table
- 清理温度 table。
Airflow 可能会在幕后为您执行这一系列 SQL 查询。您可以将 Airflow 的步骤分解为单独的任务并避免使用 LIKE
.
- 删除原点 table(可能取决于用例)- 我在重新创建 table 时发现 LIKE 的问题消失了。
- 使用普通 CREATE STATEMENT(而不是依赖于 LIKE)显式创建副本 table
- 考虑直接对 table 执行 INSERT / APPEND / COPY 并稍后处理重复项
额外信息:
这个新错误出现在 Redshift 端 。
不完全确定为什么,但是 LIKE
语句正在尝试传输 SORTKEY 但无法这样做。
如果你检查原点的定义 table schema.tablename
你可能会发现 Redshifts 对它的理解有些奇怪。
Amazon 人员提供了此视图,让您获得完整的 table DDL 语句 link
运行反对观点:
SELECT * FROM
WHERE schemaname = 'schema' AND tablename = 'tablename'
也许会展示一些有用的东西。在我的例子中,SORTKEY 和 DISTKEY 都抛出错误:对我来说,这表明 Redshift 对键的内部理解存在缺陷。更重要的是——在我的例子中,我从未设置过这些键,所以我认为它们是由 Redshift 暗示的。
我正在尝试使用 target-redshift
将数据推送到 aws-redshift
https://pypi.org/project/target-redshift/
我正在使用 airflow
来监控 etl 状态
这是错误日志,我不知道它是什么意思。 target-redshift 的在线文档几乎不存在。有什么办法可以解决这个错误吗?
[2021-03-07 15:04:11,841] {bash_operator.py:126} INFO - ERROR Exception writing records
[2021-03-07 15:04:11,841] {bash_operator.py:126} INFO - Traceback (most recent call last):
[2021-03-07 15:04:11,841] {bash_operator.py:126} INFO - File "/usr/local/airflow/.virtualenvs/target-redshift/lib/python3.7/site-packages/target_postgres/postgres.py", line 300, in write_batch
[2021-03-07 15:04:11,841] {bash_operator.py:126} INFO - {'version': target_table_version})
[2021-03-07 15:04:11,841] {bash_operator.py:126} INFO - File "/usr/local/airflow/.virtualenvs/target-redshift/lib/python3.7/site-packages/target_postgres/sql_base.py", line 840, in write_batch_helper
[2021-03-07 15:04:11,841] {bash_operator.py:126} INFO - metadata)
[2021-03-07 15:04:11,841] {bash_operator.py:126} INFO - File "/usr/local/airflow/.virtualenvs/target-redshift/lib/python3.7/site-packages/target_postgres/postgres.py", line 588, in write_table_batch
[2021-03-07 15:04:11,841] {bash_operator.py:126} INFO - table=sql.Identifier(remote_schema['name'])
[2021-03-07 15:04:11,841] {bash_operator.py:126} INFO - File "/usr/local/airflow/.virtualenvs/target-redshift/lib/python3.7/site-packages/target_postgres/postgres.py", line 65, in execute
[2021-03-07 15:04:11,841] {bash_operator.py:126} INFO - return super(_MillisLoggingCursor, self).execute(query, vars)
[2021-03-07 15:04:11,841] {bash_operator.py:126} INFO - File "/usr/local/airflow/.virtualenvs/target-redshift/lib/python3.7/site-packages/psycopg2/extras.py", line 461, in execute
[2021-03-07 15:04:11,841] {bash_operator.py:126} INFO - return super(LoggingCursor, self).execute(query, vars)
[2021-03-07 15:04:11,842] {bash_operator.py:126} INFO - psycopg2.errors.InternalError_: Invalid syntax: Create table sortkey auto with initial sortkeys.
[2021-03-07 15:04:11,842] {bash_operator.py:126} INFO -
[2021-03-07 15:04:11,842] {bash_operator.py:126} INFO - CRITICAL ('Exception writing records', InternalError_('Invalid syntax: Create table sortkey auto with initial sortkeys.\n'))
在您的任务下面某处正在查询此表单 运行。
CREATE TABLE schema.tablename_copy
(LIKE schema.tablename)
这就是抛出错误的原因Invalid syntax: Create table sortkey auto with initial sortkeys.
修复或删除来源 table 的 SORTKEY 和 DISTSTYLE 可解决此问题。例如
ALTER TABLE schema.tablename ALTER SORTKEY NONE;
ALTER TABLE schema.tablename ALTER DISTSTYLE EVEN;
根据您的 table 实际需要(在排序和 distkeys 方面),您可能会做其他事情。然而,这很可能是一些加载 table 并且没有 SORTKEY 等应该不是什么大问题。
其他方法
如果上述方法失败,任何避免 LIKE
的方法也将起作用。因为这个 LIKE
很可能是加载/更新序列的一部分。例如
- 制作目标的临时副本 table(使用 LIKE 语句)
- 将新数据加载到临时文件中 table
- 从目标中删除 ID 在新数据中的 table 行
- 将新数据插入目标table
- 清理温度 table。
Airflow 可能会在幕后为您执行这一系列 SQL 查询。您可以将 Airflow 的步骤分解为单独的任务并避免使用 LIKE
.
- 删除原点 table(可能取决于用例)- 我在重新创建 table 时发现 LIKE 的问题消失了。
- 使用普通 CREATE STATEMENT(而不是依赖于 LIKE)显式创建副本 table
- 考虑直接对 table 执行 INSERT / APPEND / COPY 并稍后处理重复项
额外信息:
这个新错误出现在 Redshift 端 。
不完全确定为什么,但是 LIKE
语句正在尝试传输 SORTKEY 但无法这样做。
如果你检查原点的定义 table schema.tablename
你可能会发现 Redshifts 对它的理解有些奇怪。
Amazon 人员提供了此视图,让您获得完整的 table DDL 语句 link
运行反对观点:
SELECT * FROM
WHERE schemaname = 'schema' AND tablename = 'tablename'
也许会展示一些有用的东西。在我的例子中,SORTKEY 和 DISTKEY 都抛出错误:对我来说,这表明 Redshift 对键的内部理解存在缺陷。更重要的是——在我的例子中,我从未设置过这些键,所以我认为它们是由 Redshift 暗示的。