读取行
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
读取行。
深入探索
如需查看包含此代码示例的详细文档,请参阅以下内容:
代码示例
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis content provides code samples demonstrating how to read a single row from a Google Cloud Bigtable table using various programming languages.\u003c/p\u003e\n"],["\u003cp\u003eEach code sample requires the setup of Application Default Credentials for authentication to Bigtable and provides the relevant parameters to connect to the table.\u003c/p\u003e\n"],["\u003cp\u003eThe examples are given in C++, C#, Go, Java, Node.js, PHP, Python, and Ruby, and each of them utilizes the client library for Bigtable that must be set up.\u003c/p\u003e\n"],["\u003cp\u003eAll code samples read a row from the table by specifying a \u003ccode\u003erowkey\u003c/code\u003e which is \u003ccode\u003ephone#4c410523#20190501\u003c/code\u003e and use a function to print the data of that row.\u003c/p\u003e\n"],["\u003cp\u003eFurther samples for other Google Cloud products and more information can be explored using the Google Cloud sample browser.\u003c/p\u003e\n"]]],[],null,["Read a row.\n\nExplore further\n\n\nFor detailed documentation that includes this code sample, see the following:\n\n- [Read examples](/bigtable/docs/reading-data)\n\nCode sample \n\nC++\n\n\nTo learn how to install and use the client library for Bigtable, see\n[Bigtable client libraries](/bigtable/docs/reference/libraries).\n\n\nTo authenticate to Bigtable, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n namespace cbt = ::google::cloud::bigtable;\n using ::google::cloud::StatusOr;\n [](google::cloud::bigtable::Table table, std::string const& row_key) {\n StatusOr\u003cstd::pair\u003cbool, cbt::Row\u003e\u003e tuple =\n table.ReadRow(row_key, cbt::Filter::PassAllFilter());\n if (!tuple) throw std::move(tuple).status();\n if (!tuple-\u003efirst) {\n std::cout \u003c\u003c \"Row \" \u003c\u003c row_key \u003c\u003c \" not found\\n\";\n return;\n }\n PrintRow(tuple-\u003esecond);\n }\n\nC#\n\n\nTo learn how to install and use the client library for Bigtable, see\n[Bigtable client libraries](/bigtable/docs/reference/libraries).\n\n\nTo authenticate to Bigtable, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n\n /// \u003csummary\u003e\n /// /// Reads one row from an existing table.\n ///\u003c/summary\u003e\n /// \u003cparam name=\"projectId\"\u003eYour Google Cloud Project ID.\u003c/param\u003e\n /// \u003cparam name=\"instanceId\"\u003eYour Google Cloud Bigtable Instance ID.\u003c/param\u003e\n /// \u003cparam name=\"tableId\"\u003eYour Google Cloud Bigtable table ID.\u003c/param\u003e\n public string ReadRow(\n string projectId = \"YOUR-PROJECT-ID\", string instanceId = \"YOUR-INSTANCE-ID\", string tableId = \"YOUR-TABLE-ID\")\n {\n BigtableClient bigtableClient = BigtableClient.Create();\n TableName tableName = new TableName(projectId, instanceId, tableId);\n Row row = bigtableClient.ReadRow(tableName, rowKey: \"phone#4c410523#20190501\");\n\n return PrintRow(row);\n }\n\nGo\n\n\nTo learn how to install and use the client library for Bigtable, see\n[Bigtable client libraries](/bigtable/docs/reference/libraries).\n\n\nTo authenticate to Bigtable, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n func readRow(w io.Writer, projectID, instanceID string, tableName string) error {\n \t// projectID := \"my-project-id\"\n \t// instanceID := \"my-instance-id\"\n \t// tableName := \"mobile-time-series\"\n\n \tctx := context.Background()\n \tclient, err := bigtable.NewClient(ctx, projectID, instanceID)\n \tif err != nil {\n \t\treturn fmt.Errorf(\"bigtable.NewClient: %w\", err)\n \t}\n \tdefer client.Close()\n\n \ttbl := client.Open(tableName)\n \trowKey := \"phone#4c410523#20190501\"\n \trow, err := tbl.ReadRow(ctx, rowKey)\n \tif err != nil {\n \t\treturn fmt.Errorf(\"could not read row with key %s: %w\", rowKey, err)\n \t}\n\n \tprintRow(w, row)\n \treturn nil\n }\n\nJava\n\n\nTo learn how to install and use the client library for Bigtable, see\n[Bigtable client libraries](/bigtable/docs/reference/libraries).\n\n\nTo authenticate to Bigtable, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n public static void readRow() {\n // TODO(developer): Replace these variables before running the sample.\n String projectId = \"my-project-id\";\n String instanceId = \"my-instance-id\";\n String tableId = \"mobile-time-series\";\n readRow(projectId, instanceId, tableId);\n }\n\n public static void readRow(String projectId, String instanceId, String tableId) {\n // Initialize client that will be used to send requests. This client only needs to be created\n // once, and can be reused for multiple requests. After completing all of your requests, call\n // the \"close\" method on the client to safely clean up any remaining background resources.\n try (BigtableDataClient dataClient = BigtableDataClient.create(projectId, instanceId)) {\n String rowkey = \"phone#4c410523#20190501\";\n\n Row row = dataClient.readRow(TableId.of(tableId), rowkey);\n printRow(row);\n\n } catch (IOException e) {\n System.out.println(\n \"Unable to initialize service client, as a network error occurred: \\n\" + e.toString());\n }\n }\n\nNode.js\n\n\nTo learn how to install and use the client library for Bigtable, see\n[Bigtable client libraries](/bigtable/docs/reference/libraries).\n\n\nTo authenticate to Bigtable, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n const rowkey = 'phone#4c410523#20190501';\n\n const [row] = await table.row(rowkey).get();\n printRow(rowkey, row.data);\n\nPHP\n\n\nTo learn how to install and use the client library for Bigtable, see\n[Bigtable client libraries](/bigtable/docs/reference/libraries).\n\n\nTo authenticate to Bigtable, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n use Google\\Cloud\\Bigtable\\BigtableClient;\n\n /**\n * Read a row using the row key\n *\n * @param string $projectId The Google Cloud project ID\n * @param string $instanceId The ID of the Bigtable instance\n * @param string $tableId The ID of the table to read from\n */\n function read_row(\n string $projectId,\n string $instanceId,\n string $tableId\n ): void {\n // Connect to an existing table with an existing instance.\n $dataClient = new BigtableClient([\n 'projectId' =\u003e $projectId,\n ]);\n $table = $dataClient-\u003etable($instanceId, $tableId);\n\n $rowkey = 'phone#4c410523#20190501';\n $row = $table-\u003ereadRow($rowkey);\n\n print_row($rowkey, $row);\n }\n\nPython\n\n\nTo learn how to install and use the client library for Bigtable, see\n[Bigtable client libraries](/bigtable/docs/reference/libraries).\n\n\nTo authenticate to Bigtable, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n def read_row(project_id, instance_id, table_id):\n from google.cloud import https://cloud.google.com/python/docs/reference/bigtable/latest/\n\n client = https://cloud.google.com/python/docs/reference/bigtable/latest/.https://cloud.google.com/python/docs/reference/bigtable/latest/google.cloud.bigtable.client.Client.html(project=project_id, admin=True)\n instance = https://cloud.google.com/python/docs/reference/bigtable/latest/google.cloud.bigtable.client.html.https://cloud.google.com/python/docs/reference/bigtable/latest/google.cloud.bigtable.client.Client.html#google_cloud_bigtable_client_Client_instance(instance_id)\n table = instance.table(table_id)\n\n row_key = \"phone#4c410523#20190501\"\n\n row = table.read_row(row_key)\n print_row(row)\n\nRuby\n\n\nTo learn how to install and use the client library for Bigtable, see\n[Bigtable client libraries](/bigtable/docs/reference/libraries).\n\n\nTo authenticate to Bigtable, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n # instance_id = \"my-instance\"\n # table_id = \"my-table\"\n bigtable = Google::Cloud::https://cloud.google.com/ruby/docs/reference/google-cloud-bigtable-admin-v2/latest/Google-Cloud-Bigtable.html.https://cloud.google.com/ruby/docs/reference/google-cloud-bigtable/latest/Google-Cloud-Bigtable.html\n table = bigtable.table instance_id, table_id\n\n row = table.https://cloud.google.com/ruby/docs/reference/google-cloud-bigtable/latest/Google-Cloud-Bigtable-ReadOperations.html \"phone#4c410523#20190501\"\n print_row row\n end\n\nWhat's next\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=bigtable)."]]