Repository navigation
fix(#6409): normalize WITH-setting keys, refuse duplicates everywhere, fix node identity for CASE/ORDER BY/INSERT SET - #6413
Conversation
…e always refuses, and identity holds for CASE, ORDER BY and INSERT SET Follow-ups from #6401/#6407 collected while asking, for each parser node, "does identity actually work here now": - Item 1: IMPORT, EXPORT and BACKUP DATABASE built their WITH setting keys as a raw value parked in the node's inherited value slot, while REBUILD INDEX and REBUILD TYPE already built a proper identifier expression. All five now build the key the same way (new Expression(Identifier)), and every reader recovers it the same way (toString()), removing the defensive raw-value read in BackupDatabaseStatement that existed only because the old shape was fragile. - Item 2: only REBUILD TYPE refused a duplicate WITH setting; the other four silently accepted one, last one wins. A shared SQLASTBuilder#putSetting helper now refuses a repeat - keyed on the lowercased name, matching the equalsIgnoreCase every reader already uses - in all five statements. - Item 3: a sweep for parser nodes whose identity does not work, widening the corpus test #6401 left as a starting point. Confirmed and fixed: ArrayRangeSelector (a[1..3] under-matched, comparing unequal to itself), OrderByItem and InsertSetExpression (same under-match, breaking identity for any statement carrying an ORDER BY or an INSERT ... SET), and CaseExpression (the opposite failure: no identity override of its own meant it inherited MathExpression's, which reads fields CaseExpression never populates, so two structurally different CASE WHEN expressions over-matched as equal). - Item 4: SimpleNode.equals() indexed the other node's identity array by this node's length with no guard; harmless today because every override returns a fixed-length array, but one built conditionally would throw ArrayIndexOutOfBoundsException out of equals(). Added the length guard. - Item 5 (hashCode is now O(subtree)) is a documented cost, not a defect - no code change.
|
Tick the box to add this pull request to the merge queue (same as
|
ReviewWent through the diff in detail ( Correctness spot-checks that passed:
One documentation nit, no functional issue: the new Test coverage: genuinely thorough - the new I wasn't able to execute Overall: solid, well-scoped fix. No blocking issues found. |
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 6 |
🟢 Coverage 93.33% diff coverage · -6.54% coverage variation
Metric Results Coverage variation ✅ -6.54% coverage variation Diff coverage ✅ 93.33% diff coverage Coverage variation details
Coverable lines Covered lines Coverage Common ancestor commit (2982f55) 161073 128139 79.55% Head commit (a2d6227) 193617 (+32544) 141357 (+13218) 73.01% (-6.54%) Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch:
<coverage of head commit> - <coverage of common ancestor commit>Diff coverage details
Coverable lines Covered lines Diff coverage Pull request (#6413) 15 14 93.33% Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified:
<covered lines added or modified>/<coverable lines added or modified> * 100%
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
…tive readers Review on #6413 caught it: the comment said every reader recognises a setting with equalsIgnoreCase, which is only true for REBUILD INDEX and REBUILD TYPE. BackupDatabaseStatement's setting switch is exact-case, and Import/ExportDatabaseStatement hand the key through as-is to the integration-module setter, so for those three the lowercased dedup is a defensive choice rather than a fix for an existing case-insensitive read. No behavior change.
ReviewI read through the diff in detail ( Code quality / correctness
Pre-existing gap noticed (not introduced by this PR, out of scope for #6409 items 1-4)
Test coverage
Performance / security
Nothing blocking. Nice, tightly-scoped fix with good test coverage for each item. |
Code review on this PR caught it: ImportDatabaseStatement#equals() only compared url, and ExportDatabaseStatement#getIdentityElements() only listed url, so two statements with the same URL but different WITH settings compared equal. For IMPORT DATABASE this was the sharper case: a CSV import has no URL at all, so the settings are the statement. BackupDatabaseStatement already included settings in its identity; the other two now match it. Same over-match direction as the CaseExpression fix in this PR, on a statement node instead of an expression node.
ReviewWent through the diff in detail (couldn't execute CorrectnessThe core changes hold up under a field-by-field trace:
Style / process
Test coverageSolid - Minor observations (non-blocking)
Overall: a well-scoped, well-tested follow-up. No bugs found in the static review. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6413 +/- ##
==========================================
+ Coverage 70.87% 70.92% +0.04%
==========================================
Files 1855 1855
Lines 161073 161230 +157
Branches 33847 33865 +18
==========================================
+ Hits 114158 114348 +190
+ Misses 32975 32954 -21
+ Partials 13940 13928 -12 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
Follow-ups from #6401 (merged as #6407), collected while asking, for each parser node, "does identity actually work here now". Fixes items 1-4 of #6409; item 5 is a documented cost, not a defect, so no code change.
IMPORT DATABASE,EXPORT DATABASEandBACKUP DATABASEbuilt theirWITHsetting keys as a raw name parked in the node's inheritedvalueslot, whileREBUILD INDEXandREBUILD TYPEalready built a propernew Expression(Identifier). All five now build the key the same way, and every reader recovers it the same way (toString()). This also removes the defensive raw-valueread (and itsCommandExecutionExceptionfallback) inBackupDatabaseStatementthat existed only because the old shape was fragile - the shape that, pre-fix(#6401): a hash code is a property of the value, and an expression's value is every field that carries one #6407, made a backup asked to be encrypted get written in clear.REBUILD TYPErefused a duplicateWITHsetting; the other four silently accepted one, last one wins. A sharedSQLASTBuilder#putSettinghelper now refuses a repeat - keyed on the lowercased name, matching theequalsIgnoreCaseevery reader already uses to recognise a setting - in all five statements.Issue6401NodeIdentityTest#equalNodesAnswerEqualHashCodes). Confirmed and fixed:ArrayRangeSelector(a[1..3]) had nogetIdentityElements()at all - two parses compared unequal (under-match), exactly as Follow-ups from #6401: two shapes for a WITH settings key, a duplicate setting that means three different things, and a sweep for nodes whose identity does not work #6409 called out.OrderByItemandInsertSetExpressionare plain (non-SimpleNode) helper classes referenced from a parent's identity list, with noequals()/hashCode()of their own - same under-match, breaking identity for any statement carrying anORDER BYor anINSERT ... SET.CaseExpressionhad the opposite failure: no identity override of its own meant it inheritedMathExpression's, which readschildExpressions/operators- fieldsCaseExpressionnever populates - so two structurally differentCASE WHENexpressions over-matched as equal to each other. Confirmed with a throwaway reproduction before fixing (seedifferentCaseExpressionsAreNotTheSameExpressionin the test).SimpleNode.equals()indexed the other node's identity array by this node's length, with no guard. Harmless today because every override returns a fixed-length array literal, but a future override built conditionally would throwArrayIndexOutOfBoundsExceptionout ofequals(). Added the length guard the issue suggested.hashCode()being O(subtree) is an inherent, correctly-paid cost of hashing a tree, not a defect (per the issue's own text). No code change; nothing hashes a parsed node on a hot path today.Better alternative to what the issue proposed
The issue floated normalizing item 1's key shape and centralizing item 2's duplicate guard as two separate, independent changes. This PR does both through one shared
SQLASTBuilder#putSettinghelper: since the key shape and the dedup-key derivation both start from the sameIdentifier, doing them in one place means there is exactly one spot that knows how aWITHsetting key is built, for all five statements includingREBUILD TYPE(which previously duplicated the guard logic inline). That is also the "best alternative" for item 3: rather than hand-auditing the ~67getIdentityElements()overrides, the corpus test that #6401 already had was widened, which is what actually caughtOrderByItem,InsertSetExpressionand theCaseExpressionover-match - none of which the issue text had identified.Test plan
Issue6409FollowupsTest: all fiveWITH-settings statements build the same key shape and round-trip throughtoString(); all five refuse a duplicate setting (case-sensitive and case-insensitive); distinct settings still work;SimpleNode.equals()doesn't throw on a variable-length identity array.Issue6401NodeIdentityTest#equalNodesAnswerEqualHashCodeswithArrayRangeSelector,ORDER BY,CASE WHEN, and all fiveWITH-settings statements; addeddifferentCaseExpressionsAreNotTheSameExpressionfor the over-match direction.ImportDatabaseStatementTestParserTest,ExportDatabaseStatementTestParserTest) that read the old raw-valueshape directly.mvn -o -pl engine -am teston: the fullcom.arcadedb.query.sql.parserpackage (389 tests), the full ORDER BY suite acrosssql,sql.executor,indexandselectpackages,SQLCaseTest,DatabaseAdminStatementsTest,RebuildTypeRepartitionTest- all green.mvn -o compile- green.🔗 Closes #6409