Mit einem Filter lesen
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Lesen Sie mithilfe eines Filters den neuesten Wert in einer bestimmten Spalte.
Weitere Informationen
Eine ausführliche Dokumentation, die dieses Codebeispiel enthält, finden Sie hier:
Codebeispiel
Nächste Schritte
Wenn Sie nach Codebeispielen für andere Google Cloud -Produkte suchen und filtern möchten, können Sie den Google Cloud -Beispielbrowser verwenden.
Sofern nicht anders angegeben, sind die Inhalte dieser Seite unter der Creative Commons Attribution 4.0 License und Codebeispiele unter der Apache 2.0 License lizenziert. Weitere Informationen finden Sie in den Websiterichtlinien von Google Developers. Java ist eine eingetragene Marke von Oracle und/oder seinen Partnern.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","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)."]]