删除表和索引

可以使用 TableRequest API 删除 NoSQL 表。

TableRequest 指定的操作的执行是异步的。这些操作可能是长时间运行的操作。TableResult 是从 TableRequest 操作返回的,它将封装表的状态。有关 TableRequest 类及其方法的更多详细信息,请参阅 Oracle NoSQL Java SDK API Reference

Download the full code AlterTable.java from the examples here.

/*Drop the table*/
private static void dropTab(NoSQLHandle handle) throws Exception {
   String dropTableDDL = "DROP TABLE " + tableName;
   TableRequest treq = new TableRequest().setStatement(dropTableDDL);
   TableResult tres = handle.tableRequest(treq);
   tres.waitForCompletion(handle, 60000, /* wait 60 sec */
       1000); /* delay ms for poll */
   System.out.println("Table " + tableName + " is dropped");
}

可以使用 borneo.TableRequest 类删除表。对 borneo.NoSQLHandle.table_request() 的所有调用都是异步的,因此需要检查结果并调用 borneo.TableResult.wait_for_completion() 以等待操作完成。有关 table_request 及其方法的更多详细信息,请参阅 Oracle NoSQL Python SDK API Reference

Download the full code AlterTable.py from the examples here.

def drop_table(handle):
   statement = '''DROP TABLE stream_acct'''
   request = TableRequest().set_statement(statement)
   table_result = handle.do_table_request(request, 40000, 3000)
   table_result.wait_for_completion(handle, 40000, 3000)
   print('Dropped table: stream_acct')

可以使用 TableRequest 类删除表。TableRequest 指定的操作的执行是异步的。这些操作可能是长时间运行的操作。此请求用作 Client.DoTableRequest() 操作的输入,该操作将返回可用于轮询的 TableResult,直到表达到所需状态。有关 TableRequest 类的各种方法的更多详细信息,请参阅 Oracle NoSQL Go SDK API Reference

Download the full code AlterTable.go from the examples here.

//drop an existing table
func dropTable(client *nosqldb.Client, err error, tableName string)(){
   stmt := fmt.Sprintf("DROP TABLE %s",tableName)
   tableReq := &nosqldb.TableRequest{
		Statement: stmt,
   }
   tableRes, err := client.DoTableRequest(tableReq)
   return
}

可以使用 tableDDL 方法删除表。此方法为异步方法,返回 Promise of TableResultTableResult 是一个普通的 JavaScript 对象,在执行 DDL 操作后封装表的状态。有关方法详细信息,请参见 NoSQLClient 类。

Download the full JavaScript code AlterTable.js from the examples here and the full TypeScript code AlterTable.ts from the examples here.

//drop a table
async function dropTable(handle) {
   const dropDDL = `DROP TABLE ${TABLE_NAME}`;
   let res =  await handle.tableDDL(dropDDL);
   console.log('Table dropped: ' + TABLE_NAME);
}

可以使用 ExecuteTableDDLAsyncExecuteTableDDLWithCompletionAsync 方法之一删除表。这两种方法都返回 Task<TableResult>TableResult 实例在执行 DDL 操作后封装表的状态。有关这些方法的更多详细信息,请参阅 Oracle NoSQL Dotnet SDK API Reference

Download the full code AlterTable.cs from the examples here.

private static async Task dropTable(NoSQLClient client){
   var sql = $@"DROP TABLE {TableName}";
   var tableResult = await client.ExecuteTableDDLAsync(sql);
   // Wait for the operation completion
   await tableResult.WaitForCompletionAsync();
   Console.WriteLine("  Table {0} is dropped", tableResult.TableName);
}

可以使用 TableRequest API 删除 NoSQL 表的索引。

TableRequest 类指定的操作的执行是异步的。这些操作可能是长时间运行的操作。TableResult 是从 TableRequest 操作返回的,它将封装表的状态。有关 TableRequest 类及其方法的更多详细信息,请参阅 Oracle NoSQL Java SDK API Reference

Download the full code Indexes.java from the examples here.

