Décrire le tableau - Amazon Timestream

Les traductions sont fournies par des outils de traduction automatique. En cas de conflit entre le contenu d'une traduction et celui de la version originale en anglais, la version anglaise prévaudra.

Décrire le tableau

Vous pouvez utiliser les extraits de code suivants pour obtenir des informations sur les attributs de votre table.

Note

Ces extraits de code sont basés sur des exemples complets d'applications sur. GitHub Pour plus d'informations sur la façon de démarrer avec les exemples d'applications, consultezExemple d'application.

Java
public void describeTable() { System.out.println("Describing table"); final DescribeTableRequest describeTableRequest = new DescribeTableRequest(); describeTableRequest.setDatabaseName(DATABASE_NAME); describeTableRequest.setTableName(TABLE_NAME); try { DescribeTableResult result = amazonTimestreamWrite.describeTable(describeTableRequest); String tableId = result.getTable().getArn(); System.out.println("Table " + TABLE_NAME + " has id " + tableId); } catch (final Exception e) { System.out.println("Table " + TABLE_NAME + " doesn't exist = " + e); throw e; } }
Java v2
public void describeTable() { System.out.println("Describing table"); final DescribeTableRequest describeTableRequest = DescribeTableRequest.builder() .databaseName(DATABASE_NAME).tableName(TABLE_NAME).build(); try { DescribeTableResponse response = timestreamWriteClient.describeTable(describeTableRequest); String tableId = response.table().arn(); System.out.println("Table " + TABLE_NAME + " has id " + tableId); } catch (final Exception e) { System.out.println("Table " + TABLE_NAME + " doesn't exist = " + e); throw e; } }
Go
// Describe table. describeTableInput := &timestreamwrite.DescribeTableInput{ DatabaseName: aws.String(*databaseName), TableName: aws.String(*tableName), } describeTableOutput, err := writeSvc.DescribeTable(describeTableInput) if err != nil { fmt.Println("Error:") fmt.Println(err) } else { fmt.Println("Describe table is successful, below is the output:") fmt.Println(describeTableOutput) }
Python
def describe_table(self): print("Describing table") try: result = self.client.describe_table(DatabaseName=Constant.DATABASE_NAME, TableName=Constant.TABLE_NAME) print("Table [%s] has id [%s]" % (Constant.TABLE_NAME, result['Table']['Arn'])) except self.client.exceptions.ResourceNotFoundException: print("Table doesn't exist") except Exception as err: print("Describe table failed:", err)
Node.js

L'extrait de code suivant est utilisé AWS SDK pour JavaScript la version 3. Pour plus d'informations sur l'installation du client et son utilisation, consultez Timestream Write Client - AWS SDK for JavaScript v3.

Voir également Classe DescribeTableCommand et DescribeTable.

import { TimestreamWriteClient, DescribeTableCommand } from "@aws-sdk/client-timestream-write"; const writeClient = new TimestreamWriteClient({ region: "us-east-1" }); const params = { DatabaseName: "testDbFromNode", TableName: "testTableFromNode" }; const command = new DescribeTableCommand(params); try { const data = await writeClient.send(command); console.log(`Table ${data.Table.TableName} has id ${data.Table.Arn}`); } catch (error) { if (error.code === 'ResourceNotFoundException') { console.log("Table or Database doesn't exist."); } else { console.log("Describe table failed.", error); throw error; } }

L'extrait suivant utilise le style AWS SDK for JavaScript V2. Il est basé sur l'exemple d'application disponible sur Node.js, un exemple d'Amazon Timestream LiveAnalytics pour une application sur. GitHub

async function describeTable() { console.log("Describing Table"); const params = { DatabaseName: constants.DATABASE_NAME, TableName: constants.TABLE_NAME }; const promise = writeClient.describeTable(params).promise(); await promise.then( (data) => { console.log(`Table ${data.Table.TableName} has id ${data.Table.Arn}`); }, (err) => { if (err.code === 'ResourceNotFoundException') { console.log("Table or Database doesn't exists."); } else { console.log("Describe table failed.", err); throw err; } } ); }
.NET
public async Task DescribeTable() { Console.WriteLine("Describing Table"); try { var describeTableRequest = new DescribeTableRequest { DatabaseName = Constants.DATABASE_NAME, TableName = Constants.TABLE_NAME }; DescribeTableResponse response = await writeClient.DescribeTableAsync(describeTableRequest); Console.WriteLine($"Table {Constants.TABLE_NAME} has id:{response.Table.Arn}"); } catch (ResourceNotFoundException) { Console.WriteLine("Table does not exist."); } catch (Exception e) { Console.WriteLine("Describe table failed:" + e.ToString()); } }