@Override public void submissionFailed(UserException ex) { logger.debug("Query failed: " + ex.getMessage()); }
public static List<QueryError> of(UserException e) { switch(e.getErrorType()) { case PARSE: case PLAN: case VALIDATION: return ImmutableList.of(new QueryError(e.getMessage(), rangeOf(e))); default: return ImmutableList.of(); } }
@Test (expected = UserException.class) // Should be "Failure while parsing sql. SabotNode [rel#26:Subset#6.LOGICAL.ANY([]).[]] could not be implemented;". // Dremio will hit CanNotPlan, until we add code fix to transform the local LHS filter in left outer join properly. public void testDRILL1337_LocalLeftFilterLeftOutJoin() throws Exception { try { test("select count(*) from cp.\"tpch/nation.parquet\" n left outer join cp.\"tpch/region.parquet\" r on n.n_regionkey = r.r_regionkey and n.n_nationkey > 10;"); } catch (UserException e) { logger.info("***** Test resulted in expected failure: " + e.getMessage()); throw e; } }
@Override protected boolean matchesSafely(final UserException e) { // Use .contains(...) to compare expected and actual message as the exact messages may differ. return (expectedType == e.getErrorType()) && (expectedMessage == null || e.getMessage().contains(expectedMessage)) && (expectedContexts == null || FluentIterable.from(Arrays.asList(expectedContexts)).filter(new Predicate<String>() { @Override public boolean apply(String input) { for (String context : e.getContextStrings()) { if (context.contains(input)) { return true; } } return false; } }).size() == expectedContexts.length); }
@Override protected void describeMismatchSafely(final UserException e, final Description description) { description.appendText("UserException thrown was of type: ") .appendValue(e.getErrorType().toString()); if (expectedMessage != null) { description.appendText(" with message: \"") .appendText(e.getMessage()) .appendText("\""); } if (expectedContexts != null) { description.appendValueList(" with contexts {", ",", "}", e.getContextStrings()); } } }
@Test(expected = UserException.class) // Should get "At line 1, column 8: Column 'n_nationkey' is ambiguous" @Ignore("this no longer happens") public void testSelStarAmbiguousJoin() throws Exception { try { test("select x.n_nationkey, x.n_name, x.n_regionkey, x.r_name from (select * from cp.\"tpch/nation.parquet\" n, cp.\"tpch/region.parquet\" r where n.n_regionkey = r.r_regionkey) x " ) ; } catch (UserException e) { logger.info("***** Test resulted in expected failure: " + e.getMessage()); throw e; } }
@Test public void noMatchHardAffinity() throws Exception { try { final Wrapper wrapper = newSplitWrapper(200, 1, 20, Collections.singletonList(new EndpointAffinity(N1_EP1, 1.0, true, 20)), new ExecutionNodeMap(ImmutableList.of(N2_EP1)) ); INSTANCE.parallelizeFragment(wrapper, newParameters(SLICE_TARGET_DEFAULT, 5, 20), ImmutableList.of(N2_EP1)); fail("Should throw exception as affinity endpoint does not match active endpoint"); } catch (UserException uex) { assertTrue(uex.getMessage().startsWith("No executors are available for data with hard affinity.")); } }
public static QueryProfile.Builder addError(UserException ex, QueryProfile.Builder profileBuilder) { if (ex != null) { profileBuilder.setError(ex.getMessage()) .setVerboseError(ex.getVerboseMessage(false)) .setErrorId(ex.getErrorId()); if (ex.getErrorLocation() != null) { profileBuilder.setErrorNode(ex.getErrorLocation()); } } return profileBuilder; } }
@Test public void throwsProperly() throws Exception { final String username = "throwsProperly"; final StoragePlugin plugin = mock(StoragePlugin.class); final PermissionCheckCache checks = new PermissionCheckCache(DirectProvider.wrap(plugin), DirectProvider.wrap(1000L), 1000); when(plugin.hasAccessPermission(anyString(), any(NamespaceKey.class), any(DatasetConfig.class))) .thenThrow(new RuntimeException("you shall not pass")); try { checks.hasAccess(username, new NamespaceKey(Lists.newArrayList("what")), null, new MetadataStatsCollector()); fail(); } catch (UserException e) { assertEquals(UserBitShared.DremioPBError.ErrorType.PERMISSION, e.getErrorType()); assertEquals("Access denied reading dataset what.", e.getMessage()); } } }
@Test public void testSimplePrimitiveSchema_NoColumnsExistInTheSchema() throws Exception { final String file = AvroTestUtil.generateSimplePrimitiveSchema_NoNullValues().getFilePath(); final String sql = "select h_dummy1, e_dummy2 from dfs_root.\"" + file + "\""; try { test(sql); Assert.fail("Test should fail as h_dummy1 and e_dummy2 does not exist."); } catch(UserException ue) { Assert.assertTrue("Test should fail as h_dummy1 and e_dummy2 does not exist.", ue.getMessage().contains("Column 'h_dummy1' not found in any table")); } }
@Test public void withTasksExceedingTimeout() throws Exception { UserException ex = null; try { List<TimedRunnable<Void>> tasks = Lists.newArrayList(); for (int i = 0; i < 100; i++) { if ((i & (i + 1)) == 0) { tasks.add(new TestTask(2000)); } else { tasks.add(new TestTask(20000)); } } TimedRunnable.run("Execution with some tasks triggering timeout", logger, tasks, 16); } catch (UserException e) { ex = e; } assertNotNull("Expected a UserException", ex); assertThat(ex.getMessage(), containsString("Waited for 93750ms, but tasks for 'Execution with some tasks triggering timeout' are not " + "complete. Total runnable size 100, parallelism 16.")); }
@Test public void testUnsupportedRexNode() { try { // Create the data type factory. RelDataTypeFactory relFactory = SqlTypeFactoryImpl.INSTANCE; // Create the rex builder RexBuilder rex = new DremioRexBuilder(relFactory); RelDataType anyType = relFactory.createSqlType(SqlTypeName.ANY); List<RexNode> emptyList = new LinkedList<>(); ImmutableList<RexFieldCollation> e = ImmutableList.copyOf(new RexFieldCollation[0]); // create a dummy RexOver object. RexNode window = rex.makeOver(anyType, SqlStdOperatorTable.AVG, emptyList, emptyList, e, null, null, true, false, false, false); RexToExpr.toExpr(null, null, null, window); } catch (UserException e) { if (e.getMessage().contains(RexToExpr.UNSUPPORTED_REX_NODE_ERROR)) { // got expected error return return; } Assert.fail("Hit exception with unexpected error message"); } Assert.fail("Failed to raise the expected exception"); } }
@Test @Ignore public void testExceptionHandling() throws Exception { try { test("select * from cp.\"jsoninput/DRILL-2350.json\""); } catch(UserException e) { Assert.assertEquals(UserBitShared.DremioPBError.ErrorType.UNSUPPORTED_OPERATION, e.getOrCreatePBError(false).getErrorType()); String s = e.getMessage(); assertEquals("Expected Unsupported Operation Exception.", true, s.contains("Dremio does not support lists of different types.")); } }
@Test public void emptySelection() { boolean exThrown = false; try { recommender.getRules(new Selection("col", "883 N Shoreline Blvd.", 5, 0), TEXT); fail("not expected to reach here"); } catch (UserException e) { exThrown = true; assertEquals("text recommendation requires non-empty text selection", e.getMessage()); } assertTrue("expected a UserException", exThrown); }
@Test public void insertingDifferentEntityTypesAtSamePath() throws Exception { try (final KVStoreProvider kvstore = new LocalKVStoreProvider(DremioTest.CLASSPATH_SCAN_RESULT, null, true, false)) { kvstore.start(); final NamespaceService ns = new NamespaceServiceImpl(kvstore); addSpace(ns, "a"); thrown.expect(ConcurrentModificationException.class); addSource(ns, "a"); addFolder(ns, "a.foo"); // Try to add dataset with path "a.foo" try { addDS(ns, "a.foo"); fail("Expected the above call to fail"); } catch (UserException ex) { assertTrue(ex.getMessage().contains("There already exists an entity of type [FOLDER] at given path [a.foo]")); } // Try to add folder with path "a.foo". There already a folder at "a.foo" try { addFolder(ns, "a.foo"); fail("Expected the above call to fail"); } catch (UserException ex) { assertTrue(ex.getMessage().contains("There already exists an entity of type [FOLDER] at given path [a.foo]")); } } }
@Test public void testDropTable() throws Exception { // create tables as user2 updateClient(user2); test(String.format("use \"%s.user2_workspace1\"", MINIDFS_STORAGE_PLUGIN_NAME)); // create a table that can be dropped by another user in a different group test("create table parquet_table_775 as select * from cp.\"employee.json\""); // create a table that cannot be dropped by another user test(String.format("use \"%s.user2_workspace2\"", MINIDFS_STORAGE_PLUGIN_NAME)); test("create table parquet_table_700 as select * from cp.\"employee.json\""); // Drop tables as user1 updateClient(user1); test(String.format("use \"%s.user2_workspace1\"", MINIDFS_STORAGE_PLUGIN_NAME)); testBuilder() .sqlQuery("drop table parquet_table_775") .unOrdered() .baselineColumns("ok", "summary") .baselineValues(true, String.format("Table [%s] dropped", "parquet_table_775")) .go(); test(String.format("use \"%s.user2_workspace2\"", MINIDFS_STORAGE_PLUGIN_NAME)); boolean dropFailed = false; try { test("drop table parquet_table_700"); } catch (UserException e) { Assert.assertTrue(e.getMessage().contains("PERMISSION ERROR")); dropFailed = true; } Assert.assertTrue("Permission checking failed during drop table", dropFailed); }
test(String.format(DROP_TABLE, tableName)); } catch (UserException e) { Assert.assertTrue(e.getMessage().contains("VALIDATION ERROR")); dropFailed = true;
private void testSingleMode(String fileName) throws Exception{ test(SINGLE_MODE); CoordinationProtos.NodeEndpoint endpoint = nodes[0].getContext().getEndpoint(); String controlsString = "{\"injections\":[{" + "\"address\":\"" + endpoint.getAddress() + "\"," + "\"port\":\"" + endpoint.getUserPort() + "\"," + "\"type\":\"exception\"," + "\"siteClass\":\"" + "com.dremio.exec.physical.impl.ScanBatch" + "\"," + "\"desc\":\"" + "next-allocate" + "\"," + "\"nSkip\":0," + "\"nFire\":1," + "\"exceptionClass\":\"" + OutOfMemoryException.class.getName() + "\"" + "}]}"; ControlsInjectionUtil.setControls(client, controlsString); String query = getFile(fileName); try { test(query); } catch(UserException uex) { DremioPBError error = uex.getOrCreatePBError(false); Assert.assertEquals(DremioPBError.ErrorType.RESOURCE, error.getErrorType()); Assert.assertTrue("Error message isn't related to memory error", uex.getMessage().contains(UserException.MEMORY_ERROR_MSG)); } }
Assert.assertEquals(DremioPBError.ErrorType.RESOURCE, error.getErrorType()); Assert.assertTrue("Error message isn't related to memory error", uex.getMessage().contains(UserException.MEMORY_ERROR_MSG));
@Test public void testReplaceInvalidReplacedValues() { boolean exThrown = false; try { VirtualDatasetState state = new VirtualDatasetState() .setFrom(nameDSRef); Expression exp0 = new ExpColumnReference("bar").wrap(); FieldTransformationBase transf1 = new FieldReplaceValue() .setReplacedValuesList(Collections.<String>emptyList()) .setReplacementType(DATE) .setReplaceType(ReplaceType.VALUE) .setReplacementValue("2016-11-05"); Expression exp = new ExpFieldTransformation(transf1.wrap(), exp0).wrap(); SQLGenerator.generateSQL(state.setColumnsList(asList(new Column("foo", exp)))); fail("not expected to reach here"); } catch (UserException e) { exThrown = true; assertEquals("select at least one value to replace", e.getMessage()); } assertTrue("expected a UserException", exThrown); }