Package org.apache.calcite.test
Class Matchers
java.lang.Object
org.apache.calcite.test.Matchers
Matchers for testing SQL queries.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Matchers.IsWithin<T extends Number>
Matcher that tests whether the numeric value is within a given difference another value. -
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Comparable<T>>
org.hamcrest.Matcher<T>between
(T min, T max) Creates a matcher that matches if the examined value is between bounds:min ≤ value ≤ max
.static <F,
T> org.hamcrest.Matcher<F> Creates a matcher by applying a function to a value before calling another matcher.static org.hamcrest.Matcher<String>
containsStringLinux
(String value) Creates a matcher that matches when the examined string is equal to the specifiedoperand
when all Windows-style line endings ("\r\n") have been converted to Unix-style line endings ("\n").static org.hamcrest.Matcher<String>
containsWithoutNodeIds
(String value) Creates aMatcher
that matches execution plan and trims, id=123
node ids.static <E extends Comparable>
org.hamcrest.Matcher<Iterable<E>>equalsUnordered
(E... lines) static org.hamcrest.Matcher<? super Throwable>
expectThrowable
(Throwable expected) Creates a matcher that matches if the examined value is expected throwable.static org.hamcrest.Matcher<RelNode>
hasFieldNames
(String fieldNames) Creates a Matcher that matches aRelNode
if its field names, converting to a list, are equal to the givenvalue
.static org.hamcrest.Matcher<RelNode>
Creates a Matcher that matches aRelNode
if its hints string representation is equal to the givenvalue
.static org.hamcrest.Matcher<RexNode>
Creates a Matcher that matches aRexNode
if its string representation, after converting Windows-style line endings ("\r\n") to Unix-style line endings ("\n"), is equal to the givenvalue
.static org.hamcrest.Matcher<RelNode>
Creates a Matcher that matches aRelNode
if its string representation, after converting Windows-style line endings ("\r\n") to Unix-style line endings ("\n"), is equal to the givenvalue
.static org.hamcrest.Matcher<RelNode>
Creates a Matcher that matches aRelNode
if its string representation, after converting Windows-style line endings ("\r\n") to Unix-style line endings ("\n"), contains the givenvalue
as a substring.static org.hamcrest.Matcher<Double>
isAlmost
(double value) Creates a matcher that matches when the examined object is withinEPSILON
of the specifiedoperand
.static org.hamcrest.Matcher<Charset>
Creates a matcher that matches if the examined value has a given name.static org.hamcrest.Matcher<String>
Creates a Matcher that matches when the examined string is equal to the specifiedvalue
when all Windows-style line endings ("\r\n") have been converted to Unix-style line endings ("\n").static org.hamcrest.Matcher<com.google.common.collect.RangeSet>
isRangeSet
(String value) Creates a Matcher that matches aRangeSet
if its string representation, after changing "ߩ" to "..", is equal to the givenvalue
.static org.hamcrest.Matcher<RelNode>
static org.hamcrest.Matcher<? super ResultSet>
returnsUnordered
(String... lines) Creates a matcher that matches if the examined result set returns the given collection of rows in some order.static String
sanitizeRangeSet
(String string) Changes all '‥' (a unicode symbol denoting a range) to '..', consistent with Guava 29+.static <T> org.hamcrest.Matcher<Iterable<T>>
Matcher that succeeds for any collection that, when converted to strings and sorted on those strings, matches the given reference string.static String
static <T extends Number>
org.hamcrest.Matcher<T>within
(T value, double epsilon) Creates a matcher that matches when the examined object is withinepsilon
of the specifiedvalue
.
-
Field Details
-
EPSILON
public static final double EPSILONA small positive value.- See Also:
-
-
Method Details
-
returnsUnordered
Creates a matcher that matches if the examined result set returns the given collection of rows in some order.Closes the result set after reading.
For example:
assertThat(statement.executeQuery("select empno from emp"), returnsUnordered("empno=1234", "empno=100"));
-
equalsUnordered
-
within
Creates a matcher that matches when the examined object is withinepsilon
of the specifiedvalue
. -
isAlmost
Creates a matcher that matches when the examined object is withinEPSILON
of the specifiedoperand
. -
between
Creates a matcher that matches if the examined value is between bounds:min ≤ value ≤ max
.- Type Parameters:
T
- value type- Parameters:
min
- Lower boundmax
- Upper bound
-
compose
public static <F,T> org.hamcrest.Matcher<F> compose(org.hamcrest.Matcher<T> matcher, Function<F, T> f) Creates a matcher by applying a function to a value before calling another matcher. -
isLinux
Creates a Matcher that matches when the examined string is equal to the specifiedvalue
when all Windows-style line endings ("\r\n") have been converted to Unix-style line endings ("\n").Thus, if
foo()
is a function that returns "hello{newline}world" in the current operating system's line endings, thenassertThat(foo(), isLinux("hello\nworld"));
will succeed on all platforms.
- See Also:
-
relIsValid
-
hasTree
Creates a Matcher that matches aRelNode
if its string representation, after converting Windows-style line endings ("\r\n") to Unix-style line endings ("\n"), is equal to the givenvalue
. -
hasFieldNames
Creates a Matcher that matches aRelNode
if its field names, converting to a list, are equal to the givenvalue
. -
inTree
Creates a Matcher that matches aRelNode
if its string representation, after converting Windows-style line endings ("\r\n") to Unix-style line endings ("\n"), contains the givenvalue
as a substring. -
hasRex
Creates a Matcher that matches aRexNode
if its string representation, after converting Windows-style line endings ("\r\n") to Unix-style line endings ("\n"), is equal to the givenvalue
. -
hasHints
Creates a Matcher that matches aRelNode
if its hints string representation is equal to the givenvalue
. -
isRangeSet
Creates a Matcher that matches aRangeSet
if its string representation, after changing "ߩ" to "..", is equal to the givenvalue
.This method is necessary because
RangeSet.toString()
changed behavior. Guava 19 - 28 used a unicode symbol; Guava 29 onwards uses "..". -
sanitizeRangeSet
Changes all '‥' (a unicode symbol denoting a range) to '..', consistent with Guava 29+. -
containsWithoutNodeIds
@API(since="1.22", status=EXPERIMENTAL) public static org.hamcrest.Matcher<String> containsWithoutNodeIds(String value) Creates aMatcher
that matches execution plan and trims, id=123
node ids.RelOptNode.getId()
is not stable across runs, so this matcher enables to trim those.- Parameters:
value
- execpted execution plan- Returns:
- matcher
-
containsStringLinux
Creates a matcher that matches when the examined string is equal to the specifiedoperand
when all Windows-style line endings ("\r\n") have been converted to Unix-style line endings ("\n").Thus, if
foo()
is a function that returns "hello{newline}world" in the current operating system's line endings, thenassertThat(foo(), isLinux("hello\nworld"));
will succeed on all platforms.
- See Also:
-
trimNodeIds
-
expectThrowable
Creates a matcher that matches if the examined value is expected throwable.- Parameters:
expected
- Throwable to match.
-
isCharset
Creates a matcher that matches if the examined value has a given name.- Parameters:
charsetName
- Name of character set- See Also:
-
sortsAs
Matcher that succeeds for any collection that, when converted to strings and sorted on those strings, matches the given reference string.Use it as an alternative to
Is.is(org.hamcrest.Matcher<T>)
if items in your list might occur in any order.For example:
List<Integer> ints = Arrays.asList(2, 500, 12); assertThat(ints, sortsAs("[12, 2, 500]");
-