Ler usando um filtro de amostra de linha

Cria um filtro limitante em linhas usando uma amostragem aleatória.

Páginas de documentação que incluem esta amostra de código

Para visualizar o exemplo de código usado em contexto, consulte a seguinte documentação:

Amostra de código

C#

Para saber como instalar e usar a biblioteca de cliente do Bigtable, consulte Bibliotecas de cliente do Bigtable.

/// <summary>
/// /// Read using a row sample filter from an existing table.
///</summary>
/// <param name="projectId">Your Google Cloud Project ID.</param>
/// <param name="instanceId">Your Google Cloud Bigtable Instance ID.</param>
/// <param name="tableId">Your Google Cloud Bigtable table ID.</param>

public string filterLimitRowSample(string projectId = "YOUR-PROJECT-ID", string instanceId = "YOUR-INSTANCE-ID", string tableId = "YOUR-TABLE-ID")
{
    // A filter that matches cells from a row with probability .75
    RowFilter filter = RowFilters.RowSample(.75);
    return readFilter(projectId, instanceId, tableId, filter);
}

C++

Para saber como instalar e usar a biblioteca de cliente do Bigtable, consulte Bibliotecas de cliente do Bigtable.

namespace cbt = ::google::cloud::bigtable;
using ::google::cloud::StatusOr;
[](cbt::Table table) {
  // Filter the results, only include rows with a given probability
  cbt::Filter filter = cbt::Filter::RowSample(0.75);

  // Read and print the rows.
  for (StatusOr<cbt::Row> const& row :
       table.ReadRows(cbt::RowSet(cbt::RowRange::InfiniteRange()), filter)) {
    if (!row) throw std::runtime_error(row.status().message());
    std::cout << row->row_key() << " = ";
    for (auto const& cell : row->cells()) {
      std::cout << "[" << cell.family_name() << ", "
                << cell.column_qualifier() << ", " << cell.value() << "],";
    }
    std::cout << "\n";
  }
}

Go

Para saber como instalar e usar a biblioteca de cliente do Bigtable, consulte Bibliotecas de cliente do Bigtable.

func filterLimitRowSample(w io.Writer, projectID, instanceID string, tableName string) error {
	filter := bigtable.RowSampleFilter(.75)
	return readWithFilter(w, projectID, instanceID, tableName, filter)
}

Java

Para saber como instalar e usar a biblioteca de cliente do Bigtable, consulte Bibliotecas de cliente do Bigtable.

public static void filterLimitRowSample() {
  // TODO(developer): Replace these variables before running the sample.
  String projectId = "my-project-id";
  String instanceId = "my-instance-id";
  String tableId = "mobile-time-series";
  filterLimitRowSample(projectId, instanceId, tableId);
}

public static void filterLimitRowSample(String projectId, String instanceId, String tableId) {
  // A filter that matches cells from a row with probability .75
  Filter filter = FILTERS.key().sample(.75);
  readFilter(projectId, instanceId, tableId, filter);
}

Node.js

Para saber como instalar e usar a biblioteca de cliente do Bigtable, consulte Bibliotecas de cliente do Bigtable.

const filter = {
  row: {
    sample: 0.75,
  },
};
readWithFilter(filter);

PHP

Para saber como instalar e usar a biblioteca de cliente do Bigtable, consulte Bibliotecas de cliente do Bigtable.

use Google\Cloud\Bigtable\BigtableClient;
use Google\Cloud\Bigtable\Filter;

/**
 * Create a limiting filter on rows using a random sampling
 *
 * @param string $projectId The Google Cloud project ID
 * @param string $instanceId The ID of the Bigtable instance
 * @param string $tableId The ID of the table to read from
 */
function filter_limit_row_sample(
    string $projectId,
    string $instanceId,
    string $tableId
): void {
    // Connect to an existing table with an existing instance.
    $dataClient = new BigtableClient([
        'projectId' => $projectId,
    ]);
    $table = $dataClient->table($instanceId, $tableId);

    $filter = Filter::key()->sample(.75);

    $rows = $table->readRows([
        'filter' => $filter
    ]);

    foreach ($rows as $key => $row) {
        // The "print_row" helper function is defined in https://cloud.google.com/bigtable/docs/samples/bigtable-reads-print
        print_row($key, $row);
    }
}

Python

Para saber como instalar e usar a biblioteca de cliente do Bigtable, consulte Bibliotecas de cliente do Bigtable.

def filter_limit_row_sample(project_id, instance_id, table_id):
    client = bigtable.Client(project=project_id, admin=True)
    instance = client.instance(instance_id)
    table = instance.table(table_id)

    rows = table.read_rows(filter_=row_filters.RowSampleFilter(.75))
    for row in rows:
        print_row(row)

Ruby

Para saber como instalar e usar a biblioteca de cliente do Bigtable, consulte Bibliotecas de cliente do Bigtable.

# instance_id = "my-instance"
# table_id    = "my-table"
filter = Google::Cloud::Bigtable::RowFilter.sample 0.75
read_with_filter instance_id, table_id, filter

A seguir

Para pesquisar e filtrar exemplos de código de outros produtos do Google Cloud, consulte o navegador de exemplos do Google Cloud.