MCPcopy Create free account
hub / github.com/apache/impala / TestUtils

Class TestUtils

fe/src/test/java/org/apache/impala/testutil/TestUtils.java:65–543  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63import com.google.common.collect.Maps;
64
65public class TestUtils {
66 private final static Logger LOG = LoggerFactory.getLogger(TestUtils.class);
67 private final static String[] ignoreContentAfter_ = { "HOST:", "LOCATIONS:" };
68 // Special prefix that designates an expected value specified as a regex rather
69 // than a literal
70 private final static String REGEX_AGAINST_ACTUAL = "regex:";
71
72 // Regexes that match various elements in plan.
73 private final static String NUMBER_REGEX = "\\d+(\\.\\d+)?";
74 private final static String BYTE_SUFFIX_REGEX = "[KMGT]?B";
75 private final static String BYTE_VALUE_REGEX = NUMBER_REGEX + BYTE_SUFFIX_REGEX;
76 // Note: The older Hive Server JDBC driver (Hive .9 and earlier) is named similarly:
77 // "org.apache.hadoop.hive.jdbc.HiveDriver". However, Impala currently only supports
78 // the Hive Server 2 JDBC driver (Hive .10 and later).
79 final static String HIVE_SERVER2_DRIVER_NAME =
80 "org.apache.hive.jdbc.HiveDriver";
81 // The default connection string template to connect to localhost on a given port
82 // number.
83 final static String HS2_CONNECTION_TEMPLATE = "jdbc:hive2://localhost:%d/default";
84
85 public interface ResultFilter {
86 public boolean matches(String input);
87 public String transform(String input);
88 }
89
90 // Our partition file paths are returned in the format of:
91 // hdfs://<host>:<port>/<table>/year=2009/month=4/-47469796--667104359_25784_data.0
92 // Everything after the month=4 can vary run to run so we want to filter this out
93 // when comparing expected vs actual results. We also want to filter out the
94 // host/port because that could vary run to run as well.
95 static class PathFilter implements ResultFilter {
96 private final static String PATH_FILTER = "-*\\d+--\\d+_\\d+.*$";
97 private final static String PORT_FILTER = "//\\w+(\\.\\w+)?(\\.\\w+)?:\\d+";
98 private final String filterKey_;
99
100 public PathFilter(String prefix) { filterKey_ = prefix; }
101
102 @Override
103 public boolean matches(String input) { return input.contains(filterKey_); }
104
105 @Override
106 public String transform(String input) {
107 String result = input.replaceFirst(filterKey_, "");
108 result = result.replaceAll(PATH_FILTER, " ");
109 return result.replaceAll(PORT_FILTER, "");
110 }
111 }
112
113 /**
114 * Filter to ignore the value from elements in the format key=value.
115 */
116 public static class IgnoreValueFilter implements ResultFilter {
117 // Literal string containing the key name.
118 protected final String keyPrefix;
119 protected final String valueRegex;
120
121 /**
122 * Create a filter that ignores the value from key value pairs where the key is

Callers

nothing calls this directly

Calls 1

asListMethod · 0.80

Tested by

no test coverage detected