Ler usando um filtro de intervalo de carimbo de data/hora
Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Cria um filtro limitante em um intervalo de carimbos de data/hora de células.
Mais informações
Para ver a documentação detalhada que inclui este exemplo de código, consulte:
Exemplo de código
Exceto em caso de indicação contrária, o conteúdo desta página é licenciado de acordo com a Licença de atribuição 4.0 do Creative Commons, e as amostras de código são licenciadas de acordo com a Licença Apache 2.0. Para mais detalhes, consulte as políticas do site do Google Developers. Java é uma marca registrada da Oracle e/ou afiliadas.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis code demonstrates how to apply a timestamp range filter to limit the range of cell timestamps when reading data from a Bigtable table.\u003c/p\u003e\n"],["\u003cp\u003eThe filter can be configured to include cells within a specific time frame, like between 1 millisecond and 2 milliseconds, or until an hour ago or earlier.\u003c/p\u003e\n"],["\u003cp\u003eMultiple language implementations, including C++, C#, Go, Java, Node.js, PHP, Python, and Ruby, showcase the consistent method of setting a timestamp range filter using their respective Bigtable client libraries.\u003c/p\u003e\n"],["\u003cp\u003eThe various code examples also provide different ways of defining the start and end parameters, allowing for flexibility when setting up the timestamp range.\u003c/p\u003e\n"],["\u003cp\u003eYou can learn more about filters and other examples through the documentation linked, such as the \u003ca href=\"/bigtable/docs/using-filters\"\u003eUse filters\u003c/a\u003e.\u003c/p\u003e\n"]]],[],null,["Creates a limiting filter on a range of cell timestamps.\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 cbt::Filter filter =\n cbt::Filter::TimestampRange(microseconds(1000), milliseconds(2));\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() \u003c\u003c \"],\";\n }\n std::cout \u003c\u003c \"\\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 timestamp range 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 FilterLimitTimestampRange(string projectId, string instanceId, string tableId)\n {\n BigtableVersion timestamp_minus_hr = new BigtableVersion(new DateTime(2020, 1, 10, 13, 0, 0, DateTimeKind.Utc));\n\n // A filter that matches cells whose timestamp is from an hour ago or earlier\n RowFilter filter = RowFilters.TimestampRange(new DateTime(0), timestamp_minus_hr.ToDateTime());\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 filterLimitTimestampRange(w io.Writer, projectID, instanceID string, tableName string) error {\n \tstartTime := time.Unix(0, 0)\n \tendTime := time.Now().Add(-1 * time.Hour)\n \tfilter := bigtable.TimestampRangeFilter(startTime, endTime)\n\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 filterLimitTimestampRange() {\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 filterLimitTimestampRange(projectId, instanceId, tableId);\n }\n\n public static void filterLimitTimestampRange(\n String projectId, String instanceId, String tableId) {\n // Get a time representing one hour ago\n long timestamp = Instant.now().minus(1, ChronoUnit.HOURS).toEpochMilli() * 1000;\n\n // A filter that matches cells whose timestamp is from an hour ago or earlier\n Filter filter = FILTERS.timestamp().range().startClosed(0L).endOpen(timestamp);\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 start = 0;\n const end = new Date(2019, 5, 1);\n end.setUTCHours(0);\n const filter = {\n time: {\n start,\n end,\n },\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 range of cell timestamps\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 * @param int $endTime The timestamp upto which you want to fetch the rows\n */\n function filter_limit_timestamp_range(\n string $projectId,\n string $instanceId,\n string $tableId,\n int $endTime = null\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 $endTime = is_null($endTime) ? (time() - 60 * 60) * 1000 * 1000 : $endTime;\n\n $start = 0;\n $filter = Filter::timestamp()\n -\u003erange()\n -\u003estartClosed($start)\n -\u003eendOpen($endTime);\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\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_timestamp_range(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 import datetime\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 end = datetime.datetime(2019, 5, 1)\n\n rows = table.read_rows(\n filter_=row_filters.TimestampRangeFilter(row_filters.TimestampRange(end=end))\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 timestamp_minus_hr = (Time.now.to_f * 1_000_000).round(-3) - (60 * 60 * 1000 * 1000)\n puts timestamp_minus_hr\n filter = Google::Cloud::Bigtable::RowFilter.timestamp_range from: 0, to: timestamp_minus_hr\n\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)."]]