Skip to content

Commit 539b081

Browse files
Fix incorrect handling of !ignore custom tag in YAML (#3725)
This restores the proper comparison against `!ignore` tags in YAML. This fixes #3727. --------- Co-authored-by: Arnaud Lacurie <a_lacurie@apple.com>
1 parent d5e59a8 commit 539b081

File tree

4 files changed

+120
-1
lines changed

4 files changed

+120
-1
lines changed

yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/Matchers.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,10 @@ private static ResultSetMatchResult matchField(@Nullable final Object expected,
561561
@Nullable final Object actual,
562562
int rowNumber,
563563
@Nonnull String cellRef) throws SQLException {
564+
if (expected instanceof IgnoreTag.IgnoreMatcher) {
565+
return ResultSetMatchResult.success();
566+
}
567+
564568
if (expected == null && actual == null) {
565569
return ResultSetMatchResult.success();
566570
}

yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/tags/IgnoreTag.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.yaml.snakeyaml.nodes.Tag;
2929

3030
import javax.annotation.Nonnull;
31+
import javax.annotation.Nullable;
3132

3233
@AutoService(CustomTag.class)
3334
public final class IgnoreTag implements CustomTag {
@@ -36,7 +37,7 @@ public final class IgnoreTag implements CustomTag {
3637
private static final Tag tag = new Tag("!ignore");
3738

3839
@Nonnull
39-
private static final Matchable INSTANCE = (other, rowNumber, cellRef) -> Matchers.ResultSetMatchResult.success();
40+
private static final Matchable INSTANCE = new IgnoreMatcher();
4041

4142
@Nonnull
4243
private static final Construct CONSTRUCT_INSTANCE = new AbstractConstruct() {
@@ -60,4 +61,17 @@ public Tag getTag() {
6061
public Construct getConstruct() {
6162
return CONSTRUCT_INSTANCE;
6263
}
64+
65+
public static final class IgnoreMatcher implements Matchable {
66+
@Nonnull
67+
@Override
68+
public Matchers.ResultSetMatchResult matches(@Nullable final Object other, final int rowNumber, @Nonnull final String cellRef) {
69+
return Matchers.ResultSetMatchResult.success();
70+
}
71+
72+
@Override
73+
public String toString() {
74+
return tag.getValue();
75+
}
76+
}
6377
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* CustomTagTest
3+
*
4+
* This source file is part of the FoundationDB open source project
5+
*
6+
* Copyright 2015-2025 Apple Inc. and the FoundationDB project authors
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
import com.apple.foundationdb.relational.yamltests.YamlConnectionFactory;
22+
import com.apple.foundationdb.relational.yamltests.YamlExecutionContext;
23+
import com.apple.foundationdb.relational.yamltests.YamlRunner;
24+
import com.apple.foundationdb.relational.yamltests.configs.EmbeddedConfig;
25+
import com.apple.foundationdb.test.FDBTestEnvironment;
26+
import org.junit.jupiter.api.AfterAll;
27+
import org.junit.jupiter.api.BeforeAll;
28+
import org.junit.jupiter.params.ParameterizedTest;
29+
import org.junit.jupiter.params.provider.MethodSource;
30+
31+
import javax.annotation.Nonnull;
32+
import java.util.stream.Stream;
33+
34+
/**
35+
* Tests for custom YAML tags such as {@link com.apple.foundationdb.relational.yamltests.tags.IgnoreTag}.
36+
*/
37+
class CustomTagTest {
38+
private static final String CLUSTER_FILE = FDBTestEnvironment.randomClusterFile();
39+
private static final EmbeddedConfig config = new EmbeddedConfig(CLUSTER_FILE);
40+
41+
@BeforeAll
42+
static void beforeAll() throws Exception {
43+
config.beforeAll();
44+
}
45+
46+
@AfterAll
47+
static void afterAll() throws Exception {
48+
config.afterAll();
49+
}
50+
51+
private void doRun(String testName, YamlConnectionFactory connectionFactory) throws Exception {
52+
new YamlRunner(testName, connectionFactory, YamlExecutionContext.ContextOptions.EMPTY_OPTIONS).run();
53+
}
54+
55+
@Nonnull
56+
static Stream<String> shouldPass() {
57+
return Stream.of(
58+
"ignore-tag"
59+
);
60+
}
61+
62+
@ParameterizedTest
63+
@MethodSource("shouldPass")
64+
void shouldPass(String filename) throws Exception {
65+
doRun("custom-tags/shouldPass/" + filename + ".yamsql", config.createConnectionFactory());
66+
}
67+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#
2+
# ignore-tag.yamsql
3+
#
4+
# This source file is part of the FoundationDB open source project
5+
#
6+
# Copyright 2021-2025 Apple Inc. and the FoundationDB project authors
7+
#
8+
# Licensed under the Apache License, Version 2.0 (the "License");
9+
# you may not use this file except in compliance with the License.
10+
# You may obtain a copy of the License at
11+
#
12+
# http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing, software
15+
# distributed under the License is distributed on an "AS IS" BASIS,
16+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
# See the License for the specific language governing permissions and
18+
# limitations under the License.
19+
---
20+
schema_template:
21+
create table t1(id bigint, col1 bigint, primary key(id))
22+
---
23+
test_block:
24+
preset: single_repetition_ordered
25+
tests:
26+
-
27+
- query: insert into t1 values (null, 200)
28+
- count: 1
29+
-
30+
- query: select * from t1
31+
- result: [{!ignore _, 200}]
32+
-
33+
- query: select col1 from t1
34+
- result: [{!ignore _}]

0 commit comments

Comments
 (0)