-
Notifications
You must be signed in to change notification settings - Fork 74
Example UDF and its unit test to repro issue: https://github.com/link… #123
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
mohit10verma
wants to merge
1
commit into
linkedin:master
Choose a base branch
from
mohit10verma:PRforGithubIssue
base: master
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
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
46 changes: 46 additions & 0 deletions
46
...fs/src/main/java/com/linkedin/transport/examples/StructElementIncrementByOneFunction.java
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,46 @@ | ||
| /** | ||
| * Copyright 2023 LinkedIn Corporation. All rights reserved. | ||
| * Licensed under the BSD-2 Clause license. | ||
| * See LICENSE in the project root for license information. | ||
| */ | ||
| package com.linkedin.transport.examples; | ||
|
|
||
| import com.google.common.collect.ImmutableList; | ||
| import com.linkedin.transport.api.data.StdInteger; | ||
| import com.linkedin.transport.api.data.StdStruct; | ||
| import com.linkedin.transport.api.udf.StdUDF1; | ||
| import com.linkedin.transport.api.udf.TopLevelStdUDF; | ||
| import java.util.List; | ||
|
|
||
|
|
||
| public class StructElementIncrementByOneFunction extends StdUDF1<StdStruct, StdStruct> implements TopLevelStdUDF { | ||
|
|
||
| @Override | ||
| public List<String> getInputParameterSignatures() { | ||
| return ImmutableList.of( | ||
| "row(integer, integer)" | ||
| ); | ||
| } | ||
|
|
||
| @Override | ||
| public String getOutputParameterSignature() { | ||
| return "row(integer, integer)"; | ||
| } | ||
|
|
||
| @Override | ||
| public StdStruct eval(StdStruct myStruct) { | ||
| int currVal = ((StdInteger) myStruct.getField(0)).get(); | ||
| myStruct.setField(0, getStdFactory().createInteger(currVal + 1)); | ||
| return myStruct; | ||
| } | ||
|
|
||
| @Override | ||
| public String getFunctionName() { | ||
| return "struct_element_increment_by_one"; | ||
| } | ||
|
|
||
| @Override | ||
| public String getFunctionDescription() { | ||
| return "increment first element by one"; | ||
| } | ||
| } | ||
33 changes: 33 additions & 0 deletions
33
...rc/test/java/com/linkedin/transport/examples/TestStructElementIncrementByOneFunction.java
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,33 @@ | ||
| /** | ||
| * Copyright 2023 LinkedIn Corporation. All rights reserved. | ||
| * Licensed under the BSD-2 Clause license. | ||
| * See LICENSE in the project root for license information. | ||
| */ | ||
| package com.linkedin.transport.examples; | ||
|
|
||
| import com.google.common.collect.ImmutableList; | ||
| import com.google.common.collect.ImmutableMap; | ||
| import com.linkedin.transport.api.udf.StdUDF; | ||
| import com.linkedin.transport.api.udf.TopLevelStdUDF; | ||
| import com.linkedin.transport.test.AbstractStdUDFTest; | ||
| import com.linkedin.transport.test.spi.StdTester; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import org.testng.annotations.Test; | ||
|
|
||
|
|
||
| public class TestStructElementIncrementByOneFunction extends AbstractStdUDFTest { | ||
|
|
||
| @Override | ||
| protected Map<Class<? extends TopLevelStdUDF>, List<Class<? extends StdUDF>>> getTopLevelStdUDFClassesAndImplementations() { | ||
| return ImmutableMap.of( | ||
| StructElementIncrementByOneFunction.class, ImmutableList.of(StructElementIncrementByOneFunction.class)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testStructElementIncrementByOneFunction() { | ||
| StdTester tester = getTester(); | ||
| tester.check(functionCall("struct_element_increment_by_one", row(1, 3)), row(2, 3), "row(integer,integer)"); | ||
| tester.check(functionCall("struct_element_increment_by_one", row(-2, 3)), row(-1, 3), "row(integer,integer)"); | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you try
transport/transportable-udfs-hive/src/main/java/com/linkedin/transport/hive/data/HiveStruct.java
Line 64 in 09a8950
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think transport UDFs test framework lets users create structs with named fields. You can try that and let me know if I am mistaken.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried fixing this in a totally different PR here: #119
But this issue is independent.