refactor: consolidate duplicated array element type mapping#3401
refactor: consolidate duplicated array element type mapping#3401pymilvus-bot wants to merge 1 commit intomasterfrom
Conversation
…le dict The DataType-to-protobuf-attribute mapping for array elements (e.g. INT64 -> long_data, VARCHAR -> string_data) was duplicated across four functions in entity_helper.py and search_result.py. Introduce a single _ARRAY_ELEMENT_TYPE_TO_ATTR dict and rewrite the helpers to use it: - Merge extract_array_row_data_with_validity / _no_validity into one extract_array_rows(field_data, rows, count, has_valid) function. - Simplify extract_array_row_data (single-row) to a two-line lookup. - Simplify extract_array_row_data in search_result.py to use the shared mapping via entity_helper._ARRAY_ELEMENT_TYPE_TO_ATTR. Net result: -86 lines, one source of truth for the mapping. Signed-off-by: pymilvus-bot <pymilvus@zilliz.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3401 +/- ##
==========================================
+ Coverage 90.76% 90.82% +0.05%
==========================================
Files 64 64
Lines 13887 13837 -50
==========================================
- Hits 12605 12567 -38
+ Misses 1282 1270 -12 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Reposting from bot account (pymilvus-bot) — auto-review must come from bot.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: pymilvus-bot The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Clean refactor — consolidating four copies of the same mapping into one dict is the right call, and replacing the list-comprehension side-effect pattern with A few things worth addressing: 1. Private symbol accessed cross-module 2. Constant defined below first use 3. Silent skip for unsupported types in 4. Docstring None of these are blockers — the core change is correct and a clear improvement. |
Summary
The DataType-to-protobuf-attribute mapping for array elements (e.g.
INT64 -> long_data,VARCHAR -> string_data) was copy-pasted acrossfour separate functions in
entity_helper.pyandsearch_result.py.This PR introduces a single
_ARRAY_ELEMENT_TYPE_TO_ATTRdict andrewrites the helpers to use it:
extract_array_row_data_with_validity/_no_validityinto oneextract_array_rows(field_data, rows, count, has_valid)functionextract_array_row_data(single-row variant) to a two-linedict lookup
extract_array_row_datainsearch_result.pyto use theshared mapping
Net result: -86 lines, one source of truth for the mapping, easier
to maintain when new array element types are added.
Signed-off-by: pymilvus-bot pymilvus@zilliz.com