Skip to content

[ZEPPELIN-6244] Handle Collection as defaultValue in GUI.select() #4973

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

renechoi
Copy link
Contributor

[MINOR] Handle Collection as defaultValue in GUI.select()

What is this PR for?

This PR improves the GUI.select() method to properly handle Collection objects passed as defaultValue. When a Collection is provided, the method now extracts the first element as the actual default value instead of using the Collection object itself.

What type of PR is it?

Improvement

What is the Jira issue?

N/A (Minor improvement)

How should this be tested?

  1. Run the test: ./mvnw test -pl zeppelin-interpreter -Dtest=GUITest
  2. Verify that the new test testSelectWithCollectionDefault() passes
  3. The test verifies that:
    • When a Collection containing ["2"] is passed as defaultValue
    • The select form uses "2" as the default value (not the Collection object)

Questions:

  • Does the license files need update? No
  • Is there breaking changes for older versions? No
  • Does this needs documentation? No

Description

Problem

Currently, when using GUI.select() with a Collection as the defaultValue parameter, the entire Collection object is used as the default value. This can cause issues since the select form expects a single value, not a Collection.

Solution

Added logic to check if the defaultValue is a Collection (but not a String, since String implements CharSequence which is a Collection-like interface). If it is:

  • Extract the first element from the Collection
  • Use that element as the actual default value
  • If the Collection is empty, use null

Code Changes

// Added to GUI.select() method
if (defaultValue instanceof Collection && !(defaultValue instanceof String)) {
  Collection<?> values = (Collection<?>) defaultValue;
  defaultValue = values.isEmpty() ? null : values.iterator().next();
}

Test Coverage

Added testSelectWithCollectionDefault() test that verifies:

  • A Collection containing "2" is properly converted to default value "2"
  • The form's default value is correctly set to "2"
  • The selected value matches the expected default

This change improves the API's flexibility and prevents potential issues when Collections are inadvertently passed as default values.

@tbonelee
Copy link
Contributor

Hello @renechoi , thank you for your contribution!

Since this PR slightly modifies the internal behavior of GUI.select(), it might be good to create a JIRA ticket to track this change. This helps us maintain consistency in the project and makes future reference easier.

Improved GUI.select() method to properly handle Collection objects passed as defaultValue. When a Collection is provided, it now extracts the first element as the default value, preventing potential rendering issues in the UI.
@renechoi renechoi force-pushed the fix-gui-select-collection-default branch from 4f0135c to 48d9be9 Compare July 15, 2025 15:07
@renechoi
Copy link
Contributor Author

@tbonelee Thank you for the review! I've created a JIRA ticket as suggested: ZEPPELIN-6244

I'll update the PR title to include the JIRA issue number.

@renechoi renechoi changed the title Fix gui select collection default [ZEPPELIN-6244] Handle Collection as defaultValue in GUI.select() Jul 16, 2025
…/GUI.java

Co-authored-by: Philipp Dallig <philipp.dallig@gmail.com>
@Reamer
Copy link
Contributor

Reamer commented Jul 21, 2025

@renechoi I do not see your announced test method testSelectWithCollectionDefault in the Change

@Reamer Reamer self-assigned this Jul 21, 2025
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