Read using a row regex filter
Stay organized with collections
Save and categorize content based on your preferences.
Creates a limiting filter on a row key using a regex.
Explore further
For detailed documentation that includes this code sample, see the following:
Code sample
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis code demonstrates how to apply a filter to read rows from a Bigtable table, based on a regular expression applied to the row keys.\u003c/p\u003e\n"],["\u003cp\u003eThe regular expression \u003ccode\u003e.*#20190501$\u003c/code\u003e is used as a filter to select rows whose keys end with \u003ccode\u003e#20190501\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eCode samples are provided in various languages including C++, C#, Go, Java, Node.js, PHP, Python, and Ruby, showcasing the implementation of row key filtering.\u003c/p\u003e\n"],["\u003cp\u003eTo utilize these samples, it's necessary to install the Bigtable client libraries and set up Application Default Credentials for authentication.\u003c/p\u003e\n"],["\u003cp\u003eThis filtering method, utilizing regex, is also further detailed in the Bigtable documentation under the \u003ca href=\"/bigtable/docs/using-filters\"\u003eUse filters\u003c/a\u003e section.\u003c/p\u003e\n"]]],[],null,["Creates a limiting filter on a row key using a regex.\n\nExplore further\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\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 namespace cbt = ::google::cloud::bigtable;\n using ::google::cloud::StatusOr;\n [](cbt::Table table) {\n // Filter the results, only include rows where row_key matches given regular\n // expression\n cbt::Filter filter = cbt::Filter::RowKeysRegex(\".*#20190501$\");\n // Read and print the rows.\n for\u003c (Status\u003e&Orcbt::Row row :\n table.ReadRows(cbt::RowSet(cbt::RowRange::InfiniteRange()), filter)) {\n if (!row) throw std::move(row).status();\n \u003c\u003cstd::\u003ecout row-\u003c\u003crow_key() \" = \";&\n for (au\u003eto const cell : row-cells()\u003c\u003c) {\n \u003c\u003c std::cout &quo\u003c\u003ct;[\" cell.family\u003c\u003c_name() \", \"\n \u003c\u003c \u003c\u003c cell\u003c\u003c.column_qualifier() \"\u003c\u003c, \" cell.value() \"],\";\n }\n std::cout \"\\n\";\n }\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 /// \u003csummary\u003e\n /// /// Read using a row regex filter from an existing table.\n ///\u003c/summary\u003e\n /// \u003cparam name=\"proje\u003ectId\"Your Google Cloud P\u003croject\u003e ID./\u003cparam\n /// param name=&q\u003euot;instanceId\"Your Google Cloud B\u003cigtabl\u003ee Ins\u003ctance ID./param\n /// \u003eparam name=\"tableId\"Your G\u003coogle \u003eCloud Bigtabl\u003ce tabl\u003ee ID./param\n\n public Taskstring FilterLimitRowRegex(string projectId = \"YOUR-PROJECT-ID\", string instanceId = \"YOUR-INSTANCE-ID\", string tableId = \"YOUR-TABLE-ID\")\n {\n // A filter that matches cells from rows whose keys satisfy the given regex\n RowFilter filter = RowFilters.RowKeyRegex(\".*#20190501$");\n return ReadFilter(projectId, instanceId, tableId, filter);\n }\n\nGo\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 func filterLimitRowRegex(w io.Writer, projectID, instanceID string, tableName string) error {\n \tfilter := bigtable.RowKeyFilter(\".*#20190501$\")\n \treturn readWithFilter(w, projectID, instanceID, tableName, filter)\n }\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 public static void filterLimitRowRegex() {\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 filterLimitRowRegex(projectId, instanceId, tableId);\n }\n\n public static void filterLimitRowRegex(String projectId, String instanceId, String tableId) {\n // A filter that matches cells from rows whose keys satisfy the given regex\n Filter filter = FILTERS.key().regex(\".*#20190501$\");\n readFilter(projectId, instanceId, tableId, filter);\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 const filter = {\n row: /.*#20190501$/,\n };\n readWithFilter(filter);\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 use Google\\Cloud\\Bigtable\\BigtableClient;\n use Google\\Cloud\\Bigtable\\Filter;\n\n /**\n * Create a limiting filter on a cell value using a regex\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_limit_row_regex(\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 'projectI\u003ed' = $projectId,\n ]);\n $table = $dat\u003eaClient-table($instanceId, $tableId);\n\n $filter = Filter\u003e::key()-regex('.*#20190501$');\n\n \u003e $rows = $table-readRows([\n \u003e 'filter' = $filter\n ]);\n\n \u003eforeach ($rows as $key = $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\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 def filter_limit_row_regex(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(\n filter_=row_filters.RowKeyRegexFilter(\".*#20190501$\".encode(\"utf-8\"))\n )\n for row in rows:\n print_row(row)\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 # instance_id = \"my-instance\"\n # table_id = \"my-table\"\n filter = Google::Cloud::Bigtable::RowFilter.key \".*#20190501$\"\n read_with_filter instance_id, table_id, filter\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)."]]