-
Notifications
You must be signed in to change notification settings - Fork 117
feat(frontend): Support for UDF Ui Parameter #4268
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
carloea2
wants to merge
23
commits into
apache:main
Choose a base branch
from
carloea2:feat/ui-parameter
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
f206864
v1
carloea2 299dc0f
Merge branch 'apache:main' into feat/ui-parameter
carloea2 5b29ad8
v2
carloea2 6258a99
Merge branch 'feat/ui-parameter' of https://github.com/carloea2/texer…
carloea2 3550ccd
v2
carloea2 7a210a7
py2udf
carloea2 4a56861
v2.1
carloea2 16f89ac
Merge branch 'feat/ui-parameter' of https://github.com/carloea2/texer…
carloea2 5aa3f4e
vnt
carloea2 1d82c9a
v2
carloea2 b36628f
v2.1
carloea2 dd46609
Update ui-udf-parameters.component.scss
carloea2 2c8167b
v2.1
carloea2 06d7f5a
v3
carloea2 ac2b265
v3
carloea2 c8239c2
Merge branch 'main' into feat/ui-parameter
carloea2 edd3869
Merge branch 'main' into feat/ui-parameter
carloea2 0c9f0cd
Merge branch 'main' into feat/ui-parameter
chenlica 6ff1e86
v3CopilotVs
carloea2 ce96e19
Merge branch 'main' into feat/ui-parameter
carloea2 52845c3
Update PythonUdfUiParameterInjectorSpec.scala
carloea2 b863937
Merge branch 'feat/ui-parameter' of https://github.com/carloea2/texer…
carloea2 06ba53b
v4
carloea2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
154 changes: 154 additions & 0 deletions
154
amber/src/main/python/pytexera/udf/test_udf_operator.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| import datetime | ||
| from typing import Iterator, Optional | ||
|
|
||
| import pytest | ||
|
|
||
| from core.models.type.large_binary import largebinary | ||
| from pytexera import AttributeType, Tuple, TupleLike, UDFOperatorV2 | ||
| from pytexera.udf.udf_operator import _UiParameterSupport | ||
|
|
||
|
|
||
| class InjectedParametersOperator(UDFOperatorV2): | ||
| def _texera_injected_ui_parameters(self): | ||
| return { | ||
| "count": "7", | ||
| "enabled": "yes", | ||
| "created_at": "2024-01-01T00:00:00", | ||
| } | ||
|
|
||
| def open(self): | ||
| self.count_parameter = self.UiParameter("count", AttributeType.INT) | ||
| self.enabled_parameter = self.UiParameter( | ||
| name="enabled", type=AttributeType.BOOL | ||
| ) | ||
| self.created_at_parameter = self.UiParameter( | ||
| "created_at", type=AttributeType.TIMESTAMP | ||
| ) | ||
|
|
||
| def process_tuple(self, tuple_: Tuple, port: int) -> Iterator[Optional[TupleLike]]: | ||
| yield tuple_ | ||
|
|
||
|
|
||
| class ConflictingParameterOperator(UDFOperatorV2): | ||
| def _texera_injected_ui_parameters(self): | ||
| return {"duplicate": "1"} | ||
|
|
||
| def open(self): | ||
| self.UiParameter("duplicate", AttributeType.INT) | ||
| self.UiParameter("duplicate", AttributeType.STRING) | ||
|
|
||
| def process_tuple(self, tuple_: Tuple, port: int) -> Iterator[Optional[TupleLike]]: | ||
| yield tuple_ | ||
|
|
||
|
|
||
| class FirstIndependentParameterOperator(UDFOperatorV2): | ||
| def _texera_injected_ui_parameters(self): | ||
| return {"count": "1"} | ||
|
|
||
| def open(self): | ||
| self.count_parameter = self.UiParameter("count", AttributeType.INT) | ||
|
|
||
| def process_tuple(self, tuple_: Tuple, port: int) -> Iterator[Optional[TupleLike]]: | ||
| yield tuple_ | ||
|
|
||
|
|
||
| class SecondIndependentParameterOperator(UDFOperatorV2): | ||
| def _texera_injected_ui_parameters(self): | ||
| return {"count": "2"} | ||
|
|
||
| def open(self): | ||
| self.count_parameter = self.UiParameter("count", AttributeType.INT) | ||
|
|
||
| def process_tuple(self, tuple_: Tuple, port: int) -> Iterator[Optional[TupleLike]]: | ||
| yield tuple_ | ||
|
|
||
|
|
||
| class TestUiParameterSupport: | ||
| def test_injected_values_are_applied_before_open(self): | ||
| operator = InjectedParametersOperator() | ||
|
|
||
| operator.open() | ||
|
|
||
| assert operator.count_parameter.value == 7 | ||
| assert operator.enabled_parameter.value is True | ||
| assert operator.created_at_parameter.value == datetime.datetime( | ||
| 2024, 1, 1, 0, 0 | ||
| ) | ||
|
|
||
| def test_duplicate_parameter_names_with_conflicting_types_raise(self): | ||
| operator = ConflictingParameterOperator() | ||
|
|
||
| with pytest.raises(ValueError) as exc_info: | ||
| operator.open() | ||
|
|
||
| assert "Duplicate UiParameter name 'duplicate'" in str(exc_info.value) | ||
|
|
||
| @pytest.mark.parametrize( | ||
| ("raw_value", "attr_type", "expected"), | ||
| [ | ||
| ("hello", AttributeType.STRING, "hello"), | ||
| ("7", AttributeType.INT, 7), | ||
| ("99", AttributeType.LONG, 99), | ||
| ("3.14", AttributeType.DOUBLE, 3.14), | ||
| ("yes", AttributeType.BOOL, True), | ||
| ("payload", AttributeType.BINARY, b"payload"), | ||
| ( | ||
| "2024-01-01T00:00:00", | ||
| AttributeType.TIMESTAMP, | ||
| datetime.datetime(2024, 1, 1, 0, 0), | ||
| ), | ||
| ( | ||
| "s3://bucket/path/to/object", | ||
| AttributeType.LARGE_BINARY, | ||
| largebinary("s3://bucket/path/to/object"), | ||
| ), | ||
| ], | ||
| ) | ||
| def test_parse_supported_types(self, raw_value, attr_type, expected): | ||
| assert _UiParameterSupport._parse(raw_value, attr_type) == expected | ||
|
|
||
| def test_parse_unsupported_type_raises_helpful_error(self): | ||
| with pytest.raises(TypeError, match="UiParameter.type .* is not supported"): | ||
| _UiParameterSupport._parse("value", object()) | ||
|
|
||
| def test_wrapped_open_uses_instance_local_state(self): | ||
| assert ( | ||
| getattr( | ||
| FirstIndependentParameterOperator.open, | ||
| "__texera_ui_params_wrapped__", | ||
| False, | ||
| ) | ||
| is True | ||
| ) | ||
|
|
||
| first_operator = FirstIndependentParameterOperator() | ||
| second_operator = SecondIndependentParameterOperator() | ||
|
|
||
| first_operator.open() | ||
| second_operator.open() | ||
|
|
||
| assert first_operator.count_parameter.value == 1 | ||
| assert second_operator.count_parameter.value == 2 | ||
| assert first_operator._ui_parameter_injected_values == {"count": "1"} | ||
| assert second_operator._ui_parameter_injected_values == {"count": "2"} | ||
| assert ( | ||
| first_operator._ui_parameter_injected_values | ||
| is not second_operator._ui_parameter_injected_values | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.