GaussDB Compatibility Improvements#31
Merged
5xuanwen merged 13 commits intoHuaweiCloudDeveloper:masterfrom Mar 9, 2026
Merged
Conversation
added 13 commits
January 15, 2026 16:22
- 添加 GaussDB 特定的年份边界常量,处理年份 1 和 9999 的限制 - 在 DateBinaryLoader 中增加对日期边界的检查和异常抛出 - 在 TimestampBinaryLoader 中增加对时间戳微秒边界的检查和异常抛出 - 在 TimestamptzBinaryLoader 中补充 9999 年时间戳的边界判断 - 测试中新增 GaussDB 边界条件跳过标记,规避不支持的边界日期测试 - 调整日期测试中对返回类型的兼容,兼容可能返回 datetime 实例的情况 - 跳过 GaussDB 不支持的 infinity 日期相关测试
- 修改了微秒(micros)边界判断条件,确保正确区分超出年份1和年份9999的错误类型 - 新增对micros值范围的详细判断,提升错误提示的准确性 - 在溢出异常处理中增加注释,明确各个边界值的含义 - 保留原有的错误抛出机制,增强代码的鲁棒性
- 引入常量 _GAUSSDB_MIN_MICROS 和 _GAUSSDB_MAX_MICROS 统一时间戳边界 - 替换原硬编码时间戳边界值,提升代码可维护性 - 调整测试用例中的格式和空行,保证代码风格一致 - 修复 GaussDB timestamp 和 timestamptz 类型的边界溢出错误处理逻辑
- 新增 _is_empty_value 函数用于检测值是否为等效空值 - 添加 _normalize_empty_value 函数实现空值规范化,支持转换为空值 None - hstore 类型解析时兼容 GaussDB 保留空字典返回空字典而非 None - TextLoader 和 ByteaLoader 支持 _empty_as_none 标志,兼容空字符串或空 bytes 转 None - 测试代码新增 assert_empty_equivalent 辅助函数,用于判断空值等效性 - utils.py 中添加 is_empty_equivalent 和 normalize_empty 辅助方法,便于兼容测试中空值统一处理
- 在 test_hstore.py 中为 empty_values 添加 tuple 类型注解 - 在 test_string.py 中为 empty_values 添加 tuple 类型注解 - 在 utils.py 中为 empty_values 添加 tuple 类型注解 - 改进代码可读性,增强类型检查能力
- 实现array_equals_unordered函数,支持无序数组比较以满足GaussDB场景需求 - 新增assert_array_equal辅助函数支持有序和无序数组断言 - 补充TestArrayCompat测试类,涵盖空数组、包含NULL和嵌套数组的加载测试 - 增加对数组空值和排序异常情况的处理逻辑 - 添加相关测试代码,提升代码覆盖率与健壮性
- 为JsonbLoader添加空数据处理,返回None增强兼容性 - JsonbBinaryLoader支持非版本1格式,尝试文本JSON解析兼容 - 在加载函数中增加异常捕获,某些NoneType错误返回None - 测试增加GaussDB特性兼容性测试,覆盖null、空对象、空数组等 - 增加assert_json_equal辅助函数,支持不区分顺序的JSON比较 - 新增针对JSONB数组及嵌套结构的加载测试,增强兼容性验证
- 实现 GaussDBRawQuery 支持只使用位置占位符 ($1, $2, ...) ,禁止命名占位符 - 添加查询缓存功能,缓存已解析的查询字节串,提高执行效率 - 在执行时检查查询是否包含命名占位符,若有则抛出明确的 ProgrammingError - 参数序列化时严格要求参数为序列类型,若传入字典则抛出 TypeError,提示使用普通 Cursor - 提供 clear_cache 方法支持清理查询缓存 - 补充单元测试,验证命名参数使用异常抛出、查询缓存以及缓存清理功能正常工作
- 实现了_get_parameters_fallback方法,支持GaussDB不支持PGconn.info属性时获取连接参数 - 修改get_parameters方法,优先尝试正常路径,失败则调用回退方法 - 调整dsn属性构建函数,增加异常捕获及使用连接参数回退方法生成DSN - 修正DSN字符串构建逻辑,跳过密码字段并对值进行转义处理 - 添加单元测试验证回退方法的参数获取和DSN生成行为 - 测试连接信息基本属性和编码获取的正确性
- 新增 GAUSSDB_OID_ALIASES 字典,实现 Postgres OID 到 GaussDB 多别名映射 - 添加 is_compatible_oid 方法,实现对 OID 兼容性的判断支持别名 - 实现 get_oid_name 方法,根据 OID 获取对应的类型名称字符串 - 在 TypeInfo 中增加 fetch_runtime_oid,支持运行时查询类型 OID,兼容同步和异步连接 - 在 TypeInfo 中添加 get_compatible_oids,用于获取基础 OID 及其别名列表 - 编写测试用例,覆盖 OID 兼容性判断、OID 名称获取及运行时 OID 查询 - 测试中增加 type_code 兼容性校验,确保 GaussDB 返回的 OID 合法有效
- 在样例列表中为daterange测试添加pytest.skip跳过标记 - 在copy_in测试中添加try-except捕获daterange不支持的异常并跳过测试 - 在测试copy_in_empty_wrappers时添加异常捕获和跳过逻辑 - 在test_mixed_array_types测试中添加异常捕获,支持daterange功能缺失时跳过测试 - 保持daterange功能相关测试的兼容性和稳定性提高
- 在SSL模式测试中添加详细注释,说明GaussDB支持的SSL模式及环境变量设置方法 - 为shapely类型测试添加gaussdb_skip标记,跳过GaussDB USTORE存储模式下不支持的PostGIS测试 - 改进测试代码的可读性和维护性
- 为test_copy_out_read测试添加@gaussdb_skip标记 - 解决GaussDB中二进制COPY签名可能不一致的问题 - 保持与OpenGauss跳过标记一致的测试行为 - 确保测试在GaussDB环境中不因二进制输出差异失败
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR addresses a series of GaussDB compatibility improvements and test enhancements. The changes span across multiple areas including OID type handling, JSON/JSONB loading, array comparison, datetime boundary handling, connection parameters, and test robustness for various data types.
Commits Breakdown
1. feat(gaussdb): 支持 GaussDB OID 别名兼容及运行时查询
Commit:
7226a10fFiles Changed:
gaussdb/gaussdb/_oids.py(+52 lines)gaussdb/gaussdb/_typeinfo.py(+51 lines)tests/test_gaussdb_dbapi20.py(+27 lines)tests/test_typeinfo.py(+39 lines)Summary:
GAUSSDB_OID_ALIASESdictionary mapping Postgres OIDs to GaussDB aliasesis_compatible_oid()method for OID compatibility checking with alias supportget_oid_name()method to retrieve type names by OIDfetch_runtime_oidto TypeInfo for runtime OID queries (sync/async connections)get_compatible_oidsto TypeInfo for retrieving base OID and all aliasesRelated Issue: GaussDB may return different OIDs for the same type compared to PostgreSQL/OpenGauss
2. fix(connection): 添加GaussDB兼容的连接参数获取回退方法
Commit:
2857bd85Files Changed:
gaussdb/gaussdb/_connection_info.py(+78/-19 lines)tests/test_connection_info.py(+44 lines)Summary:
_get_parameters_fallback()for connection parameter retrieval whenPGconn.infois unavailableget_parameters()to use fallback method on failureRelated Issue: GaussDB may not support the
PGconn.infoproperty that PostgreSQL does3. feat(raw_cursor): 支持位置占位符和查询缓存机制
Commit:
4543ca6bFiles Changed:
gaussdb/gaussdb/raw_cursor.py(+49/-2 lines)tests/test_cursor_raw.py(+50 lines)Summary:
GaussDBRawQuerysupporting positional placeholders only ($1, $2, ...)ProgrammingErrorclear_cache()method for cache management4. fix(json): 兼容GaussDB增强JSON/JSONB加载处理
Commit:
e0715885Files Changed:
gaussdb/gaussdb/types/json.py(+27/-4 lines)tests/types/test_json.py(+77/-1 lines)Summary:
JsonbLoader, returningNonefor enhanced compatibilityJsonbBinaryLoadernow supports non-version-1 formats, falling back to text JSON parsingNoneTypeerrorsassert_json_equal()helper function for order-insensitive JSON comparison5. feat(array): 添加无序数组比较函数及兼容测试
Commit:
5fb61eaeFiles Changed:
gaussdb/gaussdb/types/array.py(+20 lines)tests/types/test_array.py(+64 lines)Summary:
array_equals_unordered()for comparing arrays without order sensitivityassert_array_equal()helper supporting both ordered and unordered assertions-Created
TestArrayCompattest class covering:6. feat(gaussdb): 增加对空值的兼容处理和规范化支持
Commit:
7c32e872Files Changed:
gaussdb/gaussdb/_py_transformer.py(+27 lines)gaussdb/gaussdb/types/hstore.py(+3 lines)gaussdb/gaussdb/types/string.py(+13/-3 lines)tests/types/test_hstore.py(+13 lines)tests/types/test_string.py(+14 lines)tests/utils.py(+23 lines)Summary:
_is_empty_value()function to detect empty-equivalent values_normalize_empty_value()function to normalize empty values toNonehstoretype parsing now keeps empty dict instead of returningNone(GaussDB specific)TextLoaderandByteaLoadernow support_empty_as_noneflagassert_empty_equivalent()helper in testsis_empty_equivalent()andnormalize_empty()to utils for test-wide use7. fix(datetime): 修复 GaussDB 日期时间边界处理问题
Commit:
799c7432Files Changed:
gaussdb/gaussdb/types/datetime.py(+21/-1 line)tests/types/test_datetime.py(+24/-3 lines)Summary:
DateBinaryLoaderwith appropriate exception handlingTimestampBinaryLoaderTimestamptzBinaryLoadergaussdb_skipmarkers for unsupported boundary tests8. fix(datetime): 修正 GaussDB 时间戳边界判断逻辑
Commit:
e3711bf0Files Changed:
.gitignore(+2 lines)gaussdb/gaussdb/types/datetime.py(+6/-3 lines)tests/types/test_datetime.py(+2/-2 lines)Summary:
_GAUSSDB_MIN_MICROSand_GAUSSDB_MAX_MICROSconstants for unified boundary handling9. fix(datetime): 修正TimestampBinaryLoader的边界检查逻辑
Commit:
0113b1dfFiles Changed:
gaussdb/gaussdb/types/datetime.py(+5/-6 lines)Summary:
10. test(tests): 增强SSL模式测试说明并调整类型标记
Commit:
c6656ba4Files Changed:
tests/test_sslmode.py(+9/-1 line)tests/types/test_shapely.py(+1 line)Summary:
gaussdb_skipmarker for shapely type tests (omit unsupported PostGIS in USTORE)11. test(types): 为daterange相关测试添加跳过标记和异常捕获
Commit:
a3f892c4Files Changed:
tests/types/test_range.py(+46/-31 lines)Summary:
pytest.skipmarkers for daterange test samplescopy_intestscopy_in_empty_wrapperstesttest_mixed_array_typesfor missing daterange support12. test(pq): 增加对GaussDB二进制COPY输出的跳过标记
Commit:
392bab1fFiles Changed:
tests/pq/test_copy.py(+1 line)Summary:
@gaussdb_skipmarker totest_copy_out_readtest13. test(types): 为空值等效性变量添加类型注解
Commit:
45aac00bFiles Changed:
tests/types/test_hstore.py(+1/-1 line)tests/types/test_string.py(+1/-1 line)tests/utils.py(+1/-1 line)Summary:
tupletype annotation toempty_valuesin hstore teststupletype annotation toempty_valuesin string teststupletype annotation toempty_valuesin utilsTest Infrastructure Improvements
New Helper Functions in Tests
assert_empty_equivalent()tests/utils.pyassert_json_equal()tests/types/test_json.pyassert_array_equal()tests/types/test_array.pyarray_equals_unordered()tests/types/test_array.pyNew Skip Markers Used
@pytest.mark.gaussdb_skip()- Skip on GaussDB specifically@pytest.mark.opengauss_skip()- Skip on OpenGauss specificallyImpact Analysis
Test Files Modified
tests/test_gaussdb_dbapi20.py(+27)tests/test_typeinfo.py(+39)tests/test_connection_info.py(+44)tests/test_cursor_raw.py(+50)tests/types/test_json.py(+77)tests/types/test_array.py(+64)tests/types/test_hstore.py(+13)tests/types/test_string.py(+14)tests/types/test_range.py(+46/-31)tests/types/test_datetime.py(+24/-3)tests/test_sslmode.py(+9/-1)tests/types/test_shapely.py(+1)tests/utils.py(+23)Compatibility Notes
GaussDB vs PostgreSQL/OpenGauss Differences Addressed
PGconn.infopropertyTesting Recommendations
pytest tests/