Skip to content
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

fix: fix parsing issue with LIST property overrides #3601

Merged
Merged
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
Expand Up @@ -25,6 +25,7 @@
import io.confluent.ksql.util.KsqlException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -124,10 +125,21 @@ private static Map<String, Object> coerceTypes(final Map<String, Object> streams

private static Object coerceType(final String key, final Object value) {
Copy link
Contributor

Choose a reason for hiding this comment

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

MIght be nice to rename this coerceProperty or similar? It took me a while to figure out what it's doing, which would have been more obvious with a better name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm ok with the name as-is, plus not added in this PR.

try {
final String stringValue = value == null ? null : String.valueOf(value);
final String stringValue = value == null
? null
: value instanceof List
? listToString((List<?>) value)
: String.valueOf(value);

return PROPERTY_PARSER.parse(key, stringValue);
} catch (final Exception e) {
throw new KsqlException("Failed to set '" + key + "' to '" + value + "'", e);
}
}

private static String listToString(final List<?> value) {
return value.stream()
.map(e -> e == null ? null : e.toString())
.collect(Collectors.joining(","));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.is;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.testing.EqualsTester;
import io.confluent.ksql.json.JsonMapper;
Expand Down Expand Up @@ -202,6 +204,27 @@ public void shouldHandleNullPropertyValue() {
assertThat(props.get(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG), is("earliest"));
}

@Test
public void shouldHandleOverridesOfTypeList() {
// Given:
final KsqlRequest request = new KsqlRequest(
"sql",
ImmutableMap.of(
ConsumerConfig.INTERCEPTOR_CLASSES_CONFIG, ImmutableList.of("some.type")
),
null
);

// When:
final Map<String, Object> props = request.getStreamsProperties();

// Then:
assertThat(
props,
hasEntry(ConsumerConfig.INTERCEPTOR_CLASSES_CONFIG, ImmutableList.of("some.type"))
);
}

private static String serialize(final KsqlRequest request) {
try {
return OBJECT_MAPPER.writeValueAsString(request);
Expand Down