Skip to content

[refactor](Expr) Refactor Expr, Function, and related classes for module isolation#61216

Open
morrySnow wants to merge 4 commits intoapache:masterfrom
morrySnow:expr_refactor
Open

[refactor](Expr) Refactor Expr, Function, and related classes for module isolation#61216
morrySnow wants to merge 4 commits intoapache:masterfrom
morrySnow:expr_refactor

Conversation

@morrySnow
Copy link
Contributor

  • Decouple Function toThrift/toSql: create FunctionToThriftConverter and FunctionToSqlConverter, remove methods from Function/ScalarFunction/ AggregateFunction/AliasFunction
  • Inline FunctionName#toThrift at single call site; move FunctionName from analysis to catalog package
  • Move SearchDslParser and ANTLR grammars (SearchParser.g4, SearchLexer.g4) to analysis package alongside SearchPredicate
  • Move isExplainVerboseContext and buildFieldBindingExplainLines from SearchPredicate into ExprToSqlVisitor
  • Inline buildAnalyzerSqlFragment into InvertedIndexUtil; extract InvertedIndexProperties (Env-free) for MatchPredicate usage
  • Create NameFormatUtils in fe-common; move Utils.normalizeName there
  • Move SHADOW_NAME_PREFIX from SchemaChangeHandler to Column
  • Move FractionalFormat to org.apache.doris.common in fe-common module

Release note

None

Check List (For Author)

  • Test

    • Regression test
    • Unit Test
    • Manual test (add detailed scripts or steps below)
    • No need to test or manual test. Explain why:
      • This is a refactor/code format and no logic has been changed.
      • Previous test can cover this change.
      • No code files have been changed.
      • Other reason
  • Behavior changed:

    • No.
    • Yes.
  • Does this need documentation?

    • No.
    • Yes.

Check List (For Reviewer who merge this PR)

  • Confirm the release note
  • Confirm test cases
  • Confirm document
  • Add branch pick label

…ule isolation

- Decouple Function toThrift/toSql: create FunctionToThriftConverter and
  FunctionToSqlConverter, remove methods from Function/ScalarFunction/
  AggregateFunction/AliasFunction
- Inline FunctionName#toThrift at single call site; move FunctionName
  from analysis to catalog package
- Move SearchDslParser and ANTLR grammars (SearchParser.g4, SearchLexer.g4)
  to analysis package alongside SearchPredicate
- Move isExplainVerboseContext and buildFieldBindingExplainLines from
  SearchPredicate into ExprToSqlVisitor
- Inline buildAnalyzerSqlFragment into InvertedIndexUtil; extract
  InvertedIndexProperties (Env-free) for MatchPredicate usage
- Create NameFormatUtils in fe-common; move Utils.normalizeName there
- Move SHADOW_NAME_PREFIX from SchemaChangeHandler to Column
- Move FractionalFormat to org.apache.doris.common in fe-common module

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Thearas
Copy link
Contributor

Thearas commented Mar 11, 2026

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

…ion, and refactor PrintableMap

- Extract IndexType enum from IndexDefinition to org.apache.doris.catalog.info.IndexType
  in fe-catalog module. Update all files referencing IndexDefinition.IndexType.
- Create BasicPrintableMap in fe-foundation with protected hooks (shouldIncludeEntry,
  formatValue) for subclass customization. Zero Doris-specific dependencies.
- Rename PrintableMap to DatasourcePrintableMap, extending BasicPrintableMap.
  Sensitive key masking and hidden key filtering now use the hook pattern.
- Update Index.java to use InvertedIndexProperties directly instead of InvertedIndexUtil.
- Update Index.getPropertiesString() to use BasicPrintableMap.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
morrySnow and others added 2 commits March 11, 2026 18:13
- Create InvertedIndexPropertiesTest with 30 tests covering all methods
  including buildAnalyzerSqlFragment tests migrated from InvertedIndexSqlGeneratorTest.
- Delete InvertedIndexSqlGenerator (was just a pass-through delegate).
- Switch AnalyzeProperties and SinglePartitionDesc to BasicPrintableMap
  (no password masking needed for these use cases).
- Clean up FQN references in ExprToThriftVisitor and ShowCreateFunctionCommand.
- Remove deprecated normalizeName delegate from Utils.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ctionToThriftConverter

- BasicPrintableMapTest: 12 tests covering null/empty map, quotation, wrapping,
  custom separators/delimiters, subclass hooks, and deterministic ordering.