/* Drop the index acct_episodes*/
private static void dropIndex(NoSQLHandle handle) throws Exception {
   String dropIndexDDL = "DROP INDEX acct_episodes ON " + tableName;
   TableRequest treq = new TableRequest().setStatement(dropIndexDDL);
   TableResult tres = handle.tableRequest(treq);
   tres.waitForCompletion(handle, 60000, /* wait 60 sec */
            1000); /* delay ms for poll */
   System.out.println("Index acct_episodes on " + tableName + " is dropped");
}

可以使用 borneo.TableRequest 类删除表索引。对 borneo.NoSQLHandle.table_request() 的所有调用都是异步的,因此需要检查结果并调用 borneo.TableResult.wait_for_completion() 以等待操作完成。有关 table_request 及其方法的更多详细信息,请参阅 Oracle NoSQL Python SDK API Reference

Download the full code Indexes.py from the examples here.

#drop the index
def drop_index(handle):
   statement = '''DROP INDEX acct_episodes ON stream_acct'''
   request = TableRequest().set_statement(statement)
   table_result = handle.do_table_request(request, 40000, 3000)
   table_result.wait_for_completion(handle, 40000, 3000)
   print('Index acct_episodes on the table stream_acct is dropped')

可以使用 TableRequest 类删除表索引。TableRequest 指定的操作的执行是异步的。这些操作可能是长时间运行的操作。此请求用作 Client.DoTableRequest() 操作的输入,该操作将返回可用于轮询的 TableResult,直到表达到所需状态。有关 TableRequest 类的各种方法的更多详细信息,请参阅 Oracle NoSQL Go SDK API Reference

Download the full code Indexes.go from the examples here.

//drops an index from a table
func dropIndex(client *nosqldb.Client, err error, tableName string)(){
   stmt := fmt.Sprintf("DROP INDEX acct_episodes ON %s",tableName)
   tableReq := &nosqldb.TableRequest{
		Statement: stmt,
   }
   tableRes, err := client.DoTableRequest(tableReq)
   if err != nil {
      fmt.Printf("cannot initiate DROP INDEX request: %v\n", err)
      return
   }
   // The drop index request is asynchronous, wait for drop index to complete.
   _, err = tableRes.WaitForCompletion(client, 60*time.Second, time.Second)
   if err != nil {
      fmt.Printf("Error finishing DROP INDEX request: %v\n", err)
      return
   }
   fmt.Println("Dropped index acct_episodes on table ", tableName)
   return
}

可以使用 tableDDL 方法删除表索引。此方法为异步方法,返回 Promise of TableResultTableResult 是一个普通的 JavaScript 对象,其中包含 DDL 操作的状态,例如 TableState、name、schema 和 TableLimits。有关方法详细信息,请参见 NoSQLClient 类。

Download the full JavaScript code Indexes.js from the examples here and the full TypeScript code Indexes.ts from the examples here.

//drops an index
async function dropIndex(handle) {
   const dropindDDL = `DROP INDEX acct_episodes ON ${TABLE_NAME}`;
   let res =  await handle.tableDDL(dropindDDL);
   console.log('Index acct_episodes is dropped from table: ' + TABLE_NAME);
}

可以使用 ExecuteTableDDLAsyncExecuteTableDDLWithCompletionAsync 方法之一删除表索引。这两种方法都返回 Task<TableResult>TableResult 实例包含 DDL 操作的状态,例如 TableState 和表方案。有关这些方法的更多详细信息,请参阅 Oracle NoSQL Dotnet SDK API Reference

Download the full code Indexes.cs from the examples here.

private static async Task dropIndex(NoSQLClient client){
   var sql = $@"DROP INDEX acct_episodes on {TableName}";
   var tableResult = await client.ExecuteTableDDLAsync(sql);
   // Wait for the operation completion
   await tableResult.WaitForCompletionAsync();
   Console.WriteLine(" Index acct_episodes is dropped from table Table {0}",
                tableResult.TableName);
}

相关主题