使用篩選器讀取資料
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
使用篩選器讀取指定資料欄的最新值。
深入探索
如需包含這個程式碼範例的詳細說明文件,請參閱下列內容:
程式碼範例
C++
如要瞭解如何安裝及使用 Bigtable 的用戶端程式庫,請參閱這篇文章。
如要向 Bigtable 進行驗證,請設定應用程式預設憑證。
詳情請參閱「為本機開發環境設定驗證」。
C#
如要瞭解如何安裝及使用 Bigtable 的用戶端程式庫,請參閱這篇文章。
如要向 Bigtable 進行驗證,請設定應用程式預設憑證。
詳情請參閱「為本機開發環境設定驗證」。
Java
如要瞭解如何安裝及使用 Bigtable 的用戶端程式庫,請參閱這篇文章。
如要向 Bigtable 進行驗證,請設定應用程式預設憑證。
詳情請參閱「為本機開發環境設定驗證」。
Node.js
如要瞭解如何安裝及使用 Bigtable 的用戶端程式庫,請參閱這篇文章。
如要向 Bigtable 進行驗證,請設定應用程式預設憑證。
詳情請參閱「為本機開發環境設定驗證」。
PHP
如要瞭解如何安裝及使用 Bigtable 的用戶端程式庫,請參閱這篇文章。
如要向 Bigtable 進行驗證,請設定應用程式預設憑證。
詳情請參閱「為本機開發環境設定驗證」。
Python
如要瞭解如何安裝及使用 Bigtable 的用戶端程式庫,請參閱這篇文章。
如要向 Bigtable 進行驗證,請設定應用程式預設憑證。
詳情請參閱「為本機開發環境設定驗證」。
Ruby
如要瞭解如何安裝及使用 Bigtable 的用戶端程式庫,請參閱這篇文章。
如要向 Bigtable 進行驗證,請設定應用程式預設憑證。
詳情請參閱「為本機開發環境設定驗證」。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 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)."]]