Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge release/v1.1.0 to develop #5130

Merged
merged 6 commits into from
Nov 18, 2024
Merged

Merge release/v1.1.0 to develop #5130

merged 6 commits into from
Nov 18, 2024

Conversation

voxel51-bot
Copy link
Collaborator

@voxel51-bot voxel51-bot commented Nov 16, 2024

Merge release/v1.1.0 to develop

Summary by CodeRabbit

  • New Features

    • Introduced additional filtering options in the Lightning queries, allowing for more complex query capabilities.
    • Added a new optional field filters to the LightningPathInput and DistinctQuery classes.
  • Improvements

    • Enhanced search functionality with refined filter management.
    • Updated logic for handling filters to improve user experience.
    • Streamlined deserialization process for mask data extraction.
  • Bug Fixes

    • Improved error handling in the getTarget method to prevent out-of-bounds access.

Copy link
Contributor

coderabbitai bot commented Nov 16, 2024

Walkthrough

The changes in this pull request involve modifications to several files related to the filtering logic within the application. Key updates include enhancements to the stringSearchResults selectorFamily to better manage filters, the introduction of a new filters parameter in the lightningStringResults selectorFamily, and adjustments to the LightningPathInput and DistinctQuery classes to incorporate filtering capabilities. Additionally, the State namespace has been reorganized for improved flexibility in filter handling.

Changes

File Path Change Summary
app/packages/core/src/components/Filters/StringFilter/state.ts Updated stringSearchResults to manage filters more effectively, introducing a filters variable.
app/packages/core/src/components/Filters/StringFilter/useSelected.ts Modified logic to include isFrameField for determining useSearch conditions.
app/packages/state/src/recoil/filters.ts Changed import of State to a type-only import.
app/packages/state/src/recoil/pathData/lightningString.ts Added filters parameter to lightningStringResults selectorFamily.
app/packages/state/src/recoil/types.ts Removed CategoricalFilter and Filter types; introduced FilterValues and updated Filter interface.
app/schema.graphql Added optional filters field to LightningPathInput input type.
fiftyone/server/lightning.py Enhanced query capabilities by adding filters to LightningPathInput and DistinctQuery classes; modified related functions.
app/packages/looker/src/overlays/segmentation.ts Improved error handling in getTarget method of SegmentationOverlay class.
app/packages/looker/src/worker/deserializer.ts Introduced extractSerializedMask function to streamline mask data extraction in deserialization.

Possibly related PRs

  • Coinciding filter results for QP sidebar #5121: The changes in the main PR involve modifications to the stringSearchResults selectorFamily in the StringFilter/state.ts file, which directly relates to the filtering mechanism discussed in the retrieved PR that also focuses on filter handling in the sidebar.
  • extend compatibility of array deserialization in lookers #5132: The changes in the main PR enhance the filtering logic in the StringFilter/state.ts, which aligns with the modifications in the SegmentationOverlay class in the retrieved PR that improve error handling related to target indexing, indicating a focus on robust filtering and selection mechanisms.

Suggested reviewers

  • findtopher

🐇 In the fields where we play,
Filters now lead the way!
With logic bright and clear,
Searching brings us cheer.
New paths to explore,
Let’s hop and filter more! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (5)
app/packages/state/src/recoil/pathData/lightningString.ts (1)

11-11: Add JSDoc comments explaining the filters parameter

Consider adding documentation to explain:

  • The purpose and expected structure of the filters parameter
  • How it affects the results
  • Example usage
+  /**
+   * @param filters - Serializable filter criteria to narrow down the results
+   * @example
+   * {
+   *   path: "metadata.tags",
+   *   filters: { field: "value" }
+   * }
+   */
   filters: SerializableParam;
app/packages/core/src/components/Filters/StringFilter/useSelected.ts (1)

38-40: Consider extracting complex condition into a named function

The condition for determining useSearch is becoming complex with multiple checks. Consider extracting it into a descriptive function to improve readability and maintainability.

+ const shouldDisableSearch = (path: string, queryPerformance: boolean, isFrameField: boolean, modal: boolean) => {
+   return path === "_label_tags" && queryPerformance && !isFrameField && !modal;
+ };

  return {
    results,
-   useSearch:
-     path === "_label_tags" && queryPerformance && !isFrameField && !modal
-       ? undefined
-       : useSearch,
+   useSearch: shouldDisableSearch(path, queryPerformance, isFrameField, modal) ? undefined : useSearch,
    showSearch: Boolean(shown) && !boolean,
  };
