Las traducciones son generadas a través de traducción automática. En caso de conflicto entre la traducción y la version original de inglés, prevalecerá la version en inglés.
Actualizar tabla
Puede utilizar los siguientes fragmentos de código para actualizar una tabla.
nota
Estos fragmentos de código se basan en aplicaciones de muestra completas en. GitHub
- Java
-
public void updateTable() { System.out.println("Updating table"); UpdateTableRequest updateTableRequest = new UpdateTableRequest(); updateTableRequest.setDatabaseName(DATABASE_NAME); updateTableRequest.setTableName(TABLE_NAME); final RetentionProperties retentionProperties = new RetentionProperties() .withMemoryStoreRetentionPeriodInHours(HT_TTL_HOURS) .withMagneticStoreRetentionPeriodInDays(CT_TTL_DAYS); updateTableRequest.setRetentionProperties(retentionProperties); amazonTimestreamWrite.updateTable(updateTableRequest); System.out.println("Table updated"); }
- Java v2
-
public void updateTable() { System.out.println("Updating table"); final RetentionProperties retentionProperties = RetentionProperties.builder() .memoryStoreRetentionPeriodInHours(HT_TTL_HOURS) .magneticStoreRetentionPeriodInDays(CT_TTL_DAYS).build(); final UpdateTableRequest updateTableRequest = UpdateTableRequest.builder() .databaseName(DATABASE_NAME).tableName(TABLE_NAME).retentionProperties(retentionProperties).build(); timestreamWriteClient.updateTable(updateTableRequest); System.out.println("Table updated"); }
- Go
-
// Update table. magneticStoreRetentionPeriodInDays := int64(7 * 365) memoryStoreRetentionPeriodInHours := int64(24) updateTableInput := ×treamwrite.UpdateTableInput{ DatabaseName: aws.String(*databaseName), TableName: aws.String(*tableName), RetentionProperties: ×treamwrite.RetentionProperties{ MagneticStoreRetentionPeriodInDays: &magneticStoreRetentionPeriodInDays, MemoryStoreRetentionPeriodInHours: &memoryStoreRetentionPeriodInHours, }, } updateTableOutput, err := writeSvc.UpdateTable(updateTableInput) if err != nil { fmt.Println("Error:") fmt.Println(err) } else { fmt.Println("Update table is successful, below is the output:") fmt.Println(updateTableOutput) }
- Python
-
def update_table(self): print("Updating table") retention_properties = { 'MemoryStoreRetentionPeriodInHours': Constant.HT_TTL_HOURS, 'MagneticStoreRetentionPeriodInDays': Constant.CT_TTL_DAYS } try: self.client.update_table(DatabaseName=Constant.DATABASE_NAME, TableName=Constant.TABLE_NAME, RetentionProperties=retention_properties) print("Table updated.") except Exception as err: print("Update table failed:", err)
- Node.js
-
El siguiente fragmento se utiliza AWS SDK para JavaScript la versión 3. Para obtener más información sobre cómo instalar el cliente y su uso, consulte Timestream Write Client, para la versión 3. AWS SDK JavaScript
Consulte también Class y. UpdateTableCommand UpdateTable
import { TimestreamWriteClient, UpdateTableCommand } from "@aws-sdk/client-timestream-write"; const writeClient = new TimestreamWriteClient({ region: "us-east-1" }); const params = { DatabaseName: "testDbFromNode", TableName: "testTableFromNode", RetentionProperties: { MemoryStoreRetentionPeriodInHours: 24, MagneticStoreRetentionPeriodInDays: 180 } }; const command = new UpdateTableCommand(params); try { const data = await writeClient.send(command); console.log("Table updated") } catch (error) { console.log("Error updating table. ", error); }
El siguiente fragmento usa el estilo AWS SDK for JavaScript V2. Se basa en la aplicación de ejemplo de Node.js, ejemplo de Amazon Timestream LiveAnalytics
para su aplicación en. GitHub async function updateTable() { console.log("Updating Table"); const params = { DatabaseName: constants.DATABASE_NAME, TableName: constants.TABLE_NAME, RetentionProperties: { MemoryStoreRetentionPeriodInHours: constants.HT_TTL_HOURS, MagneticStoreRetentionPeriodInDays: constants.CT_TTL_DAYS } }; const promise = writeClient.updateTable(params).promise(); await promise.then( (data) => { console.log("Table updated") }, (err) => { console.log("Error updating table. ", err); throw err; } ); }
- .NET
-
public async Task UpdateTable() { Console.WriteLine("Updating Table"); try { var updateTableRequest = new UpdateTableRequest { DatabaseName = Constants.DATABASE_NAME, TableName = Constants.TABLE_NAME, RetentionProperties = new RetentionProperties { MagneticStoreRetentionPeriodInDays = Constants.CT_TTL_DAYS, MemoryStoreRetentionPeriodInHours = Constants.HT_TTL_HOURS } }; UpdateTableResponse response = await writeClient.UpdateTableAsync(updateTableRequest); Console.WriteLine($"Table {Constants.TABLE_NAME} updated"); } catch (ResourceNotFoundException) { Console.WriteLine("Table does not exist."); } catch (Exception e) { Console.WriteLine("Update table failed:" + e.ToString()); } }