Lee con un filtro
Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
Lee el valor más reciente en una columna determinada con un filtro.
Explora más
Para obtener documentación en la que se incluye esta muestra de código, consulta lo siguiente:
Muestra de código
Salvo que se indique lo contrario, el contenido de esta página está sujeto a la licencia Atribución 4.0 de Creative Commons, y los ejemplos de código están sujetos a la licencia Apache 2.0. Para obtener más información, consulta las políticas del sitio de Google Developers. Java es una marca registrada de Oracle o sus afiliados.
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","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)."]]