public void recordRemoteFailure(int coordinationId, DremioPBError failure) { // logger.debug("Updating failed future."); try { RpcOutcome<?> rpc = removeFromMap(coordinationId); rpc.setException(UserRemoteException.create(failure)); } catch (Exception ex) { logger.warn("Failed to remove from map. Not a problem since we were updating on failed future.", ex); } }
void testAndExpectUserException(final String query, ErrorType errorType, final String errorMessage) throws Exception { try { test(query); Assert.fail("Query should've failed"); } catch (UserRemoteException uex) { Assert.assertEquals("Error Message: "+ uex.getMessage(), errorType, uex.getErrorType()); Assert.assertTrue( String.format("Expected error message to contain: %s but was actually [%s].", errorMessage, uex.getMessage()), uex.getMessage().contains(errorMessage)); } } }
/** * Creates (or deserializes) a {@link UserRemoteException} from a {@link DremioPBError}. * * @param error serialized error message * @return user remote exception */ public static UserRemoteException create(DremioPBError error) { return new UserRemoteException(error); } }
@Test // DRILL-3688 public void testIncorrectHeaderFooterProperty() throws Exception { Map<String, String> testData = ImmutableMap.<String, String>builder() .put("hive.skipper.kv_incorrect_skip_header","skip.header.line.count") .put("hive.skipper.kv_incorrect_skip_footer", "skip.footer.line.count") .build(); String query = "select * from %s"; String exceptionMessage = "Hive table property %s value 'A' is non-numeric"; for (Map.Entry<String, String> entry : testData.entrySet()) { try { test(String.format(query, entry.getKey())); } catch (UserRemoteException e) { assertThat(e.getMessage(), containsString(String.format(exceptionMessage, entry.getValue()))); } } }
private boolean hasType(SQLException e, ErrorType errorType) { UserRemoteException userException = ((UserRemoteException) e.getCause()); return userException.getErrorType() == errorType; }
@Test public void testSchemaChange() throws Exception { File dir = new File("target/tests/" + this.getClass().getName() + "/testSchemaChange"); if ((!dir.exists() && !dir.mkdirs()) || (dir.exists() && !dir.isDirectory())) { throw new RuntimeException("can't create dir " + dir); } // CAUTION: There's no ordering guarantee about which file will be read first // so make sure that each file has an incompatible schema compared to the other one. File input1 = new File(dir, "1.json"); File input2 = new File(dir, "2.json"); try (FileWriter fw = new FileWriter(input1)) { fw.append("{\"a\":\"foo\"}\n"); fw.append("{\"a\":\"bar\"}\n"); fw.append("{\"a\":\"baz\", \"c\": \"foz\"}\n"); } try (FileWriter fw = new FileWriter(input2)) { fw.append("{\"b\":\"foo\"}\n"); fw.append("{\"a\":1, \"b\":\"baz\"}\n"); fw.append("{\"a\":\"baz\",\"b\":\"boz\"}\n"); } // we don't retry in test, so let the schema learn the first time around try { test("select * from " + "dfs.\"" + dir.getAbsolutePath() + "\""); fail("query should have failed with schema change error"); } catch (UserRemoteException e) { assertTrue(e.toString(), e.getMessage().contains("SCHEMA_CHANGE ERROR")); } // and it should work the second time runTestAndValidate("*", "*", "dfs.\"" + dir.getAbsolutePath() + "\"", "schema_change_parquet", false); }
/** * Utility method which tests given query produces a {@link UserException} with the expected * errorType and exception message. * @param testSqlQuery Test query * @param expectedErrorType Expected error type * @param expectedErrorMsg Expected error message. */ protected static void errorMsgWithTypeTestHelper(final String testSqlQuery, final ErrorType expectedErrorType, final String expectedErrorMsg) { try { test(testSqlQuery); fail("Query expected to fail"); } catch (Exception ex) { Assert.assertTrue("UserRemoteException expected", ex instanceof UserRemoteException); UserRemoteException uex = ((UserRemoteException) ex); Assert.assertEquals("Invalid ErrorType. Expected " + expectedErrorType + " but got " + uex.getErrorType(), expectedErrorType, uex.getErrorType()); Assert.assertTrue("Expected message to contain " + expectedErrorMsg + " but was " + uex.getOriginalMessage() + " instead", uex.getOriginalMessage().contains(expectedErrorMsg)); } }
@Override public String getVerboseMessage() { return getVerboseMessage(true); }
DremioPBError remoteError = ure.getOrCreatePBError(false);
@Test public void testIncorrectFunctionPlacement() throws Exception { Map<String, String> configMap = ImmutableMap.<String, String>builder() .put("select %s('dfs_root','" + path + "') from dfs.\"" + path + "/*/*.csv\"", "Select List") .put("select dir0 from dfs.\"" + path + "/*/*.csv\" order by %s('dfs_root','" + path + "')", "Order By") .put("select max(dir0) from dfs.\"" + path + "/*/*.csv\" group by %s('dfs_root','" + path + "')", "Group By") .put("select concat(concat(%s('dfs_root','" + path + "'),'someName'),'someName') from dfs.\"" + path + "/*/*.csv\"", "Select List") .put("select dir0 from dfs.\"" + path + "/*/*.csv\" order by concat(%s('dfs_root','" + path + "'),'someName')", "Order By") .put("select max(dir0) from dfs.\"" + path + "/*/*.csv\" group by concat(%s('dfs_root','" + path + "'),'someName')", "Group By") .build(); for (Map.Entry<String, String> configEntry : configMap.entrySet()) { for (ConstantFoldingTestConfig functionConfig : tests) { try { test(String.format(configEntry.getKey(), functionConfig.funcName)); } catch (UserRemoteException e) { assertThat(e.getMessage(), containsString( String.format("Directory explorers [MAXDIR, IMAXDIR, MINDIR, IMINDIR] functions are not supported in %s", configEntry.getValue()))); } } } }
@Test public void testColumnExceedsSize() throws Exception { try { runSQL(QUERY_LARGE); } catch (Exception ex) { if (!(ex instanceof UserRemoteException)) { fail("Unexpected Error"); } UserRemoteException urex = (UserRemoteException) ex; assertEquals(UserBitShared.DremioPBError.ErrorType.UNSUPPORTED_OPERATION, urex.getErrorType()); } }
@Test public void testWildCardEmptyNoCache() throws Exception { prepareTables("4376_3", false); try { runSQL("SELECT COUNT(*) AS \"count\" FROM dfs_test.\"4376_3/604*\""); fail("Query should've failed!"); } catch (UserRemoteException uex) { final String expectedMsg = "Table 'dfs_test.4376_3/604*' not found"; assertTrue(String.format("Error message should contain \"%s\" but was instead \"%s\"", expectedMsg, uex.getMessage()), uex.getMessage().contains(expectedMsg)); } }
@Test public void ensureColumnNameDisplayedinError() throws Exception { final String COL_NAME = "col1"; try { test("select max(columns[1]) as %s from cp.\"textinput/input1.csv\" where %s is not null", COL_NAME, COL_NAME); fail("Query should have failed"); } catch(UserRemoteException ex) { assertEquals(ErrorType.VALIDATION, ex.getErrorType()); assertTrue("Error message should contain " + COL_NAME, ex.getMessage().contains(COL_NAME)); } }
@Override public void statusUpdate(final FragmentStatus status) { logger.debug("New fragment status was provided to QueryManager of {}", status); switch(status.getProfile().getState()) { case AWAITING_ALLOCATION: case RUNNING: case CANCELLATION_REQUESTED: updateFragmentStatus(status); break; case FAILED: logger.info("Fragment {} failed, cancelling remaining fragments.", QueryIdHelper.getQueryIdentifier(status.getHandle())); completionListener.failed(UserRemoteException.create(status.getProfile().getError())); fragmentDone(status); break; case FINISHED: FragmentHandle fragmentHandle = status.getHandle(); if (fragmentHandle.getMajorFragmentId() == 0) { cancelExecutingFragments(); } fragmentDone(status); break; case CANCELLED: fragmentDone(status); break; default: throw new UnsupportedOperationException(String.format("Received status of %s", status)); } } };
@Test public void testSkipLineColumnExceedsSize() throws Exception { try { runSQL(QUERY_SKIPLINE_LARGE); } catch (Exception ex) { if (!(ex instanceof UserRemoteException)) { fail("Unexpected Error"); } UserRemoteException urex = (UserRemoteException) ex; assertEquals(UserBitShared.DremioPBError.ErrorType.UNSUPPORTED_OPERATION, urex.getErrorType()); } }
@Test public void testSelectEmptyNoCache() throws Exception { prepareTables("4376_5", false); try { runSQL("SELECT COUNT(*) AS \"count\" FROM dfs_test.\"4376_5/6041\""); fail("Query should've failed!"); } catch (UserRemoteException uex) { final String expectedMsg = "Table 'dfs_test.4376_5/6041' not found"; assertTrue(String.format("Error message should contain \"%s\" but was instead \"%s\"", expectedMsg, uex.getMessage()), uex.getMessage().contains(expectedMsg)); } }
@Test public void testDirectImpersonation_NoReadPermissions() throws Exception { try { // Table lineitem is owned by "user0_1:group0_1" with permissions 750. Now try to read the table as "user2_1". We // should expect a permission denied error as "user2_1" is not part of the "group0_1" updateClient(org1Users[2]); test(String.format("SELECT * FROM %s ORDER BY l_orderkey LIMIT 1", fullPath(org1Users[0], "lineitem"))); fail("query is expected to fail"); } catch(UserRemoteException e) { assertEquals(ErrorType.PERMISSION, e.getErrorType()); assertThat(e.getMessage(), containsString("PERMISSION ERROR: Access denied reading dataset miniDfsPlugin.\"/user/user0_1/lineitem\"")); } }
if (isFailureResult) { resultsListener.submissionFailed(UserRemoteException.create(queryResult.getError(0)));
@Test public void testBadLineDelimiterSkipLineNormalQuery() throws Exception { try { runSQL(QUERY_BAD_LINEDL_SKIP_SMALL); } catch (Exception ex) { if (!(ex instanceof UserRemoteException)) { fail("Unexpected Error"); } UserRemoteException urex = (UserRemoteException) ex; assertEquals(UserBitShared.DremioPBError.ErrorType.DATA_READ, urex.getErrorType()); } }
@Test @Ignore("empty table") public void testSelectEmptyWithCache() throws Exception { prepareTables("4376_4", true); try { runSQL("SELECT COUNT(*) AS \"count\" FROM dfs_test.\"4376_4/6041\""); fail("Query should've failed!"); } catch (UserRemoteException uex) { final String expectedMsg = "The table you tried to query is empty"; assertTrue(String.format("Error message should contain \"%s\" but was instead \"%s\"", expectedMsg, uex.getMessage()), uex.getMessage().contains(expectedMsg)); } }