Repository navigation
refactor(engine): extract shared ES/OS helpers into esoscommon - #22432
Conversation
Move five byte-identical pure helpers from the Elasticsearch and OpenSearch backends into internal/engine/internal/esoscommon: - dedupeStrings -> DedupeStrings - totalHitsFromESResponse -> TotalHitsFromSearchResponse - buildMetadataIndexName -> BuildMetadataIndexName - Preprocess -> PreprocessSQL (with its two package-level regexes) - isTimeoutError -> IsTimeoutError Consolidate the seven duplicated tests into a single esoscommon copy and update all 24 production call sites. This is a behavior-preserving move: no wire-format, error-message or SQL-semantics changes.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
yuzhichang
left a comment
There was a problem hiding this comment.
Reviewed 356a928c..fdcddc0d (15 files, +479/−708).
Verdict: no blocking findings.
Verification of the move (static, against the base SHA):
dedupeStrings,totalHitsFromESResponse,isTimeoutError,Preprocessbodies were byte-identical betweenelasticsearch/andopensearch/at base; I diffed the removed and added bodies pairwise. The only deltas inesoscommonare the identifier renames (DedupeStrings,TotalHitsFromSearchResponse,IsTimeoutError,PreprocessSQL,preprocessWhitespaceRe), the parameter nameesResponse→searchResponse, and the neutralizedtotalHitscomment.- Import hygiene checks out:
errors,net,regexp,strings,tokenizerare gone from bothsql.gofiles and have zero remaining uses;fmtin bothcommon.gofiles stays used afterbuildMetadataIndexNameremoval (8 call sites each);encoding/json/bytes/io/httpremain used in themetadata.gofiles. - No stale call sites: a repo-wide grep for
buildMetadataIndexName,dedupeStrings,totalHitsFromESResponse,isTimeoutError,whitespaceRe,lktksMatchRe,Preprocessunderinternal/engine/{elasticsearch,opensearch}andinternal/engine/internal/esoscommonreturns only the new qualified names. ThededupeStringshits that remain outside are unrelated private helpers ininternal/agent/canvas,internal/service/document,internal/utility, andinternal/engine/infinitykeeps its own two-linepreprocessSQLfor a different SQL dialect — correctly left out of this change. - Import graph is acyclic:
esoscommon→tokenizer→internal/binding/internal/common, andesoscommonis only consumed byinternal/engine/elasticsearchandinternal/engine/opensearch, all under theinternal/engine/internal/visibility boundary. No duplicate declarations of the five exported symbols or the two regex vars in the target package. - Both backends'
RunSQLretry/timeout tests stay in place and now exerciseesoscommon.IsTimeoutErrorthrough the shared path;metadata_pushdown_test.goandTestPushdownCapSemanticswere updated to the qualified name rather than dropped, so the overflow-fallback contract is still covered.
One observation, not blocking and not introduced by this PR's production code: the new TestMain in internal/engine/internal/esoscommon/sql_test.go sets the process-global tokenizer engine to infinity, which now also applies to the pre-existing tests in that package (e.g. TestMapMemoryMessageToESDoc trivially passes either way). That is test-only scoping with no production effect, so it is not a merge blocker.
Summary
The Elasticsearch and OpenSearch backends carried five byte-identical pure helpers plus two package-level regexes. This PR moves them into
internal/engine/internal/esoscommonand consolidates the duplicated tests.Moved helpers:
dedupeStrings→esoscommon.DedupeStringstotalHitsFromESResponse→esoscommon.TotalHitsFromSearchResponse(dropped the misleading ES-only wording — OpenSearch calls it too)buildMetadataIndexName→esoscommon.BuildMetadataIndexNamePreprocess→esoscommon.PreprocessSQL(together with its two package-level regexes)isTimeoutError→esoscommon.IsTimeoutErrorAll 24 production call sites (12 ES / 12 OS) now use the shared versions. The seven duplicated test functions are merged into a single copy under
esoscommon, while engine-specificRunSQLtimeout/retry tests stay in their respective backends.Verification
bash build.sh --test ./internal/engine/...passes for every package, including both backends'RunSQLretry tests.elasticsearch/andopensearch/returns zero hits.whitespaceRe→preprocessWhitespaceRewas renamed, and thetotalHitscomment adopts the neutral wording from the OpenSearch copy.Scope
Behavior-preserving move only: no wire-format, error-message, or SQL-semantics changes.
buildBoolQueryFromConditionRaw(the ES/OS id-filter divergence) and theSearchResponse/searchAfterFetchertypes are deliberately left out.