发布

  • [OPIK-2875][BE][FE] dataset item tagging and filtering (#4108)

    frostbyte_neo 发布于 2025-11-18 16:06:44 +00:00

    • OPIK-3102 introduce dataset item edit endpoint

    • OPIK-3102 changed PUT to PATCH

    • OPIK-2875 tags support implementation

    • OPIK-2875 fix tags display and add bulk tag operations for dataset items

    • Fix DatasetItemResultMapper to properly map tags field from database
    • Create AddTagDialog component for bulk tag operations (similar to traces)
    • Add 'Add tags' button to DatasetItemsActionsPanel with Tag icon
    • Update useDatasetItemUpdateMutation to invalidate both item and list queries
    • Bulk operations send individual PATCH requests per item as designed
    • Tags now display correctly in side panel and are persisted to database
    • OPIK-2875 fix state updates for tag operations
    • Fixed query key mismatch in useDatasetItemUpdateMutation
      • Changed 'datasetItem' to 'dataset-item' (singular)
      • Changed 'datasetItems' to 'dataset-items' with datasetId parameter
    • Added datasetId parameter to useDatasetItemUpdateMutation
    • Pass datasetId through component hierarchy:
      • DatasetItemsPage -> DatasetItemPanelContent
      • DatasetItemsActionsPanel -> AddTagDialog
    • Tags now update immediately in UI without manual refresh
    • Both individual tag management and bulk operations update state correctly
    • OPIK-2875 fix action buttons layout to match spans page behavior
    • Changed parent container to use flex-wrap with gap-x-8 gap-y-2
    • Removed flex-wrap from right button group to keep buttons together
    • Uses justify-between to create clean break between Search and buttons
    • Wide screens: Search left, buttons right (single line)
    • Narrow screens: Search line 1, all buttons together line 2
    • Matches spans page responsive behavior exactly
    • OPIK-2875 add filters button for filtering dataset items by tags
    • Added FiltersButton component next to Search input
    • Created filtersColumnData with only Tags column (COLUMN_TYPE.list)
    • Added filters state using JsonParam from query params
    • Passed filters to useDatasetItemsList API calls
    • Filters UI matches traces/spans page behavior
    • Users can now filter dataset items by tags using 'contains' operator
    • OPIK-2875 fix dataset items filtering by tags and add comprehensive tests

    Backend changes:

    • Added TAGS field mapping to DATASET_ITEM_FIELDS_MAP in FilterQueryBuilder
    • Added DatasetItemField.TAGS to DATASET_ITEM filter strategy
    • Added comprehensive tests for tag add/update/remove operations
    • Added test for filtering dataset items by tags using CONTAINS operator

    Test coverage:

    • patchDatasetItem__whenAddingTags__thenSucceed
    • patchDatasetItem__whenUpdatingTags__thenSucceed
    • patchDatasetItem__whenRemovingAllTags__thenSucceed
    • getDatasetItemsByDatasetId__whenFilteringByTags__thenSucceed
    • OPIK-2875 Add comprehensive documentation for dataset item tagging

    Documentation changes:

    • Added 'Managing dataset item tags' section to manage_datasets.mdx
    • Documented use cases for tags (categorization, filtering, workflow organization)
    • Provided step-by-step instructions for adding tags (individual and batch)
    • Explained filtering dataset items by tags

    The documentation covers all aspects of the tagging feature:

    • Individual tag management from the details panel
    • Batch tag operations via the 'Add tags' button
    • Filtering dataset items using the Filters button
    • OPIK-2875 refactor PATCH tests to use DatasetResourceClient helper methods
    • Added patchDatasetItem() and callPatchDatasetItem() methods to DatasetResourceClient
    • Replaced all explicit PATCH calls in DatasetsResourceTest with helper methods
    • Fixed null vs empty array issue in parametrized patch tests by explicitly setting tags to Set.of()

    Benefits:

    • Improved test code maintainability and consistency
    • Centralized PATCH endpoint logic in resource client
    • Follows established pattern used by other resource operations (GET, POST, DELETE)
    • All tests pass successfully
    • OPIK-2875 address PR review feedback
    • Changed AddTagDialog state from 'boolean | number' to 'boolean'

      • Renamed 'open' state to 'addTagDialogOpen' in DatasetItemsActionsPanel
      • Updated setOpen(3) to setAddTagDialogOpen(true)
      • Changed open={open === 3} to open={addTagDialogOpen}
      • Simplified Dialog component to use open directly instead of Boolean(open)
    • Removed flex-wrap from DatasetItemsPage action buttons container

      • Changed from 'flex flex-wrap ... gap-x-8 gap-y-2' to 'flex ... gap-8'
      • Prevents unwanted button location changes on different screen sizes
    • Changed mutation params to accept full Partial instead of just tags

    • Updated parameter from 'tags: string[]' to 'item: Partial'

    • Updated all usages in DatasetItemPanelContent and AddTagDialog to wrap tags in item object

    • Makes the hook reusable for updating any dataset item field, not just tags

    • Maintains backward compatibility with datasetId and itemId parameters

    Example usage:

    • OPIK-2875 fix BE tests

    The tags field was causing a 500 error in queries with experiment items:
    'Column di.tags is not under aggregate function and not in GROUP BY keys'

    Solution:

    • Use any(di.tags) aggregate function instead of di.tags in SELECT
    • This follows ClickHouse best practices for non-grouped fields
    • Only changed tags field, left trace_id/span_id/source unchanged
    • Tests now pass including CrossProjectTracesDuplicateTest

    The error occurred because the query groups by dataset_item_id but selects
    di.tags without aggregation. Using any() is safe since all rows with the
    same dataset_item_id have the same tags value.

    • OPIK-2875 PR comments: add tags to GROUP BY clause per PR feedback

    Reverted Revision 12 based on PR feedback - tags should be in GROUP BY
    clause rather than using any() aggregate function.

    Changes:

    • Added di.tags to GROUP BY clause in SELECT_DATASET_ITEMS_WITH_EXPERIMENT_ITEMS
    • Changed back from any(di.tags) to di.tags in SELECT clause
    • This matches the pattern for other dataset item fields (trace_id, span_id, source)

    All tests pass including CrossProjectTracesDuplicateTest.

    下载附件