@Override public int executeUpdate(String sql) throws SQLException { //System.out.println("QUERY: ["+sql+"]"); sql = sql.replaceAll("\r", " ").replaceAll("\n", " ").trim(); // custom stuff to support UPDATE statements since Presto does not parse it if(sql.toLowerCase().startsWith("update")){ return updateState.execute(sql); } com.facebook.presto.sql.tree.Statement statement = parser.createStatement(sql); if(statement instanceof Query) throw new SQLException("A regular query cannot be executed as an Update"); if(statement instanceof Insert){ //if(connection.getSchema() == null) throw new SQLException("No active index set for this driver. Pleas specify an active index or alias by executing 'USE <index/alias>' first"); return updateState.execute(sql, (Insert)statement, connection.getSchema()); }else if(statement instanceof Delete){ if(connection.getSchema() == null) throw new SQLException("No active index set for this driver. Pleas specify an active index or alias by executing 'USE <index/alias>' first"); return updateState.execute(sql, (Delete)statement, connection.getSchema()); }else if(statement instanceof CreateTable){ return updateState.execute(sql, (CreateTable)statement, connection.getSchema()); }else if(statement instanceof CreateTableAsSelect){ return updateState.execute(sql, (CreateTableAsSelect)statement, connection.getSchema()); }else if(statement instanceof CreateView){ return updateState.execute(sql, (CreateView)statement, connection.getSchema()); }else if(statement instanceof Use){ connection.setSchema( ((Use)statement).getSchema()); //connection.getTypeMap(); // updates the type mappings found in properties return 0; }else if(statement instanceof DropTable){ return updateState.execute(sql, (DropTable)statement); }else if(statement instanceof DropView){ return updateState.execute(sql, (DropView)statement); }throw new SQLFeatureNotSupportedException("Unable to parse provided update sql"); }
static ClientSession processSessionParameterChange(Object parsedStatement, ClientSession session, Map<String, String> existingProperties) { if (parsedStatement instanceof Use) { Use use = (Use) parsedStatement; session = withCatalogAndSchema(session, use.getCatalog().orElse(session.getCatalog()), use.getSchema()); session = withSessionProperties(session, existingProperties); } return session; }
@Override protected RelationType visitUse(Use node, AnalysisContext context) { analysis.setUpdateType("USE"); throw new SemanticException(NOT_SUPPORTED, node, "USE statement is not supported"); }
private static boolean isSessionParameterChange(Object statement) { return statement instanceof Use; }
@Override public Node visitUse(SqlBaseParser.UseContext context) { return new Use(getLocation(context), getTextIfPresent(context.catalog), context.schema.getText()); }
@Override protected CatalogSchemaContext visitUse(Use node, CatalogSchemaContext context) { return new CatalogSchemaContext(node.getCatalog().orElse(context.getCatalog()), node.getSchema()); }