Appliquer un libellé
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Crée un filtre qui applique un libellé.
En savoir plus
Pour obtenir une documentation détaillée incluant cet exemple de code, consultez les pages suivantes :
Exemple de code
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis code demonstrates how to create a filter that adds a "labelled" label to cells in a Bigtable read operation.\u003c/p\u003e\n"],["\u003cp\u003eThe filter is implemented using the \u003ccode\u003eApplyLabelTransformer\u003c/code\u003e or \u003ccode\u003elabel\u003c/code\u003e methods in multiple programming languages, including C++, C#, Java, Node.js, PHP, Python, and Ruby.\u003c/p\u003e\n"],["\u003cp\u003eThe code snippets show how to apply this label filter when reading rows from a Bigtable table, allowing you to mark or identify specific data during retrieval.\u003c/p\u003e\n"],["\u003cp\u003eAuthentication to Bigtable requires setting up Application Default Credentials, as referenced by the documentation.\u003c/p\u003e\n"],["\u003cp\u003eDetailed instructions for installing and using Bigtable client libraries are available in the Bigtable client libraries documentation.\u003c/p\u003e\n"]]],[],null,["# Apply a label\n\nCreates a filter that applies a label.\n\nExplore further\n---------------\n\n\nFor detailed documentation that includes this code sample, see the following:\n\n- [Use filters](/bigtable/docs/using-filters)\n\nCode sample\n-----------\n\n### C++\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 [](cbt::Table table) {\n cbt::Filter filter = cbt::Filter::ApplyLabelTransformer(\"labelled\");\n // Read and print the rows.\n for (StatusOr\u003ccbt::Row\u003e& row :\n table.ReadRows(cbt::RowSet(cbt::RowRange::InfiniteRange()), filter)) {\n if (!row) throw std::move(row).status();\n std::cout \u003c\u003c row-\u003erow_key() \u003c\u003c \" = \";\n for (auto const& cell : row-\u003ecells()) {\n std::cout \u003c\u003c \"[\" \u003c\u003c cell.family_name() \u003c\u003c \", \"\n \u003c\u003c cell.column_qualifier() \u003c\u003c \", \" \u003c\u003c cell.value()\n \u003c\u003c \", label(\";\n for (auto const& label : cell.labels()) {\n std::cout \u003c\u003c label \u003c\u003c \",\";\n }\n std::cout \u003c\u003c \")],\";\n }\n std::cout \u003c\u003c \"\\n\";\n }\n }\n\n### C#\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 /// \u003csummary\u003e\n /// /// Read using a strip value filter 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\n public Task\u003cstring\u003e FilterModifyApplyLabel(string projectId = \"YOUR-PROJECT-ID\", string instanceId = \"YOUR-INSTANCE-ID\", string tableId = \"YOUR-TABLE-ID\")\n {\n // A filter that applies the given label to the outputted cell\n RowFilter filter = new RowFilter { ApplyLabelTransformer = \"labelled\" };\n return ReadFilter(projectId, instanceId, tableId, filter);\n }\n\n### Java\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 filterModifyApplyLabel() {\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 filterModifyApplyLabel(projectId, instanceId, tableId);\n }\n\n public static void filterModifyApplyLabel(String projectId, String instanceId, String tableId) {\n // A filter that applies the given label to the outputted cell\n Filter filter = FILTERS.label(\"labelled\");\n readFilter(projectId, instanceId, tableId, filter);\n }\n\n### Node.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 filter = {\n label: 'labelled',\n };\n readWithFilter(filter);\n\n### PHP\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 use Google\\Cloud\\Bigtable\\Filter;\n\n /**\n * Create a filter that applies a label\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 filter_modify_apply_label(\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 $filter = Filter::label('labelled');\n\n $rows = $table-\u003ereadRows([\n 'filter' =\u003e $filter\n ]);\n\n foreach ($rows as $key =\u003e $row) {\n // The \"print_row\" helper function is defined in https://cloud.google.com/bigtable/docs/samples/bigtable-reads-print\n print_row($key, $row);\n }\n }\n\n### Python\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 filter_modify_apply_label(project_id, instance_id, table_id):\n from google.cloud import https://cloud.google.com/python/docs/reference/bigtable/latest/\n from google.cloud.bigtable import row_filters\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 rows = table.read_rows(filter_=row_filters.ApplyLabelFilter(label=\"labelled\"))\n for row in rows:\n print_row(row)\n\n### Ruby\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 filter = Google::Cloud::Bigtable::RowFilter.label \"labelled\"\n read_with_filter instance_id, table_id, filter\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=bigtable)."]]