app/packages/core/src/components/Filters/StringFilter/state.ts (1)

71-74: Consider type safety and performance improvements

While the current implementation is functionally correct, consider these improvements:

  1. Add explicit type annotations for better type safety
  2. Use object spread for better performance when filtering out a single key
-        const filters = Object.fromEntries(
-          Object.entries(get(fos.filters) || {}).filter(([p]) => p !== path)
-        );
+        const { [path]: _, ...filters } = get(fos.filters) || {};
app/packages/state/src/recoil/types.ts (1)

169-171: Consider adding JSDoc documentation for the Filter interface.

The new Filter interface provides good flexibility with its index signature. However, adding documentation would help other developers understand its purpose and usage better.

Add documentation like this:

+/**
+ * Represents a flexible filter structure where each key can hold either a single value
+ * or an array of values of various primitive types.
+ */
 export interface Filter {
   [key: string]: FilterValues | Array<FilterValues>;
 }
app/schema.graphql (1)

458-458: LGTM! Consider adding documentation for the filters field.

The addition of the optional filters field is well-structured and maintains backward compatibility. The use of the BSON scalar type provides flexibility for complex filtering criteria.

Consider adding a documentation string to describe the purpose and expected format of the filters, similar to how the exclude field is documented. Example:

input LightningPathInput {
  path: String!
  """
  exclude these values from results
  """
  exclude: [String!] = null
  first: Int = 200
  search: String = null
+ """
+ additional filtering criteria in BSON format
+ """
  filters: BSON = null
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 31a53b9 and 57858ae.

⛔ Files ignored due to path filters (1)
  • app/packages/relay/src/queries/__generated__/lightningQuery.graphql.ts is excluded by !**/__generated__/**, !**/__generated__/**
📒 Files selected for processing (7)
  • app/packages/core/src/components/Filters/StringFilter/state.ts (1 hunks)
  • app/packages/core/src/components/Filters/StringFilter/useSelected.ts (1 hunks)
  • app/packages/state/src/recoil/filters.ts (1 hunks)
  • app/packages/state/src/recoil/pathData/lightningString.ts (1 hunks)
  • app/packages/state/src/recoil/types.ts (1 hunks)
  • app/schema.graphql (1 hunks)
  • fiftyone/server/lightning.py (8 hunks)
✅ Files skipped from review due to trivial changes (1)
  • app/packages/state/src/recoil/filters.ts
🧰 Additional context used
📓 Path-based instructions (4)
app/packages/core/src/components/Filters/StringFilter/state.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/core/src/components/Filters/StringFilter/useSelected.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/state/src/recoil/pathData/lightningString.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/state/src/recoil/types.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

🔇 Additional comments (15)
app/packages/state/src/recoil/pathData/lightningString.ts (1)

7-12: Verify the impact of making filters a required parameter

Adding a required filters parameter to the selector's parameter object could be a breaking change. Existing code that uses lightningStringResults will need to be updated to provide this parameter.

app/packages/core/src/components/Filters/StringFilter/useSelected.ts (1)

32-32: LGTM: Clean addition of frame field check

The addition of isFrameField check follows the established pattern and naming conventions in the codebase.

app/packages/core/src/components/Filters/StringFilter/state.ts (1)

81-81: LGTM! Verify lightningStringResults compatibility

The addition of the filters parameter is well-integrated into the existing structure.

Let's verify that the lightningStringResults selector properly handles the new filters parameter:

✅ Verification successful

The filters parameter is properly handled by lightningStringResults selector

The verification confirms that:

  • The lightningStringResults selector is defined with filters: SerializableParam in its parameter type
  • The usage in StringFilter correctly passes the filters parameter
  • The implementation follows Recoil's selectorFamily pattern
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for lightningStringResults definition and usage to ensure parameter compatibility
ast-grep --pattern 'export const lightningStringResults = selectorFamily<$_>({
  $$$
  get: ({ $$$, filters }) => $_
  $$$
})'

Length of output: 128


Script:

#!/bin/bash
# Let's try a broader search for lightningStringResults definition
rg "lightningStringResults" -A 10

Length of output: 3545

app/packages/state/src/recoil/types.ts (2)

167-167: LGTM! Well-defined union type for filter values.

The FilterValues type effectively covers all possible primitive value types that might be needed for filtering, while keeping the type definition clean and maintainable.


167-171: Verify compatibility with existing filter implementations.

The change from CategoricalFilter<T> to this new filter structure is a significant change that could affect existing implementations.

Let's check for potential compatibility issues:

✅ Verification successful

Based on the analysis of the code changes and search results, I can now provide a final response:

Type changes are safe and consistent with the codebase

The change from CategoricalFilter<T> to the new Filter interface with FilterValues type is well-aligned with the codebase's existing filter implementations. The search results show:

  1. The new type definition matches existing usage patterns across the codebase
  2. The type is already used in key filter-related files like filters.ts, pathFilters/, etc.
  3. The change provides better type safety by explicitly defining allowed filter value types
  4. No incompatible usages were found in the codebase
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for existing filter usage patterns that might need updates

# Look for existing filter usage patterns
echo "Searching for filter usage patterns..."
rg -t typescript "CategoricalFilter|Filter\s*[:<]" --glob '!{node_modules,dist}/**'

# Look for potential type errors in filter implementations
echo "Searching for filter implementations..."
ast-grep --pattern 'interface $name implements Filter {
  $$$
}'

Length of output: 363


Script:

#!/bin/bash
# Let's try a different approach to search for filter usage patterns

# Search for Filter type usage
echo "Searching for Filter type usage..."
rg "Filter" -A 3 -B 3 --type ts

# Search for specific filter value patterns
echo "Searching for filter value assignments..."
rg ":\s*(string|boolean|number|null)\s*\[\s*\]" --type ts

# Look for array filter values
echo "Searching for array filter values..."
rg "Array<.*>" --type ts

Length of output: 333418

fiftyone/server/lightning.py (10)

25-27: Appropriate Addition of Necessary Imports

The added imports of BSON and get_view are necessary for the new functionality involving filters and are correctly included.


160-160: Consistent Addition of filters to DistinctQuery

The filters field is added to the DistinctQuery class, aligning with the changes made in LightningPathInput. This ensures that filter parameters propagate correctly through the query processing logic.


Line range hint 265-281: Proper Propagation of filters in Query Preparation

Assigning d["filters"] = path.filters correctly propagates the filters parameter when preparing the query dictionary. This ensures that filters provided by the user are included in the query execution.


292-295: Update Function _do_async_pooled_queries Signature to Include dataset

The function _do_async_pooled_queries now includes dataset as a parameter, allowing for proper context during asynchronous query execution. Ensure all calls to this function are updated accordingly.


306-306: Update Function _do_async_query Signature to Include dataset

By adding dataset to _do_async_query, the function now has access to the dataset context necessary for executing queries with filters. Verify that all invocations of this function pass the correct dataset argument.


314-314: Pass dataset to _do_distinct_pipeline in _do_async_query

Passing dataset to _do_distinct_pipeline ensures that the dataset context is available when constructing the aggregation pipeline, particularly when applying filters.


354-356: Integrate filters into the Aggregation Pipeline in _do_distinct_pipeline

The code correctly incorporates filters into the aggregation pipeline using:

if query.filters:
    pipeline += get_view(dataset, filters=query.filters)._pipeline()

This allows the filters to be applied effectively in the distinct pipeline.


368-371: Ensure Function Signatures of _match_arrays and _unwind Include dataset

The dataset parameter is now passed to _match_arrays and _unwind. Confirm that the function definitions for these helper functions have been updated accordingly and that they utilize the dataset parameter as intended.


42-42: ⚠️ Potential issue

Ensure Secure Handling of filters Input in LightningPathInput

By adding filters: t.Optional[BSON] = None to LightningPathInput, the code now accepts user-provided BSON filters. Verify that these filters are properly validated and sanitized to prevent security vulnerabilities such as injection attacks.

Consider auditing the get_view function to ensure it safely processes the filters input without exposing the system to injection risks.


360-367: ⚠️ Potential issue

Handle Potential Exceptions When Constructing ObjectId from query.search

When constructing an ObjectId using ObjectId(f"{query.search}{add}"), ensure that query.search contains valid hexadecimal characters and an appropriate length. Invalid input could raise a bson.errors.InvalidId exception.

Apply this diff to validate query.search before constructing the ObjectId:

 if query.search:
     if query.is_object_id_field:
         add = (_TWENTY_FOUR - len(query.search)) * "0"
-        value = {"$gte": ObjectId(f"{query.search}{add}")}
+        try:
+            obj_id = ObjectId(f"{query.search}{add}")
+            value = {"$gte": obj_id}
+        except bson.errors.InvalidId:
+            # Handle invalid ObjectId input gracefully
+            value = {"$gte": ObjectId("0" * _TWENTY_FOUR)}
     else:
         value = Regex(f"^{query.search}")

Alternatively, validate query.search to ensure it's a valid hexadecimal string before using it to construct an ObjectId.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
app/packages/looker/src/worker/deserializer.ts (2)

3-14: Consider strengthening type safety

The function implementation is clean and effectively centralizes the mask extraction logic. However, the type safety could be improved.

Consider this type-strengthened version:

-const extractSerializedMask = (
-  label: object,
-  maskProp: string
-): string | undefined => {
+interface BinaryData {
+  $binary: {
+    base64: string;
+  };
+}
+
+type Label = {
+  [key: string]: string | BinaryData | unknown;
+};
+
+const extractSerializedMask = (
+  label: Label,
+  maskProp: string
+): string | undefined => {

38-41: Consider further reducing code duplication

While the mask extraction has been centralized, there's still significant duplication in the buffer management code across Detection, Heatmap, and Segmentation methods.

Consider extracting the common buffer management logic:

+const createBufferedMask = (serializedData: string, buffers: ArrayBuffer[]) => {
+  const data = deserialize(serializedData);
+  const [height, width] = data.shape;
+  const mask = {
+    data,
+    image: new ArrayBuffer(width * height * 4),
+  };
+  buffers.push(data.buffer);
+  buffers.push(mask.image);
+  return mask;
+};

 Heatmap: (label, buffers) => {
   const serializedMask = extractSerializedMask(label, "map");
   if (serializedMask) {
-    const data = deserialize(serializedMask);
-    const [height, width] = data.shape;
-    label.map = {
-      data,
-      image: new ArrayBuffer(width * height * 4),
-    };
-    buffers.push(data.buffer);
-    buffers.push(label.map.image);
+    label.map = createBufferedMask(serializedMask, buffers);
   }
 },
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 57858ae and b3bc405.

📒 Files selected for processing (2)
  • app/packages/looker/src/overlays/segmentation.ts (1 hunks)
  • app/packages/looker/src/worker/deserializer.ts (3 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
app/packages/looker/src/overlays/segmentation.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/looker/src/worker/deserializer.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

🔇 Additional comments (3)
app/packages/looker/src/worker/deserializer.ts (2)

18-21: LGTM! Clean refactoring of mask extraction

The change successfully implements the centralized mask extraction while maintaining the existing buffer management logic.


54-57: Verify consistent behavior across all deserialization methods

The implementation is consistent with other methods. Let's verify that all methods handle the mask extraction and buffer management consistently.

✅ Verification successful

Let me analyze the code to verify the consistency of mask handling across deserialization methods.


Mask deserialization is consistent across all methods

The verification shows that all deserialization methods follow the same pattern:

  • Use extractSerializedMask with appropriate property name ("mask" or "map")
  • Call deserialize on the extracted data
  • Store the result in the label's corresponding property

The implementation is consistent and safe across Detection, Segmentation, and Heatmap types.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify consistent mask handling across all methods
# Look for any inconsistencies in how masks are handled

# Search for all mask-related property accesses
rg -U "mask|map" --type ts

# Search for buffer management patterns
rg -U "ArrayBuffer|buffer" --type ts

# Look for any other deserialization methods we might have missed
ast-grep --pattern 'const $_ = deserialize($_)'

Length of output: 136882


Script:

#!/bin/bash
# Search for all deserialization methods and their implementations
ast-grep --pattern 'DeserializerFactory.$_ = ($_, $_) => {
  $$$
}'

# Search for all mask extraction patterns
ast-grep --pattern 'extractSerializedMask($_, $_)'

# Search for all deserialize function calls
ast-grep --pattern 'deserialize($_)'

Length of output: 905

app/packages/looker/src/overlays/segmentation.ts (1)

276-279: LGTM! Robust error handling improvement.

The enhanced bounds checking is a solid defensive programming practice that prevents potential runtime errors from:

  • Accessing an undefined targets array
  • Out-of-bounds array access

This makes the code more robust and maintainable.

@benjaminpkane benjaminpkane merged commit 4608a23 into develop Nov 18, 2024
14 checks passed
@benjaminpkane benjaminpkane deleted the merge/release/v1.1.0 branch November 18, 2024 14:18
@coderabbitai coderabbitai bot mentioned this pull request Jan 30, 2025
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants