使用篩選器讀取資料
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
使用篩選器讀取資料列。
深入探索
如需包含這個程式碼範例的詳細說明文件,請參閱下列內容:
程式碼範例
C++
如要瞭解如何安裝及使用 Bigtable 的用戶端程式庫,請參閱這篇文章。
如要向 Bigtable 進行驗證,請設定應用程式預設憑證。
詳情請參閱「為本機開發環境設定驗證」。
C#
如要瞭解如何安裝及使用 Bigtable 的用戶端程式庫,請參閱這篇文章。
如要向 Bigtable 進行驗證,請設定應用程式預設憑證。
詳情請參閱「為本機開發環境設定驗證」。
Go
如要瞭解如何安裝及使用 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 content demonstrates how to read rows from a Bigtable table using a filter across various programming languages.\u003c/p\u003e\n"],["\u003cp\u003eThe code samples utilize a value regex filter, specifically \u003ccode\u003ePQ2A.*\u003c/code\u003e, to select rows based on the values they contain.\u003c/p\u003e\n"],["\u003cp\u003eEach language's example showcases how to set up authentication and install the client libraries necessary for interacting with Bigtable.\u003c/p\u003e\n"],["\u003cp\u003eThe code examples provide snippets on how to connect to a table and perform filtered read operations.\u003c/p\u003e\n"],["\u003cp\u003eEach language implementation shows how to iterate over the filtered results and print each individual row that matches the criteria.\u003c/p\u003e\n"]]],[],null,["Read a row with a filter.\n\nExplore further\n\n\nFor detailed documentation that includes this code sample, see the following:\n\n- [Read examples](/bigtable/docs/reading-data)\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 // Read and print the rows.\n for (StatusOr\u003ccbt::Row\u003e& row :\n table.ReadRows(cbt::RowRange::InfiniteRange(),\n cbt::Filter::ValueRegex(\"PQ2A.*\"))) {\n if (!row) throw std::move(row).status();\n PrintRow(*row);\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\n /// \u003csummary\u003e\n /// /// Reads using a 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 async Task\u003cstring\u003e ReadFilter(string projectId = \"YOUR-PROJECT-ID\", string instanceId = \"YOUR-INSTANCE-ID\", string tableId = \"YOUR-TABLE-ID\")\n {\n BigtableClient bigtableClient = BigtableClient.Create();\n TableName tableName = new TableName(projectId, instanceId, tableId);\n\n RowFilter filter = RowFilters.ValueRegex(\"PQ2A.*\");\n\n ReadRowsStream readRowsStream = bigtableClient.ReadRows(tableName, filter: filter);\n string result = \"\";\n await foreach (var row in readRowsStream)\n {\n result += PrintRow(row);\n }\n\n return result;\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 readFilter(w io.Writer, projectID, instanceID string, tableName string) error {\n \t// projectID := \"my-project-id\"\n \t// instanceID := \"my-instance-id\"\n \t// tableName := \"mobile-time-series\"\n\n \tctx := context.Background()\n \tclient, err := bigtable.NewClient(ctx, projectID, instanceID)\n \tif err != nil {\n \t\treturn fmt.Errorf(\"bigtable.NewClient: %w\", err)\n \t}\n \tdefer client.Close()\n\n \ttbl := client.Open(tableName)\n \terr = tbl.ReadRows(ctx, bigtable.RowRange{},\n \t\tfunc(row bigtable.Row) bool {\n \t\t\tprintRow(w, row)\n \t\t\treturn true\n \t\t},\n \t\tbigtable.RowFilter(bigtable.ValueFilter(\"PQ2A.*$\")),\n \t)\n \tif err != nil {\n \t\treturn fmt.Errorf(\"tbl.ReadRows: %w\", err)\n \t}\n\n \treturn nil\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 readFilter() {\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 readFilter(projectId, instanceId, tableId);\n }\n\n public static void readFilter(String projectId, String instanceId, String tableId) {\n Filters.Filter filter = FILTERS.value().regex(\"PQ2A.*\");\n\n // Initialize client that will be used to send requests. This client only needs to be created\n // once, and can be reused for multiple requests. After completing all of your requests, call\n // the \"close\" method on the client to safely clean up any remaining background resources.\n try (BigtableDataClient dataClient = BigtableDataClient.create(projectId, instanceId)) {\n Query query = Query.create(TableId.of(tableId)).filter(filter);\n ServerStream\u003cRow\u003e rows = dataClient.readRows(query);\n for (Row row : rows) {\n printRow(row);\n }\n } catch (IOException e) {\n System.out.println(\n \"Unable to initialize service client, as a network error occurred: \\n\" + e.toString());\n }\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 value: /PQ2A.*$/,\n };\n\n await table\n .createReadStream({\n filter,\n })\n .on('error', err =\u003e {\n // Handle the error.\n console.log(err);\n })\n .on('data', row =\u003e printRow(row.id, row.data))\n .on('end', () =\u003e {\n // All rows retrieved.\n });\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 * Read using a filter\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 read_filter(\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 $rowFilter = Filter::value()-\u003eregex('PQ2A.*$');\n\n $rows = $table-\u003ereadRows([\n 'filter' =\u003e $rowFilter\n ]);\n\n foreach ($rows as $key =\u003e $row) {\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 read_filter(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.ValueRegexFilter(b\"PQ2A.*$\"))\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 bigtable = Google::Cloud::https://cloud.google.com/ruby/docs/reference/google-cloud-bigtable-admin-v2/latest/Google-Cloud-Bigtable.html.https://cloud.google.com/ruby/docs/reference/google-cloud-bigtable/latest/Google-Cloud-Bigtable.html\n table = bigtable.table instance_id, table_id\n\n filter = Google::Cloud::https://cloud.google.com/ruby/docs/reference/google-cloud-bigtable-admin-v2/latest/Google-Cloud-Bigtable.html::https://cloud.google.com/ruby/docs/reference/google-cloud-bigtable/latest/Google-Cloud-Bigtable-RowFilter.html.value \"PQ2A.*$\"\n table.read_rows(filter: filter).https://cloud.google.com/ruby/docs/reference/google-cloud-bigtable/latest/Google-Cloud-Bigtable-ColumnFamilyMap.html do |row|\n print_row row\n end\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)."]]