use of com.facebook.presto.spi.WarningCollector in project presto by prestodb.
the class TestPlannerWarnings method assertPlannerWarnings.
public static void assertPlannerWarnings(LocalQueryRunner queryRunner, @Language("SQL") String sql, Map<String, String> sessionProperties, List<WarningCode> expectedWarnings, Optional<List<Rule<?>>> rules) {
Session.SessionBuilder sessionBuilder = testSessionBuilder().setCatalog(queryRunner.getDefaultSession().getCatalog().get()).setSchema(queryRunner.getDefaultSession().getSchema().get());
sessionProperties.forEach(sessionBuilder::setSystemProperty);
WarningCollector warningCollector = new DefaultWarningCollector(new WarningCollectorConfig(), WarningHandlingLevel.NORMAL);
try {
queryRunner.inTransaction(sessionBuilder.build(), transactionSession -> {
if (rules.isPresent()) {
createPlan(queryRunner, transactionSession, sql, warningCollector, rules.get());
} else {
queryRunner.createPlan(transactionSession, sql, LogicalPlanner.Stage.CREATED, false, warningCollector);
}
return null;
});
} catch (SemanticException e) {
// ignore
}
Set<WarningCode> warnings = warningCollector.getWarnings().stream().map(PrestoWarning::getWarningCode).collect(toImmutableSet());
for (WarningCode expectedWarning : expectedWarnings) {
if (!warnings.contains(expectedWarning)) {
fail("Expected warning: " + expectedWarning);
}
}
}
use of com.facebook.presto.spi.WarningCollector in project presto by prestodb.
the class TestCreateFunctionTask method testCreateTemporaryFunction.
@Test
public void testCreateTemporaryFunction() {
SqlParser parser = new SqlParser();
String sqlString = "CREATE TEMPORARY FUNCTION foo() RETURNS int RETURN 1";
CreateFunction statement = (CreateFunction) parser.createStatement(sqlString, ParsingOptions.builder().build());
TransactionManager transactionManager = createTestTransactionManager();
QueryStateMachine stateMachine = createQueryStateMachine(sqlString, TEST_SESSION, false, transactionManager, executorService, metadataManager);
WarningCollector warningCollector = stateMachine.getWarningCollector();
CreateFunctionTask createFunctionTask = new CreateFunctionTask(parser);
createFunctionTask.execute(statement, transactionManager, metadataManager, new AllowAllAccessControl(), TEST_SESSION, emptyList(), warningCollector);
assertEquals(createFunctionTask.getAddedSessionFunctions().size(), 1);
}
use of com.facebook.presto.spi.WarningCollector in project presto by prestodb.
the class TestCreateFunctionTask method testCreateTemporaryFunctionWithSameNameFails.
@Test(expectedExceptions = PrestoException.class, expectedExceptionsMessageRegExp = "Session function .* has already been defined")
public void testCreateTemporaryFunctionWithSameNameFails() {
SqlParser parser = new SqlParser();
String sqlString = "CREATE TEMPORARY FUNCTION foo() RETURNS int RETURN 1";
CreateFunction statement = (CreateFunction) parser.createStatement(sqlString, ParsingOptions.builder().build());
TransactionManager transactionManager = createTestTransactionManager();
QueryStateMachine stateMachine = createQueryStateMachine(sqlString, TEST_SESSION, false, transactionManager, executorService, metadataManager);
WarningCollector warningCollector = stateMachine.getWarningCollector();
CreateFunctionTask createFunctionTask = new CreateFunctionTask(parser);
createFunctionTask.execute(statement, transactionManager, metadataManager, new AllowAllAccessControl(), TEST_SESSION, emptyList(), warningCollector);
createFunctionTask.execute(statement, transactionManager, metadataManager, new AllowAllAccessControl(), TEST_SESSION, emptyList(), warningCollector);
}
use of com.facebook.presto.spi.WarningCollector in project presto by prestodb.
the class TestCreateMaterializedViewTask method testCreateMaterializedViewNotExistsTrue.
@Test
public void testCreateMaterializedViewNotExistsTrue() {
SqlParser parser = new SqlParser();
String sql = String.format("CREATE MATERIALIZED VIEW IF NOT EXISTS %s AS SELECT 2021 AS col_0 FROM %s", MATERIALIZED_VIEW_A, TABLE_A);
CreateMaterializedView statement = (CreateMaterializedView) parser.createStatement(sql, ParsingOptions.builder().build());
QueryStateMachine stateMachine = QueryStateMachine.begin(sql, Optional.empty(), testSession, URI.create("fake://uri"), new ResourceGroupId("test"), Optional.empty(), false, transactionManager, accessControl, executorService, metadata, WarningCollector.NOOP);
WarningCollector warningCollector = stateMachine.getWarningCollector();
CreateMaterializedViewTask createMaterializedViewTask = new CreateMaterializedViewTask(parser);
getFutureValue(createMaterializedViewTask.execute(statement, transactionManager, metadata, accessControl, testSession, emptyList(), warningCollector));
assertEquals(metadata.getCreateMaterializedViewCallCount(), 1);
}
use of com.facebook.presto.spi.WarningCollector in project presto by prestodb.
the class TestCreateMaterializedViewTask method testCreateMaterializedViewExistsFalse.
@Test
public void testCreateMaterializedViewExistsFalse() {
SqlParser parser = new SqlParser();
String sql = String.format("CREATE MATERIALIZED VIEW %s AS SELECT 2021 AS col_0 FROM %s", MATERIALIZED_VIEW_B, TABLE_A);
CreateMaterializedView statement = (CreateMaterializedView) parser.createStatement(sql, ParsingOptions.builder().build());
QueryStateMachine stateMachine = QueryStateMachine.begin(sql, Optional.empty(), testSession, URI.create("fake://uri"), new ResourceGroupId("test"), Optional.empty(), false, transactionManager, accessControl, executorService, metadata, WarningCollector.NOOP);
WarningCollector warningCollector = stateMachine.getWarningCollector();
try {
getFutureValue(new CreateMaterializedViewTask(parser).execute(statement, transactionManager, metadata, accessControl, testSession, emptyList(), warningCollector));
fail("expected exception");
} catch (RuntimeException e) {
// Expected
assertTrue(e instanceof PrestoException);
PrestoException prestoException = (PrestoException) e;
assertEquals(prestoException.getErrorCode(), ALREADY_EXISTS.toErrorCode());
}
assertEquals(metadata.getCreateMaterializedViewCallCount(), 0);
}
Aggregations