Java 类com.facebook.presto.sql.tree.DropTable 实例源码

项目:presto    文件:DropTableTask.java   
@Override
public CompletableFuture<?> execute(DropTable statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine)
{
    Session session = stateMachine.getSession();
    QualifiedObjectName tableName = createQualifiedObjectName(session, statement, statement.getTableName());

    Optional<TableHandle> tableHandle = metadata.getTableHandle(session, tableName);
    if (!tableHandle.isPresent()) {
        if (!statement.isExists()) {
            throw new SemanticException(MISSING_TABLE, statement, "Table '%s' does not exist", tableName);
        }
        return completedFuture(null);
    }

    accessControl.checkCanDropTable(session.getRequiredTransactionId(), session.getIdentity(), tableName);

    metadata.dropTable(session, tableHandle.get());

    return completedFuture(null);
}
项目:presto-query-formatter    文件:StatementFormatter.java   
@Override
protected Void visitDropTable(DropTable node, Integer context)
{
    builder.append("DROP TABLE ");
    if (node.isExists()) {
        builder.append("IF EXISTS ");
    }
    builder.append(node.getTableName());

    return null;
}
项目:sql4es    文件:ESStatement.java   
@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");
}
项目:sql4es    文件:ESUpdateState.java   
/**
 * Executes the {@link BulkRequest} being hold by this state.
 * @return an integer indicator for each executed request: Statement.SUCCESS_NO_INFO for success, 
 * else Statement.EXECUTE_FAILED)
 */
public int[] executeBulk(){
    int[] result = new int[bulkList.size()];
    SqlParser parser = new SqlParser();
    for(int i=0; i<bulkList.size(); i++) try{
        String sql = bulkList.get(i);
        com.facebook.presto.sql.tree.Statement st = parser.createStatement(sql);
        if(st instanceof DropTable){
            this.execute(sql, (DropTable)st);
        }else if(st instanceof DropView){
            this.execute(sql, (DropView)st);
        }else if(st instanceof CreateTable){
            this.execute(sql, (CreateTable)st, this.statement.getConnection().getSchema());
        }else if(st instanceof CreateTableAsSelect){
            this.execute(sql, (CreateTableAsSelect)st, this.statement.getConnection().getSchema());
        }else if(st instanceof CreateView){
            this.execute(sql, (CreateView)st, this.statement.getConnection().getSchema());
        }else if(st instanceof Delete){
            this.execute(sql, (Delete)st, this.statement.getConnection().getSchema());
        }else  if(st instanceof Insert){
            this.execute(sql, (Insert)st, this.statement.getConnection().getSchema());
        }
        result[i]= Statement.SUCCESS_NO_INFO;
    }catch (Exception e){
        result[i] = Statement.EXECUTE_FAILED;
    }
    this.clearBulk();
    return result;
}
项目:sql4es    文件:ESUpdateState.java   
/**
 * Deletes the INDEX with the specified name 
 * @param sql
 * @param drop
 * @return
 * @throws SQLException 
 */
public int execute(String sql, DropTable drop) throws SQLException {
    String index = drop.getTableName().toString();
    index = Heading.findOriginal(sql.trim()+";", index, "table\\s+",";");
    DeleteIndexResponse response = client.admin().indices().prepareDelete(index).execute().actionGet();
    if(!response.isAcknowledged()) throw new SQLException("Elasticsearch failed to delete the specified index");
    return 0;
}
项目:presto    文件:SqlFormatter.java   
@Override
protected Void visitDropTable(DropTable node, Integer context)
{
    builder.append("DROP TABLE ");
    if (node.isExists()) {
        builder.append("IF EXISTS ");
    }
    builder.append(node.getTableName());

    return null;
}
项目:presto    文件:TestSqlParser.java   
@Test
public void testDropTable()
        throws Exception
{
    assertStatement("DROP TABLE a", new DropTable(QualifiedName.of("a"), false));
    assertStatement("DROP TABLE a.b", new DropTable(QualifiedName.of("a", "b"), false));
    assertStatement("DROP TABLE a.b.c", new DropTable(QualifiedName.of("a", "b", "c"), false));

    assertStatement("DROP TABLE IF EXISTS a", new DropTable(QualifiedName.of("a"), true));
    assertStatement("DROP TABLE IF EXISTS a.b", new DropTable(QualifiedName.of("a", "b"), true));
    assertStatement("DROP TABLE IF EXISTS a.b.c", new DropTable(QualifiedName.of("a", "b", "c"), true));
}
项目:EchoQuery    文件:SqlFormatter.java   
@Override
protected Void visitDropTable(DropTable node, Integer context)
{
    builder.append("DROP TABLE ");
    if (node.isExists()) {
        builder.append("IF EXISTS ");
    }
    builder.append(node.getTableName());

    return null;
}
项目:presto    文件:AstBuilder.java   
@Override
public Node visitDropTable(SqlBaseParser.DropTableContext context)
{
    return new DropTable(getLocation(context), getQualifiedName(context.qualifiedName()), context.EXISTS() != null);
}
项目:airpal    文件:InputReferenceExtractor.java   
@Override
protected CatalogSchemaContext visitDropTable(DropTable node, CatalogSchemaContext context)
{
    references.add(qualifiedNameToTable(node.getTableName(), context));
    return context;
}