public TestBuilder sqlQuery(String query) { this.query = QueryTestUtil.normalizeQuery(query); this.queryType = UserBitShared.QueryType.SQL; return this; }
/** * Execute a single query with a user supplied result listener. * * @param client Dremio client to use * @param type type of query * @param queryString the query string * @param resultListener the result listener */ public static void testWithListener(final DremioClient client, final QueryType type, final String queryString, final UserResultsListener resultListener) { final String query = QueryTestUtil.normalizeQuery(queryString); client.runQuery(type, query, resultListener); } }
public static List<QueryDataBatch> testRunAndReturn(QueryType type, Object query) throws Exception{ if (type == QueryType.PREPARED_STATEMENT) { Preconditions.checkArgument(query instanceof PreparedStatementHandle, "Expected an instance of PreparedStatement as input query"); return testPreparedStatement((PreparedStatementHandle)query); } else { Preconditions.checkArgument(query instanceof String, "Expected a string as input query"); query = QueryTestUtil.normalizeQuery((String)query); return client.runQuery(type, (String)query); } }
/** * Execute one or more queries separated by semicolons, and print the results. * * @param client Dremio client to use * @param queryString the query string * @throws Exception */ public static void test(final DremioClient client, final String queryString) throws Exception{ final String query = normalizeQuery(queryString); String[] queries = query.split(";"); for (String q : queries) { final String trimmedQuery = q.trim(); if (trimmedQuery.isEmpty()) { continue; } testRunAndPrint(client, QueryType.SQL, trimmedQuery); } }
/** * This method will take a SQL string statement, get the PHYSICAL plan in json * format. Then check the physical plan against the list expected substrs. * Verify all the expected strings are contained in the physical plan string. */ public static void testPhysicalPlan(String sql, String... expectedSubstrs) throws Exception { sql = "EXPLAIN PLAN for " + QueryTestUtil.normalizeQuery(sql); final String planStr = getPlanInString(sql, OPTIQ_FORMAT); for (final String colNames : expectedSubstrs) { assertTrue(String.format("Unable to find expected string %s in plan: %s!", colNames, planStr), planStr.contains(colNames)); } }
private void submitRandomQuery() { final String filename = queryFile[random.nextInt(queryFile.length)]; final String query; try { query = QueryTestUtil.normalizeQuery(getFile(filename)).replace(';', ' '); } catch(IOException e) { throw new RuntimeException("Caught exception", e); } final UserResultsListener listener = new ChainingSilentListener(query); client.runQuery(UserBitShared.QueryType.SQL, query, listener); synchronized(this) { listeners.add(listener); } }
@Test public void ensureFieldNotDependentOnFlattenIsPushedBelowFlatten() throws Exception { final String query = "SELECT errorCode, errorMessage, nested_1.data.q AS q, nested_1.data.v AS v, TO_TIMESTAMP(nested_1.data.ts, 'YYYY-MM-DD\"T\"HH24:MI:SS.FFFTZO') AS ts, tagId\n" + "FROM (\n" + " SELECT errorCode, errorMessage, flatten(nested_0.tagList.data) AS data, nested_0.tagList.tagId AS tagId\n" + " FROM (\n" + " SELECT errorCode, errorMessage, flatten(tagList) AS tagList\n" + " FROM cp.\"flatten/multiflatten.json\"\n" + " ) nested_0\n" + ") nested_1"; final String plan = getPlanInString("EXPLAIN PLAN for " + QueryTestUtil.normalizeQuery(query), OPTIQ_FORMAT); assertTrue(Pattern.compile(".*Flatten.*ITEM[^\\)]*tagId.*", Pattern.MULTILINE + Pattern.DOTALL).matcher(plan).matches()); }
+ QueryTestUtil.normalizeQuery(sql);
final String plan = getPlanInString("EXPLAIN PLAN for " + QueryTestUtil.normalizeQuery(query), OPTIQ_FORMAT);
/** * Search for Json blobs (used for representing elastic pushdown queries) in the query plan. * * If multiple json values are given they must be provided in the order the appear in the plan. * * This method can only be used for checking elastic plans as it looks for the string "pushdown: =" * to find the JSON in the plan. * * The unused third parameter gives this method the same signature as the similar * testPlanMatchingPatterns() method that was used for these kinds of tests before this elastic * specific variant was introduced. Probably not the best reason, but it was included to * reduce the clutter from the patch that switched the tests to use this method. */ public static void verifyJsonInPlan(String query, String[] jsonExpectedInPlan) throws Exception { if(!ElasticsearchCluster.USE_EXTERNAL_ES5) { query = QueryTestUtil.normalizeQuery(query); verifyJsonInPlanHelper(query, jsonExpectedInPlan, true); verifyJsonInPlanHelper(query, jsonExpectedInPlan, false); } }
throws Exception { final String plan = getPlanInString("EXPLAIN PLAN INCLUDING ALL ATTRIBUTES for " + QueryTestUtil.normalizeQuery(query), OPTIQ_FORMAT);
/** * From left to right make sure we match expected in order. * @param query an explain query, this method does not add it for you * @param expectedPatterns list of patterns that should appear in the plan from left to right * @param excludedPatterns list of patterns that should not appear in the plan * @throws Exception if an inclusion or exclusion check fails, or the * planning process throws an exception */ public static void testPlanSubstrPatternsInOrder(String query, String[] expectedPatterns, String[] excludedPatterns) throws Exception { final String plan = getPlanInString("EXPLAIN PLAN for " + QueryTestUtil.normalizeQuery(query), OPTIQ_FORMAT); // Check and make sure all expected patterns are in the plan if (expectedPatterns != null) { int fromIndex = 0; for (final String s : expectedPatterns) { fromIndex = plan.indexOf(s, fromIndex); assertTrue( EXPECTED_NOT_FOUND + s + ", Output plan: " + plan, fromIndex != -1); fromIndex += s.length(); } } // Check and make sure all excluded patterns are not in the plan if (excludedPatterns != null) { for (final String s : excludedPatterns) { assertFalse(UNEXPECTED_FOUND + s + ", Output plan: " + plan, plan.contains(s)); } } }
final String plan = getPlanInString("EXPLAIN PLAN for " + QueryTestUtil.normalizeQuery(query), OPTIQ_FORMAT);
/** * Execute a SQL query, and print the results. * * @param client Dremio client to use * @param type type of the query * @param queryString query string * @return number of rows returned * @throws Exception */ public static int testRunAndPrint( final DremioClient client, final QueryType type, final String queryString) throws Exception { final String query = normalizeQuery(queryString); SabotConfig config = client.getConfig(); AwaitableUserResultsListener resultListener = new AwaitableUserResultsListener( config.getBoolean(TEST_QUERY_PRINTING_SILENT) ? new SilentListener() : new PrintingResultsListener(config, Format.TSV, VectorUtil.DEFAULT_COLUMN_WIDTH) ); client.runQuery(type, query, resultListener); return resultListener.await(); }