フィルタを使用した読み取り
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
フィルタを使用して、指定された列の最新の値を読み取ります。
もっと見る
このコードサンプルを含む詳細なドキュメントについては、以下をご覧ください。
コードサンプル
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。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 page demonstrates how to read the most recent value in a specific column of a Bigtable table using a filter.\u003c/p\u003e\n"],["\u003cp\u003eCode examples are provided in C++, C#, Java, Node.js, PHP, Python, and Ruby, each showing how to retrieve a single row based on a filter.\u003c/p\u003e\n"],["\u003cp\u003eThe examples showcase how to use the respective Bigtable client libraries for each language and set up Application Default Credentials for authentication.\u003c/p\u003e\n"],["\u003cp\u003eUsers can find additional code samples for Bigtable and other Google Cloud products through the Google Cloud sample browser.\u003c/p\u003e\n"]]],[],null,["Read the most recent value in a given column using a filter.\n\nExplore further\n\n\nFor detailed documentation that includes this code sample, see the following:\n\n- [C# hello world](/bigtable/docs/samples-c-sharp-hello)\n- [C++ hello world](/bigtable/docs/samples-cpp-hello)\n- [Node.js hello world](/bigtable/docs/samples-nodejs-hello)\n- [PHP hello world](/bigtable/docs/samples-php-hello)\n- [Python hello world](/bigtable/docs/samples-python-hello)\n- [Ruby hello world](/bigtable/docs/samples-ruby-hello)\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 StatusOr\u003cstd::pair\u003cbool, cbt::Row\u003e\u003e result = table.ReadRow(\"key-0\", filter);\n if (!result) throw std::move(result).status();\n if (!result-\u003efirst) {\n std::cout \u003c\u003c \"Cannot find row 'key-0' in the table: \" \u003c\u003c table.table_name()\n \u003c\u003c \"\\n\";\n return;\n }\n cbt::Cell const& cell = result-\u003esecond.cells().front();\n std::cout \u003c\u003c cell.family_name() \u003c\u003c \":\" \u003c\u003c cell.column_qualifier() \u003c\u003c \" @ \"\n \u003c\u003c cell.timestamp().count() \u003c\u003c \"us\\n\"\n \u003c\u003c '\"' \u003c\u003c cell.value() \u003c\u003c '\"' \u003c\u003c \"\\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 // Read from the table.\n Console.WriteLine(\"Read the first row\");\n\n int rowIndex = 0;\n\n // Read a specific row. Apply a filter to return latest only cell value accross entire row.\n Row rowRead = bigtableClient.ReadRow(\n tableName, rowKey: rowKeyPrefix + rowIndex, filter: filter);\n Console.WriteLine(\n $\"\\tRow key: {rowRead.Key.ToStringUtf8()} \" +\n $\" -- Value: {rowRead.Families[0].Columns[0].Cells[0].Value.ToStringUtf8(),-16} \" +\n $\" -- Time Stamp: {rowRead.Families[0].Columns[0].Cells[0].TimestampMicros}\");\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 private void readRowFilter(String tableId, Filter filter) {\n String rowKey =\n Base64.getEncoder().encodeToString(\"greeting0\".getBytes(StandardCharsets.UTF_8));\n Row row = dataClient.readRow(TableId.of(tableId), rowKey, filter);\n printRow(row);\n System.out.println(\"Row filter completed.\");\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 console.log('Reading a single row by row key');\n const [singleRow] = await table.row('greeting0').get({filter});\n console.log(`\\tRead: ${getRowGreeting(singleRow)}`);\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 printf('Getting a single greeting by row key.' . PHP_EOL);\n $key = 'greeting0';\n // Only retrieve the most recent version of the cell.\n $rowFilter = (new RowFilter())-\u003esetCellsPerColumnLimitFilter(1);\n\n $column = 'greeting';\n $columnFamilyId = 'cf1';\n\n $row = $table-\u003ereadRow($key, [\n 'filter' =\u003e $rowFilter\n ]);\n printf('%s' . PHP_EOL, $row[$columnFamilyId][$column][0]['value']);\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 print(\"Getting a single greeting by row key.\")\n key = \"greeting0\".encode()\n\n row = table.read_row(key, row_filter)\n cell = row.cells[column_family_id][column][0]\n print(cell.value.decode(\"utf-8\"))\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 puts \"Reading a single row by row key\"\n row = table.read_row \"greeting0\", filter: filter\n puts \"Row key: #{row.key}, Value: #{row.cells[column_family].first.value}\"\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)."]]