- FunctionToSqlConverterTest: 25 tests covering ScalarFunction/AggregateFunction/
  AliasFunction SQL generation, IF NOT EXISTS, GLOBAL, binary types, and dispatcher.
- FunctionToThriftConverterTest: 17 tests covering Thrift conversion for scalar/
  aggregate functions, base fields, return type precision handling, and dispatcher.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@morrySnow
Copy link
Contributor Author

run buildall

@morrySnow
Copy link
Contributor Author

/review

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Summary

This PR is a large FE refactoring (122 files, +2285/-965) focused on module isolation: decoupling Function toThrift/toSql into converters, extracting InvertedIndexProperties, moving SearchDslParser/ANTLR grammars, moving FractionalFormat and NameFormatUtils to fe-common, and several other class relocations.

Critical Checkpoint Conclusions

1. Goal and Correctness: The stated goal is module isolation/decoupling. The refactoring is well-executed overall. The FunctionToThriftConverter and FunctionToSqlConverter are line-by-line faithful reproductions of the original instance methods. The InvertedIndexProperties extraction is clean with proper delegation. Two non-refactoring changes are included: a bug fix in BinaryPredicate.commutative() and a serialization fix adding @SerializedName("noOp") to CastExpr.

2. Modification minimality: The PR touches 122 files, but most changes are mechanical (import updates, reference updates). The core structural changes are well-scoped.

3. Concurrency: No concurrency changes. N/A.

4. Lifecycle management: No new lifecycle concerns. N/A.

5. Configuration items: No configuration changes. N/A.

6. Incompatible changes: The @SerializedName("noOp") addition to CastExpr is a serialization format change but is forward and backward compatible (Gson silently ignores unknown fields on deserialization, and missing fields use default false). This is a correct bug fix.

7. Parallel code paths: The FunctionToThriftConverter changes dispatch from virtual methods (polymorphism) to instanceof checks. This is functionally equivalent for the current class hierarchy but means future Function subclasses would need to add branches to the converter rather than overriding a method. This is acceptable for a converter pattern.

8. Special conditional checks: The EncryptKeyName.java removal of ClusterNamespace.getNameFromFullName(db) is a concern (see inline comment). The BinaryPredicate.commutative() GT->LT fix is a confirmed correct bug fix.

9. Test coverage: The PR description indicates "no need to test" as a refactor with no logic change. However, the BinaryPredicate.commutative() GT->LT change IS a logic change (bug fix) and has no unit test coverage for this method. The CastExpr @SerializedName addition is also a behavioral change for serialization round-tripping.

10. Observability: No observability changes needed. N/A.

11. Transaction/persistence: The CastExpr @SerializedName fix correctly adds persistence for the noOp field. No EditLog concerns.

12. FE-BE variable passing: No new FE-BE variables. N/A.

13. Performance: No performance concerns. The instanceof dispatch in FunctionToThriftConverter is negligible overhead.

14. Other issues: See inline comments for the EncryptKeyName concern.

}
return ClusterNamespace.getNameFromFullName(db) + "." + keyName;
return db + "." + keyName;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential issue: Removing ClusterNamespace.getNameFromFullName(db) may produce incorrect output for environments upgraded from older Doris versions.

ConnectContext.currentDb can still contain a cluster prefix (e.g., "default_cluster:mydb") in certain code paths — for instance, MTMVPlanUtil.java:178 sets ctx.setDatabase(databaseIf.get().getFullName()), where Database.getFullName() returns the fullQualifiedName which may include the legacy cluster prefix. Similarly, encrypt keys deserialized from old FE images may have db persisted with the cluster prefix.

Without the stripping call, toString() would produce "default_cluster:mydb.mykey" instead of "mydb.mykey", and toSql() would produce invalid SQL like KEY default_cluster:mydb.mykey.

This may be intentional as part of the v3.0 cleanup (the Database class has a comment: "ClusterNamespace.getNameFromFullName should be removed in 3.0"), but please verify that all callers that set db have been migrated away from cluster-prefixed names, or that this change is coordinated with the broader cleanup.

@doris-robot
Copy link

TPC-H: Total hot run time: 27855 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit 54e3714e51d0386e57bd04e1fcff0f4d21a6df96, data reload: false

