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

Remove invalid hints from Properties inputs. #119

Merged
merged 2 commits into from
Mar 1, 2025
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 @@ -29,7 +29,7 @@

public final class DeploymentService {

private static final String HINT_OPTION = "hints";
static final String HINT_OPTION = "hints";
public static final String PIPELINE_OPTION = "pipeline";

private DeploymentService() {
Expand Down Expand Up @@ -97,11 +97,19 @@ public static PipelineRel.Implementor plan(RelRoot root, List<RelOptMaterializat
public static Map<String, String> parseHints(Properties connectionProperties) {
Map<String, String> hints = new LinkedHashMap<>();
if (connectionProperties.containsKey(HINT_OPTION)) {
hints.putAll(Splitter.on(',').withKeyValueSeparator('=').split(connectionProperties.getProperty(HINT_OPTION)));
String property = connectionProperties.getProperty(HINT_OPTION);
if (property != null && !property.isEmpty()) {
hints.putAll(Splitter.on(',').withKeyValueSeparator('=').split(property));
}
}

if (connectionProperties.containsKey(PIPELINE_OPTION)) {
hints.put(PIPELINE_OPTION, connectionProperties.getProperty(PIPELINE_OPTION));
String property = connectionProperties.getProperty(PIPELINE_OPTION);
if (property != null && !property.isEmpty()) {
hints.put(PIPELINE_OPTION, property);
}
}

return hints;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.linkedin.hoptimator.util;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import org.junit.jupiter.api.Test;

import static com.linkedin.hoptimator.util.DeploymentService.HINT_OPTION;
import static com.linkedin.hoptimator.util.DeploymentService.PIPELINE_OPTION;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;


class DeploymentServiceTest {

/**
* "hint" keys <b>and</b> values are required to be non-{@code null}. An
* empty {@link Map} is considered invalid and should <b>not</b> be added
* to the {@link Properties} object.
* <br/>
* nb. "pipeline" values are <b>always</b> added when present.
*/
@Test
void parseHints() {
Map<String, String> empty = DeploymentService.parseHints(new Properties());
assertTrue(empty.isEmpty(), "An empty map should not add `hints`.");

Map<String, String> defined = DeploymentService.parseHints(new Properties() {{
put(HINT_OPTION, "key=value");
}});
assertEquals("value", defined.get("key"), "Did not match expected key value pair: `key=value`.");

Map<String, String> nokey = DeploymentService.parseHints(new Properties() {{
put(HINT_OPTION, "flag0=,flag1=");
}});
assertTrue(nokey.keySet().containsAll(Arrays.asList("flag0", "flag1")), "Expected to find flags.");

Map<String, String> pipelineOnly = DeploymentService.parseHints(new Properties() {{
put(PIPELINE_OPTION, "pipeline");
}});
assertEquals("pipeline", pipelineOnly.get(PIPELINE_OPTION), "Did not match expected `pipeline` value.");

Map<String, String> both = DeploymentService.parseHints(new Properties() {{
putAll(defined);
put(PIPELINE_OPTION, "pipeline");
}});
assertEquals("pipeline", both.get(PIPELINE_OPTION), "Did not match expected `pipeline` value.");
}
}