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

Fail schema parsing when values are outside allowed range #33204

Merged
merged 1 commit into from
Jan 30, 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 @@ -257,16 +257,19 @@ public void setUseSignificanceModel(boolean useSignificanceModel) {

public void setWeakandStopwordLimit(double limit) {
verifyThat(this.weakandStopwordLimit == null, "already has weakand stopword-limit");
verifyThat(limit >= 0.0 && limit <= 1.0, "weakand stopword-limit must be in range [0, 1]");
this.weakandStopwordLimit = limit;
}

public void setWeakandAdjustTarget(double target) {
verifyThat(this.weakandAdjustTarget == null, "already has weakand adjust-target");
verifyThat(target >= 0.0 && target <= 1.0, "weakand adjust-target must be in range [0, 1]");
this.weakandAdjustTarget = target;
}

public void setFilterThreshold(double threshold) {
verifyThat(this.filterThreshold == null, "already has filter-threshold");
verifyThat(threshold >= 0.0 && threshold <= 1.0, "filter-threshold must be in range [0, 1]");
this.filterThreshold = threshold;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ void weakand_adjust_target_can_be_parsed() throws Exception {
assertEquals(0.01, target.get());
}


@Test
void filter_threshold_can_be_parsed() throws Exception {
String input = joinLines("schema foo {",
Expand All @@ -197,6 +196,22 @@ void filter_threshold_can_be_parsed() throws Exception {
assertEquals(0.05, target.get());
}

private void assertRankProfileWithOutOfRangeThrows(String rpContent) {
var input = "schema foo { rank-profile rp { %s } }".formatted(rpContent);
var e = assertThrows(IllegalArgumentException.class, () -> parseString(input));
assertTrue(e.getMessage().contains("must be in range [0, 1]"));
}

@Test
void range_bounded_properties_fail_parsing_on_out_of_range_input() {
assertRankProfileWithOutOfRangeThrows("filter-threshold: -0.1");
assertRankProfileWithOutOfRangeThrows("filter-threshold: 1.1");
assertRankProfileWithOutOfRangeThrows("weakand { stopword-limit: -0.1 }");
assertRankProfileWithOutOfRangeThrows("weakand { stopword-limit: 1.1 }");
assertRankProfileWithOutOfRangeThrows("weakand { adjust-target: -0.1 }");
assertRankProfileWithOutOfRangeThrows("weakand { adjust-target: 1.1 }");
}

@Test
void field_rank_specific_filter_threshold_can_be_parsed() throws Exception {
String input = """
Expand Down