Class Matchers

java.lang.Object
org.apache.calcite.test.Matchers

public class Matchers extends Object
Matchers for testing SQL queries.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Matcher that tests whether the numeric value is within a given difference another value.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final double
    A small positive value.
  • Method Summary

    Modifier and Type
    Method
    Description
    static <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>
    compose(org.hamcrest.Matcher<T> matcher, Function<F,T> f)
    Creates a matcher by applying a function to a value before calling another matcher.
    static org.hamcrest.Matcher<String>
    Creates a matcher that matches when the examined string is equal to the specified operand when all Windows-style line endings ("\r\n") have been converted to Unix-style line endings ("\n").
    static org.hamcrest.Matcher<String>
    Creates a Matcher 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>
    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 a RelNode if its field names, converting to a list, are equal to the given value.
    static org.hamcrest.Matcher<RelNode>
    Creates a Matcher that matches a RelNode if its hints string representation is equal to the given value.
    static org.hamcrest.Matcher<RexNode>
    hasRex(String value)
    Creates a Matcher that matches a RexNode if its string representation, after converting Windows-style line endings ("\r\n") to Unix-style line endings ("\n"), is equal to the given value.
    static org.hamcrest.Matcher<RelNode>
    hasTree(String value)
    Creates a Matcher that matches a RelNode if its string representation, after converting Windows-style line endings ("\r\n") to Unix-style line endings ("\n"), is equal to the given value.
    static org.hamcrest.Matcher<RelNode>
    inTree(String value)
    Creates a Matcher that matches a RelNode if its string representation, after converting Windows-style line endings ("\r\n") to Unix-style line endings ("\n"), contains the given value as a substring.
    static org.hamcrest.Matcher<Double>
    isAlmost(double value)
    Creates a matcher that matches when the examined object is within EPSILON of the specified operand.
    static org.hamcrest.Matcher<Charset>
    isCharset(String charsetName)
    Creates a matcher that matches if the examined value has a given name.
    static org.hamcrest.Matcher<String>
    isLinux(String value)
    Creates a Matcher that matches when the examined string is equal to the specified value 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>
    Creates a Matcher that matches a RangeSet if its string representation, after changing "ߩ" to "..", is equal to the given value.
    static org.hamcrest.Matcher<RelNode>
    Matcher that matches a RelNode if the RelNode is valid per RelValidityChecker.
    static org.hamcrest.Matcher<? super ResultSet>
    Creates a matcher that matches if the examined result set returns the given collection of rows in some order.
    static String
    Changes all '‥' (a unicode symbol denoting a range) to '..', consistent with Guava 29+.
    static <T> org.hamcrest.Matcher<Iterable<T>>
    sortsAs(String value)
    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 within epsilon of the specified value.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Method Details

    • returnsUnordered

      public 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.

      Closes the result set after reading.

      For example:

      assertThat(statement.executeQuery("select empno from emp"),
         returnsUnordered("empno=1234", "empno=100"));
    • equalsUnordered

      public static <E extends Comparable> org.hamcrest.Matcher<Iterable<E>> equalsUnordered(E... lines)
    • within

      public static <T extends Number> org.hamcrest.Matcher<T> within(T value, double epsilon)
      Creates a matcher that matches when the examined object is within epsilon of the specified value.
    • isAlmost

      public static org.hamcrest.Matcher<Double> isAlmost(double value)
      Creates a matcher that matches when the examined object is within EPSILON of the specified operand.
    • between

      public static <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.
      Type Parameters:
      T - value type
      Parameters:
      min - Lower bound
      max - 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

      public static org.hamcrest.Matcher<String> isLinux(String value)
      Creates a Matcher that matches when the examined string is equal to the specified value 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, then

      assertThat(foo(), isLinux("hello\nworld"));

      will succeed on all platforms.

      See Also:
    • relIsValid

      public static org.hamcrest.Matcher<RelNode> relIsValid()
      Matcher that matches a RelNode if the RelNode is valid per RelValidityChecker.
    • hasTree

      public static org.hamcrest.Matcher<RelNode> hasTree(String value)
      Creates a Matcher that matches a RelNode if its string representation, after converting Windows-style line endings ("\r\n") to Unix-style line endings ("\n"), is equal to the given value.
    • hasFieldNames

      public static org.hamcrest.Matcher<RelNode> hasFieldNames(String fieldNames)
      Creates a Matcher that matches a RelNode if its field names, converting to a list, are equal to the given value.
    • inTree

      public static org.hamcrest.Matcher<RelNode> inTree(String value)
      Creates a Matcher that matches a RelNode if its string representation, after converting Windows-style line endings ("\r\n") to Unix-style line endings ("\n"), contains the given value as a substring.
    • hasRex

      public static org.hamcrest.Matcher<RexNode> hasRex(String value)
      Creates a Matcher that matches a RexNode if its string representation, after converting Windows-style line endings ("\r\n") to Unix-style line endings ("\n"), is equal to the given value.
    • hasHints

      public static org.hamcrest.Matcher<RelNode> hasHints(String value)
      Creates a Matcher that matches a RelNode if its hints string representation is equal to the given value.
    • isRangeSet

      public static org.hamcrest.Matcher<com.google.common.collect.RangeSet> isRangeSet(String value)
      Creates a Matcher that matches a RangeSet if its string representation, after changing "ߩ" to "..", is equal to the given value.

      This method is necessary because RangeSet.toString() changed behavior. Guava 19 - 28 used a unicode symbol; Guava 29 onwards uses "..".

    • sanitizeRangeSet

      public static String sanitizeRangeSet(String string)
      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 a Matcher 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

      public static org.hamcrest.Matcher<String> containsStringLinux(String value)
      Creates a matcher that matches when the examined string is equal to the specified operand 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, then

      assertThat(foo(), isLinux("hello\nworld"));

      will succeed on all platforms.

      See Also:
    • trimNodeIds

      public static String trimNodeIds(String s)
    • expectThrowable

      public static org.hamcrest.Matcher<? super Throwable> expectThrowable(Throwable expected)
      Creates a matcher that matches if the examined value is expected throwable.
      Parameters:
      expected - Throwable to match.
    • isCharset

      public static org.hamcrest.Matcher<Charset> isCharset(String charsetName)
      Creates a matcher that matches if the examined value has a given name.
      Parameters:
      charsetName - Name of character set
      See Also:
    • sortsAs

      public static <T> org.hamcrest.Matcher<Iterable<T>> sortsAs(String value)
      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]");