------ Round 1 ----------------------------------
============================================
q1	17659	4442	4315	4315
q2	q3	10645	785	518	518
q4	4687	365	254	254
q5	7555	1216	1026	1026
q6	181	181	153	153
q7	822	851	686	686
q8	9782	1470	1352	1352
q9	5226	4741	4716	4716
q10	6322	1903	1659	1659
q11	493	267	256	256
q12	745	561	475	475
q13	18032	2965	2224	2224
q14	229	225	229	225
q15	951	791	806	791
q16	777	747	690	690
q17	745	898	401	401
q18	6240	5421	5264	5264
q19	1480	965	605	605
q20	507	497	405	405
q21	4921	2251	1574	1574
q22	412	311	266	266
Total cold run time: 98411 ms
Total hot run time: 27855 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4710	4634	4655	4634
q2	q3	3949	4396	3908	3908
q4	867	1197	808	808
q5	4083	4379	4311	4311
q6	178	177	144	144
q7	1802	1675	1545	1545
q8	2501	2720	2570	2570
q9	7674	7343	7381	7343
q10	3799	4031	3745	3745
q11	507	427	414	414
q12	500	596	454	454
q13	2946	3269	2422	2422
q14	294	297	286	286
q15	866	792	800	792
q16	724	753	726	726
q17	1221	1498	1327	1327
q18	7231	6689	6677	6677
q19	935	930	920	920
q20	2097	2195	1996	1996
q21	3971	3484	3401	3401
q22	450	418	407	407
Total cold run time: 51305 ms
Total hot run time: 48830 ms

@doris-robot
Copy link

TPC-DS: Total hot run time: 153265 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpcds-tools
TPC-DS sf100 test result on commit 54e3714e51d0386e57bd04e1fcff0f4d21a6df96, data reload: false

query5	4355	661	539	539
query6	314	234	229	229
query7	4216	471	281	281
query8	334	227	226	226
query9	8697	2738	2718	2718
query10	500	362	337	337
query11	7515	5920	5553	5553
query12	181	133	123	123
query13	1255	448	353	353
query14	6232	3860	3562	3562
query14_1	2763	2802	2744	2744
query15	218	192	177	177
query16	992	444	436	436
query17	1077	690	591	591
query18	2485	434	334	334
query19	205	206	177	177
query20	136	128	123	123
query21	218	145	121	121
query22	5031	5083	4844	4844
query23	16011	15579	15433	15433
query23_1	15373	16234	15988	15988
query24	7708	1742	1303	1303
query24_1	1265	1325	1327	1325
query25	631	536	486	486
query26	1398	293	176	176
query27	3077	481	305	305
query28	4823	1951	1963	1951
query29	887	611	502	502
query30	316	259	218	218
query31	1457	1371	1592	1371
query32	82	76	72	72
query33	509	344	283	283
query34	919	940	614	614
query35	662	672	624	624
query36	1129	1143	1022	1022
query37	131	91	86	86
query38	2951	2901	2886	2886
query39	902	878	839	839
query39_1	830	827	834	827
query40	228	156	133	133
query41	62	61	59	59
query42	302	299	297	297
query43	238	258	213	213
query44	
query45	203	195	186	186
query46	910	984	625	625
query47	2115	2098	2036	2036
query48	325	321	224	224
query49	629	465	384	384
query50	713	269	216	216
query51	4090	4094	4003	4003
query52	284	295	277	277
query53	281	336	279	279
query54	320	269	260	260
query55	90	85	80	80
query56	311	319	309	309
query57	1376	1319	1259	1259
query58	284	284	262	262
query59	1317	1393	1286	1286
query60	337	335	315	315
query61	187	164	146	146
query62	626	589	523	523
query63	312	278	274	274
query64	5052	1270	984	984
query65	
query66	1460	469	351	351
query67	16389	16385	16305	16305
query68	
query69	384	301	281	281
query70	1007	978	962	962
query71	334	312	293	293
query72	2921	2689	2479	2479
query73	542	578	320	320
query74	9950	9958	9721	9721
query75	2881	2781	2500	2500
query76	2290	1042	685	685
query77	360	372	313	313
query78	11133	11259	10657	10657
query79	1146	800	588	588
query80	1314	613	543	543
query81	550	282	247	247
query82	999	146	119	119
query83	326	261	244	244
query84	251	118	94	94
query85	890	527	431	431
query86	422	299	310	299
query87	3164	3096	2992	2992
query88	3559	2682	2660	2660
query89	435	369	341	341
query90	1995	182	175	175
query91	163	161	133	133
query92	81	74	70	70
query93	929	832	503	503
query94	625	316	285	285
query95	576	387	318	318
query96	643	518	226	226
query97	2448	2489	2412	2412
query98	228	219	216	216
query99	993	1010	904	904
Total cold run time: 233458 ms
Total hot run time: 153265 ms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants