Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you try

(using field_name instead of field index) and see if the same issue persists?

Copy link
Author

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.

Copy link
Author

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.

return myStruct;
}

@Override
public String getFunctionName() {
return "struct_element_increment_by_one";
}

@Override
public String getFunctionDescription() {
return "increment first element by one";
}
}
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)");
}
}