use of com.facebook.presto.sql.parser.SqlParser in project presto by prestodb.
the class TestClientOptions method testUpdateSessionParameters.
@Test
public void testUpdateSessionParameters() throws Exception {
ClientOptions options = new ClientOptions();
ClientSession session = options.toClientSession();
SqlParser sqlParser = new SqlParser();
ImmutableMap<String, String> existingProperties = ImmutableMap.of("query_max_memory", "10GB", "distributed_join", "true");
ImmutableMap<String, String> preparedStatements = ImmutableMap.of("my_query", "select * from foo");
session = Console.processSessionParameterChange(sqlParser.createStatement("USE test_catalog.test_schema"), session, existingProperties, preparedStatements);
assertEquals(session.getCatalog(), "test_catalog");
assertEquals(session.getSchema(), "test_schema");
assertEquals(session.getProperties().get("query_max_memory"), "10GB");
assertEquals(session.getProperties().get("distributed_join"), "true");
assertEquals(session.getPreparedStatements().get("my_query"), "select * from foo");
session = Console.processSessionParameterChange(sqlParser.createStatement("USE test_schema_b"), session, existingProperties, preparedStatements);
assertEquals(session.getCatalog(), "test_catalog");
assertEquals(session.getSchema(), "test_schema_b");
assertEquals(session.getProperties().get("query_max_memory"), "10GB");
assertEquals(session.getProperties().get("distributed_join"), "true");
assertEquals(session.getPreparedStatements().get("my_query"), "select * from foo");
session = Console.processSessionParameterChange(sqlParser.createStatement("USE test_catalog_2.test_schema"), session, existingProperties, preparedStatements);
assertEquals(session.getCatalog(), "test_catalog_2");
assertEquals(session.getSchema(), "test_schema");
assertEquals(session.getProperties().get("query_max_memory"), "10GB");
assertEquals(session.getProperties().get("distributed_join"), "true");
assertEquals(session.getPreparedStatements().get("my_query"), "select * from foo");
}
use of com.facebook.presto.sql.parser.SqlParser in project presto by prestodb.
the class PrestoVerifier method run.
public int run(String[] args) throws Exception {
if (args.length > 0) {
System.setProperty("config", args[0]);
}
ImmutableList.Builder<Module> builder = ImmutableList.<Module>builder().add(new PrestoVerifierModule()).addAll(getAdditionalModules());
Bootstrap app = new Bootstrap(builder.build());
Injector injector = app.strictConfig().initialize();
try {
VerifierConfig config = injector.getInstance(VerifierConfig.class);
injector.injectMembers(this);
Set<String> supportedEventClients = injector.getInstance(Key.get(new TypeLiteral<Set<String>>() {
}, Names.named(SUPPORTED_EVENT_CLIENTS)));
for (String clientType : config.getEventClients()) {
checkArgument(supportedEventClients.contains(clientType), "Unsupported event client: %s", clientType);
}
Set<EventClient> eventClients = injector.getInstance(Key.get(new TypeLiteral<Set<EventClient>>() {
}));
VerifierDao dao = new DBI(config.getQueryDatabase()).onDemand(VerifierDao.class);
ImmutableList.Builder<QueryPair> queriesBuilder = ImmutableList.builder();
for (String suite : config.getSuites()) {
queriesBuilder.addAll(dao.getQueriesBySuite(suite, config.getMaxQueries()));
}
List<QueryPair> queries = queriesBuilder.build();
queries = applyOverrides(config, queries);
queries = filterQueryTypes(new SqlParser(getParserOptions()), config, queries);
queries = filterQueries(queries);
if (config.getShadowWrites()) {
Sets.SetView<QueryType> allowedTypes = Sets.union(config.getTestQueryTypes(), config.getControlQueryTypes());
checkArgument(!Sets.intersection(allowedTypes, ImmutableSet.of(CREATE, MODIFY)).isEmpty(), "CREATE or MODIFY queries must be allowed in test or control to use write shadowing");
queries = rewriteQueries(new SqlParser(getParserOptions()), config, queries);
}
// Load jdbc drivers if needed
if (config.getAdditionalJdbcDriverPath() != null) {
List<URL> urlList = getUrls(config.getAdditionalJdbcDriverPath());
URL[] urls = new URL[urlList.size()];
urlList.toArray(urls);
if (config.getTestJdbcDriverName() != null) {
loadJdbcDriver(urls, config.getTestJdbcDriverName());
}
if (config.getControlJdbcDriverName() != null) {
loadJdbcDriver(urls, config.getControlJdbcDriverName());
}
}
// TODO: construct this with Guice
Verifier verifier = new Verifier(System.out, config, eventClients);
return verifier.run(queries);
} finally {
injector.getInstance(LifeCycleManager.class).stop();
}
}
use of com.facebook.presto.sql.parser.SqlParser in project presto by prestodb.
the class TestShadowing method testCreateTableAsSelect.
@Test
public void testCreateTableAsSelect() throws Exception {
handle.execute("CREATE TABLE \"my_test_table\" (column1 BIGINT, column2 DOUBLE)");
SqlParser parser = new SqlParser();
Query query = new Query(CATALOG, SCHEMA, ImmutableList.of(), "CREATE TABLE my_test_table AS SELECT 1 column1, CAST(2.0 AS DOUBLE) column2 LIMIT 1", ImmutableList.of(), null, null, ImmutableMap.of());
QueryRewriter rewriter = new QueryRewriter(parser, URL, QualifiedName.of("tmp_"), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), 1, new Duration(10, SECONDS));
Query rewrittenQuery = rewriter.shadowQuery(query);
assertEquals(rewrittenQuery.getPreQueries().size(), 1);
assertEquals(rewrittenQuery.getPostQueries().size(), 1);
CreateTableAsSelect createTableAs = (CreateTableAsSelect) parser.createStatement(rewrittenQuery.getPreQueries().get(0));
assertEquals(createTableAs.getName().getParts().size(), 1);
assertTrue(createTableAs.getName().getSuffix().startsWith("tmp_"));
assertFalse(createTableAs.getName().getSuffix().contains("my_test_table"));
assertEquals(PrestoVerifier.statementToQueryType(parser, rewrittenQuery.getQuery()), READ);
Table table = new Table(createTableAs.getName());
SingleColumn column1 = new SingleColumn(new FunctionCall(QualifiedName.of("checksum"), ImmutableList.of(new Identifier("column1"))));
SingleColumn column2 = new SingleColumn(new FunctionCall(QualifiedName.of("checksum"), ImmutableList.of(new FunctionCall(QualifiedName.of("round"), ImmutableList.of(new Identifier("column2"), new LongLiteral("1"))))));
Select select = new Select(false, ImmutableList.of(column1, column2));
QuerySpecification querySpecification = new QuerySpecification(select, Optional.of(table), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty());
assertEquals(parser.createStatement(rewrittenQuery.getQuery()), new com.facebook.presto.sql.tree.Query(Optional.empty(), querySpecification, Optional.empty(), Optional.empty()));
assertEquals(parser.createStatement(rewrittenQuery.getPostQueries().get(0)), new DropTable(createTableAs.getName(), true));
}
use of com.facebook.presto.sql.parser.SqlParser in project presto by prestodb.
the class TestRemoveUnsupportedDynamicFilters method removeUnsupportedDynamicFilters.
PlanNode removeUnsupportedDynamicFilters(PlanNode root) {
return getQueryRunner().inTransaction(session -> {
// metadata.getCatalogHandle() registers the catalog for the transaction
session.getCatalog().ifPresent(catalog -> metadata.getCatalogHandle(session, catalog));
PlanNode rewrittenPlan = new RemoveUnsupportedDynamicFilters(metadata.getFunctionAndTypeManager()).optimize(root, session, TypeProvider.empty(), new PlanVariableAllocator(), new PlanNodeIdAllocator(), WarningCollector.NOOP);
new DynamicFiltersChecker().validate(rewrittenPlan, session, metadata, new SqlParser(), TypeProvider.empty(), WarningCollector.NOOP);
return rewrittenPlan;
});
}
use of com.facebook.presto.sql.parser.SqlParser in project presto by prestodb.
the class TestStatisticsWriterNode method getJsonCodec.
private JsonCodec<StatisticsWriterNode> getJsonCodec() throws Exception {
Module module = binder -> {
SqlParser sqlParser = new SqlParser();
FunctionAndTypeManager functionAndTypeManager = createTestFunctionAndTypeManager();
binder.install(new JsonModule());
binder.install(new HandleJsonModule());
binder.bind(SqlParser.class).toInstance(sqlParser);
binder.bind(TypeManager.class).toInstance(functionAndTypeManager);
newSetBinder(binder, Type.class);
jsonBinder(binder).addDeserializerBinding(Type.class).to(TypeDeserializer.class);
jsonCodecBinder(binder).bindJsonCodec(StatisticsWriterNode.class);
};
Bootstrap app = new Bootstrap(ImmutableList.of(module));
Injector injector = app.doNotInitializeLogging().quiet().initialize();
HandleResolver handleResolver = injector.getInstance(HandleResolver.class);
handleResolver.addConnectorName("test", new TestingHandleResolver());
return injector.getInstance(new Key<JsonCodec<StatisticsWriterNode>>() {
});
}
Aggregations