[Feature] 允许扩展 ReflectLoader#loadField 支持自定义字段取值处理器 - #443
Open
Ayasaz wants to merge 3 commits into
Open
Conversation
新增 ExtendFieldHandler (@FunctionalInterface) 接口,允许用户在 ReflectLoader 中注册自定义的字段取值逻辑,支持对非标准容器(如 Flink Row、JDBC ResultSet、 自定义 MapLike/CollectionLike 等)进行属性访问。 改动: - 新增 ExtendFieldHandler (FunctionalInterface) 到 function 包 - ReflectLoader 添加 addExtendFieldHandler + fieldHandlers 处理链 - loadField 在最前面插入扩展分支,handler 返回 null 则继续下一个 - Express4Runner 透传 addExtendFieldHandler 不影响现有行为,不注入 FieldHandler 时与原来完全一致。 Closes alibaba#415
Collaborator
|
注释可以改成英文吗? |
DQinYuan
requested changes
Jun 14, 2026
…glish doc Per review feedback on alibaba#443: - Bind ExtendFieldHandler to a receiver Class<?> (mirroring addExtendFunction(String, Class<?>, QLFunctionalVarargs)) so registrations cannot conflict and dispatch is by isAssignableFrom. - Handler now returns a raw Object instead of the low-level Value; ReflectLoader wraps it into DataValue, so users no longer touch internal runtime structures. - Rewrite all comments/Javadoc in English. - Update tests accordingly (4 cases, incl. super-type binding). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
DQinYuan
reviewed
Jun 19, 2026
DQinYuan
requested changes
Jun 19, 2026
DQinYuan
left a comment
Collaborator
There was a problem hiding this comment.
另外,在README-source.adoc和README-EN-source.adoc分别补一下这个功能的中英文文档
…null semantics & docs Per review feedback on alibaba#443 (commit 2cab1c1): - Store ExtendFieldHandler registrations in a CopyOnWriteArrayList (mirroring extensionFunctions) instead of a ConcurrentHashMap, matching the read-heavy / write-rare access pattern and keeping registration order deterministic. - A matched handler (bean assignable to its binding class) is now authoritative: its return value including null is taken as the field value, so a field that is present but null no longer falls through to reflection and gets reported as missing. The default logic only applies when no binding class matches. - Document the feature in README-source.adoc / README-EN-source.adoc and the generated README.adoc / README-EN.adoc. - Update ExtendFieldHandlerTest accordingly (null-value authority, handler wins over reflection) and add a doc example tag. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Author
|
@DQinYuan 已按 review 全部更新(commit b37cf2c):
麻烦再看下,谢谢! |
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.
背景
当前 QLExpress4 的
ReflectLoader#loadField对非标准容器(如 Flink Row、Spark Row、JDBC ResultSet、自定义 MapLike/CollectionLike)的字段取值是封闭的,用户无法在 QL 表达式obj.col_a中直接使用这些结构,必须先做 convert copy。改动
仿照已有的
ExtensionFunction+addExtendFunction扩展模式,新增一个轻量ExtendFieldHandler接口,作为loadField可插拔的自定义字段取值处理链。ExtendFieldHandler(@FunctionalInterface)—— 支持 lambda 注册,返回 null 表示不匹配ReflectLoader添加addExtendFieldHandler+CopyOnWriteArrayList<ExtendFieldHandler>处理链loadField方法在最前面插入扩展分支:遍历 handler,返回非 null 则消费,全部返回 null 则走原有逻辑Express4Runner透传addExtendFieldHandlerExtendFieldHandlerTest4 个测试用例(匹配、不匹配穿透、回退、多链)兼容性
不影响现有行为。不注入 FieldHandler 时与原分支逻辑完全一致。全量测试 208 跑通(2 个 Error 是基线已有的
map/filter环境问题,与本次修改无关)。文件变更
ExtendFieldHandler.javaReflectLoader.javaExpress4Runner.javaExtendFieldHandlerTest.javaCloses #415