远大前程 SQLAlchemy 不包含小写列名

Great Expectations SQLAlchemy doesn't enclose lowercase column names

我正在尝试使用 SQLAlchemy 和 Great Expectations 来测试存储在 Snowflake DB 中的数据集的数据质量。数据集称为 candidates,感兴趣的列称为 first_name

然而,当我运行

sql_dataset = great_expectations.dataset.SqlAlchemyDataset(table_name="candidates", engine=engine, schema=creds["schema"])
sql_dataset.expect_column_values_to_be_in_set("first_name", ['Gather', 'Male'])

我得到:

ProgrammingError: (snowflake.connector.errors.ProgrammingError) 002003 (42S02): SQL compilation error:
Object 'KEBOOLA_274.WORKSPACE_48777448.CANDIDATES' does not exist or not authorized.
[SQL: SELECT count(*) AS element_count, sum(CASE WHEN (first_name IS NULL) THEN %(param_1)s ELSE %(param_2)s END) AS null_count, sum(CASE WHEN (first_name NOT IN (%(first_name_1)s, %(first_name_2)s) AND first_name IS NOT NULL) THEN %(param_3)s ELSE %(param_4)s END) AS unexpected_count 
FROM "WORKSPACE_48777448".candidates]
[parameters: {'param_1': 1, 'param_2': 0, 'first_name_1': 'Gather', 'first_name_2': 'Male', 'param_3': 1, 'param_4': 0}]
(Background on this error at: http://sqlalche.me/e/13/f405)

问题是 table 名称没有用双引号引起来,因此 Snowflake 正在寻找 CANDIDATES 而不是 candidates。如果找到 table,列名也会出现同样的问题。

我测试过

sql_dataset = great_expectations.dataset.SqlAlchemyDataset(table_name="\"candidates\"",
                                                           engine=engine,
                                                           schema=creds["schema"])

bu Snowflake 正在寻找名为 KEBOOLA_274.WORKSPACE_48777448.""candidates"" 的 table。

我知道默认情况下 SQLAlchemy 认为小写对象名称不区分大小写,因此它不会将名称括起来。请问有什么解决办法吗?

正如 Mike Walton 在评论中建议的那样,解决方案是在使用 great_expectations 包之前将所有 table 名称大写。

我作为 Great Expectations 的开发者在 Superconductive 工作。几周前我提交了一份 fix for this!您现在可以在 batch_kwargs. 中指定 use_quoted_name 属性 如果将其设置为 True,它将把您的 table 和 column_names 视为区分大小写,因此您访问小写 table 名称应该没有问题,但您还需要确保正确指定其他 table 和列名称的大小写。