Skip to content

Commit

Permalink
fix: Make sure UDTF describe shows actual function description (#5744)
Browse files Browse the repository at this point in the history
  • Loading branch information
purplefox authored Jul 8, 2020
1 parent f781446 commit afe85d9
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
6 changes: 2 additions & 4 deletions ksqldb-cli/src/test/java/io/confluent/ksql/cli/CliTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -896,13 +896,11 @@ public void shouldDescribeTableFunction() {
// variations for Udfs are loaded non-deterministically. Don't assume which variation is first
String expectedVariation =
"\tVariation : EXPLODE(list ARRAY<T>)\n"
+ "\tReturns : T\n"
+ "\tDescription : Explodes an array. This function outputs one value for each element of the array.";
+ "\tReturns : T";
assertThat(outputString, containsString(expectedVariation));

expectedVariation = "\tVariation : EXPLODE(input ARRAY<DECIMAL>)\n"
+ "\tReturns : DECIMAL\n"
+ "\tDescription : Explodes an array. This function outputs one value for each element of the array.";
+ "\tReturns : DECIMAL";
assertThat(outputString, containsString(expectedVariation));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void loadUdtfFromClass(
final KsqlTableFunction tableFunction =
createTableFunction(method, FunctionName.of(functionName), returnType,
parameters,
udtfDescriptionAnnotation.description(),
annotation.description(),
annotation
);
factory.addFunction(tableFunction);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,12 @@ public ServiceContext getServiceContext() {
@UdtfDescription(name = "test_udtf1", description = "test_udtf1 description")
public static class TestUdtf1 {

@Udtf
@Udtf(description = "test_udtf1 int")
public List<Integer> foo1(@UdfParameter(value = "foo") final int foo) {
return ImmutableList.of(1);
}

@Udtf
@Udtf(description = "test_udtf1 double")
public List<Double> foo2(@UdfParameter(value = "foo") final double foo) {
return ImmutableList.of(1.0d);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@
package io.confluent.ksql.rest.server.execution;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;

import io.confluent.ksql.rest.SessionProperties;
import io.confluent.ksql.rest.entity.ArgumentInfo;
import io.confluent.ksql.rest.entity.FunctionDescriptionList;
import io.confluent.ksql.rest.entity.FunctionInfo;
import io.confluent.ksql.rest.entity.FunctionType;
import io.confluent.ksql.rest.server.TemporaryEngine;
import java.util.Arrays;
import org.hamcrest.Description;
import org.hamcrest.TypeSafeMatcher;
import org.junit.Rule;
Expand Down Expand Up @@ -102,15 +107,30 @@ public void shouldDescribeUDTF() {
assertThat(functionList, new TypeSafeMatcher<FunctionDescriptionList>() {
@Override
protected boolean matchesSafely(final FunctionDescriptionList item) {
return functionList.getName().equals("TEST_UDTF1")
&& functionList.getType().equals(FunctionType.TABLE);
return item.getName().equals("TEST_UDTF1")
&& item.getType().equals(FunctionType.TABLE);
}

@Override
public void describeTo(final Description description) {
description.appendText(functionList.getName());
}
});

assertThat(functionList.getFunctions(), hasSize(2));

FunctionInfo expected1 = new FunctionInfo(
Arrays.asList(new ArgumentInfo("foo", "INT", "", false)),
"INT", "test_udtf1 int");

assertTrue(functionList.getFunctions().contains(expected1));

FunctionInfo expected2 = new FunctionInfo(
Arrays.asList(new ArgumentInfo("foo", "DOUBLE", "", false)),
"DOUBLE", "test_udtf1 double");

assertTrue(functionList.getFunctions().contains(expected2));

}

}

0 comments on commit afe85d9

Please sign in to comment.