As traduções são geradas por tradução automática. Em caso de conflito entre o conteúdo da tradução e da versão original em inglês, a versão em inglês prevalecerá.
Descreva a tabela
Você pode usar os trechos de código a seguir para obter informações sobre os atributos da sua tabela.
nota
Esses trechos de código são baseados em exemplos completos de aplicativos em. GitHub
- 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 := ×treamwrite.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
-
O trecho a seguir é usado AWS SDK para JavaScript a v3. Para obter mais informações sobre como instalar o cliente e o uso, consulte Timestream Write Client - AWS SDK for JavaScript v3.
Veja também Classe DescribeTableCommand DescribeTablee.
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; } }
O trecho a seguir usa o estilo AWS SDK for JavaScript V2. Ele se baseia no aplicativo de exemplo em Node.js, exemplo do Amazon Timestream LiveAnalytics
para aplicação em. 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()); } }