Package org.apache.calcite.test
Class Matchers
java.lang.Object
org.apache.calcite.test.Matchers
Matchers for testing SQL queries.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classMatchers.IsWithin<T extends Number>Matcher that tests whether the numeric value is within a given difference another value. -
Field Summary
Fields -
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 specifiedoperandwhen 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 aMatcherthat matches execution plan and trims, id=123node 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>hasExpandedTree(String value) Basically similar tohasTree(String), except for expanding RelNode's detail info.static org.hamcrest.Matcher<RelNode>hasFieldNames(String fieldNames) Creates a Matcher that matches aRelNodeif its field names, converting to a list, are equal to the givenvalue.static org.hamcrest.Matcher<RelNode>Creates a Matcher that matches aRelNodeif its hints string representation is equal to the givenvalue.static org.hamcrest.Matcher<RexNode>Creates a Matcher that matches aRexNodeif 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 aRelNodeif 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 aRelNodeif its string representation, after converting Windows-style line endings ("\r\n") to Unix-style line endings ("\n"), contains the givenvalueas a substring.static org.hamcrest.Matcher<Double>isAlmost(double value) Creates a matcher that matches when the examined object is withinEPSILONof 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 specifiedvaluewhen all Windows-style line endings ("\r\n") have been converted to Unix-style line endings ("\n").static <E> org.hamcrest.Matcher<Object>isListOf(E... es) Returns a matcher that tests whether an object is a list with the given contents.static org.hamcrest.Matcher<com.google.common.collect.RangeSet>isRangeSet(String value) Creates a Matcher that matches aRangeSetif its string representation, after changing "ߩ" to "..", is equal to the givenvalue.static org.hamcrest.Matcher<Object>primitiveArrayWithSize(int i) Returns a matcher that tests whether an object is an array (including a primitive array) with a given size.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 StringsanitizeRangeSet(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 Stringstatic <T extends Number>
org.hamcrest.Matcher<T>within(T value, double epsilon) Deprecated.
-
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
@Deprecated public static <T extends Number> org.hamcrest.Matcher<T> within(T value, double epsilon) Deprecated.UseMatchers.closeTo(double, double)Creates a matcher that matches when the examined object is withinepsilonof the specifiedvalue. -
isAlmost
Creates a matcher that matches when the examined object is withinEPSILONof 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 specifiedvaluewhen 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 aRelNodeif its string representation, after converting Windows-style line endings ("\r\n") to Unix-style line endings ("\n"), is equal to the givenvalue. -
hasExpandedTree
Basically similar tohasTree(String), except for expanding RelNode's detail info. For example, default nulls direction will be compared through this. -
hasFieldNames
Creates a Matcher that matches aRelNodeif its field names, converting to a list, are equal to the givenvalue. -
inTree
Creates a Matcher that matches aRelNodeif its string representation, after converting Windows-style line endings ("\r\n") to Unix-style line endings ("\n"), contains the givenvalueas a substring. -
hasRex
Creates a Matcher that matches aRexNodeif 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 aRelNodeif its hints string representation is equal to the givenvalue. -
isRangeSet
Creates a Matcher that matches aRangeSetif 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 aMatcherthat matches execution plan and trims, id=123node 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 specifiedoperandwhen 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]"); -
primitiveArrayWithSize
Returns a matcher that tests whether an object is an array (including a primitive array) with a given size.Compare to
Matchers.arrayWithSize(int), which does not allow primitive arrays. -
isListOf
Returns a matcher that tests whether an object is a list with the given contents.If the list is empty use
Matchers.empty().
-
Matchers.closeTo(double, double)