描述表 - Amazon Timestream

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

描述表

您可以使用以下代码片段来获取有关表属性的信息。

注意

这些代码片段基于上的完整示例应用程序。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 := &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

以下代码段用 AWS SDK于 JavaScript v3。有关如何安装客户端和用法的更多信息,请参阅 Timestream Write Client-f AWS SDK or JavaScript v3

另请参阅类 DescribeTableCommandDescribeTable

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; } }

以下代码段使用 for JavaScript V2 样式。 AWS SDK它基于 Node.js 示例 Amazon Timestream 中的示例 LiveAnalytics 应用程序,供其上使用。 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()); } }