refactor: Change HANA trigger to be statement based#272
refactor: Change HANA trigger to be statement based#272stefanrudi wants to merge 2 commits intomainfrom
Conversation
There was a problem hiding this comment.
The refactor successfully migrates HANA triggers from row-level (FOR EACH ROW) to statement-level (FOR EACH STATEMENT) semantics, eliminating the CHANGE_TRACKING_DUMMY table workaround and replacing procedural variable-based logic with set-based INSERT … SELECT DISTINCT patterns. The overall approach is sound, but there are four issues worth addressing: a dead variable left from the old implementation (entityKey in generateDeleteTrigger), another dead code block (grandParentWhereSubquery in buildGrandParentObjectIDExpr), a correctness problem with SELECT DISTINCT in buildCompositionOfOneParentContext where the correlated parentKeyExpr subquery prevents effective deduplication across multiple child rows belonging to the same parent, and a potential SQL corruption risk in TriggerCQN2SQL where subquery-valued val strings (e.g. (SELECT … WHERE pk = nt.ID)) fall through to super.val() and get quoted as string literals instead of being emitted verbatim.
PR Bot Information
Version: 1.19.3 | 📖 Documentation | 🚨 Create Incident | 💬 Feedback
- LLM:
anthropic--claude-4.6-sonnet - Correlation ID:
a4f96c20-27a6-11f1-82b7-8bfcfe8a6519 - Event Trigger:
pull_request.opened
Refactor: Convert HANA Triggers to Statement-Level
♻️ Refactor: Migrated HANA database triggers from row-level (
FOR EACH ROW) to statement-level (FOR EACH STATEMENT) execution, replacing:old/:newrow references with transition table aliases (ot/ntviaREFERENCING OLD TABLE old_tab/REFERENCING NEW TABLE new_tab).Changes
This refactor eliminates the dependency on a dummy table (
CHANGE_TRACKING_DUMMY) and rewrites all trigger SQL generation to use set-basedINSERT ... SELECTpatterns instead of per-row procedural logic.index.cds: Removed theCHANGE_TRACKING_DUMMYentity definition that was previously required as a workaround for HANA HDI triggers.lib/TriggerCQN2SQL.js: Updated trigger row reference regex to supportnt/ottable aliases; removed the customfrom()override that handled the now-deleted dummy table.lib/hana/triggers.js: Switched all three trigger types (INSERT, UPDATE, DELETE) fromREFERENCING NEW/OLD ROWtoREFERENCING NEW/OLD TABLE ... FOR EACH STATEMENT. AddedgetFromClause()helper to generate the appropriateFROMclause with transition table aliases. Updated all row references fromnew/oldtont/ot. RewrotebuildInsertSQLto embed all column expressions directly in theUNION ALLsub-selects, removing the outer wrapping SELECT.lib/hana/composition.js: Updated all composition parent context builders to use transition table aliases (nt/ot) instead of:new/:oldrow references. Replaced proceduralDECLARE/IF/END IFSQL blocks with set-basedINSERT ... SELECT DISTINCTpatterns. RemovedbuildParentLookupSQL(row-level helper). AddedparentLookupExpras a correlated subquery for parent ID resolution.lib/hana/sql-expressions.js: Replaced all:old.column/:new.columnreferences withot.column/nt.column. UpdatednullSafeChanged,getValueExpr,getWhereCondition,buildAssocLookup,buildObjectIDExpr, andbuildGrandParentObjectIDExpraccordingly. ChangedSELECT.one.from(...)toSELECT.from(...)throughout.lib/hana/register.js: Removed the HDI compiler hook logic that injected the dummy CSV data and patched the CSN definition forCHANGE_TRACKING_DUMMY.tests/build/hana-build.test.js: Removed test assertion forCHANGE_TRACKING_DUMMYCSV generation.📬 Subscribe to the Hyperspace PR Bot DL to get the latest announcements and pilot features!
PR Bot Information
Version:
1.19.3| 📖 Documentation | 🚨 Create Incident | 💬 Feedbacka4f96c20-27a6-11f1-82b7-8bfcfe8a6519pull_request.openedanthropic--claude-4.6-sonnet