הגדר איסוף אשפה

מדיניות איסוף האשפה של Bigtable מאפשרת לכם לשלוט בעלויות האחסון ולהסיר באופן אוטומטי נתונים מיושנים בתאים. אפשר להציג, להגדיר ולעדכן את כללי המדיניות האלה באמצעות מסוף Cloud de Confiance , ה-CLI של cbt או ספריות הלקוח של Cloud Bigtable. לפני שמתחילים, כדאי לקרוא את הסקירה הכללית על איסוף אשפה.

הצגת המדיניות הנוכחית של איסוף אשפה

כדי לראות את מדיניות איסוף האשפה של קבוצת עמודות, אפשר להשתמש במסוף Cloud de Confiance או ב-CLI של cbt.

המסוף

כדי לראות את מדיניות איסוף האשפה הנוכחית של קבוצת עמודות:

  1. במסוף Cloud de Confiance , פותחים את רשימת המכונות של Bigtable.

    פתיחת רשימת המכונות

  2. לוחצים על המכונה שרוצים לראות את הטבלאות שלה.

  3. בחלונית הימנית, לוחצים על Tables.

    בדף Tables מוצגת רשימת הטבלאות במכונה.

  4. לוחצים על עריכה בשורה של הטבלה.

  5. לוחצים על Open ליד קבוצת העמודות שרוצים לראות.

  6. כשמסיימים לצפות במדיניות איסוף האשפה, לוחצים על Cancel כדי לצאת.

cbt

כדי לחפש את כללי מדיניות איסוף האשפה הנוכחיים של טבלה מסוימת, מריצים את הפקודה הבאה ומחליפים את TABLE_ID במזהה טבלה חוקי:

cbt ls TABLE_ID

קביעת מדיניות איסוף אשפה

אפשר להגדיר מדיניות איסוף אשפה באמצעות מסוף Cloud de Confiance , ה-CLI של cbt או ספריות הלקוח של Cloud Bigtable.

איסוף אשפה לפי גיל

בקטע הבא מוסבר איך להגדיר את הגיל המקסימלי של נתונים בקבוצת עמודות.

המסוף

כדי להגדיר זמן תפוגה לתאים בקבוצת עמודות:

  1. במסוף Cloud de Confiance , פותחים את רשימת המכונות של Bigtable.

    פתיחת רשימת המכונות

  2. לוחצים על המכונה שרוצים לראות את הטבלאות שלה.

  3. בחלונית הימנית, לוחצים על Tables.

    בדף Tables מוצגת רשימת הטבלאות במכונה.

  4. לוחצים על סמל העריכה .

  5. לוחצים על Open ליד קבוצת העמודות שרוצים לערוך.

  6. בוחרים באפשרות מדיניות מבוססת-גיל.

  7. מזינים את הגיל בשדה גיל מקסימלי ובוחרים את יחידת הזמן בתפריט הנפתח יחידה.

    לדוגמה, כדי לשמור את הנתונים של קבוצת עמודות למשך 30 דקות, מזינים 30 ובוחרים באפשרות minutes.

  8. לוחצים על Save.

cbt

בדוגמה הזו נוצרת קבוצת עמודות בשם cf1, ואז מוגדר הגיל המקסימלי לנתונים בקבוצת העמודות לחמישה ימים. הפקודה הזו מורה ל-Bigtable להסיר את כל הנתונים עם חותמות זמן מלפני יותר מחמישה ימים בכל העמודות בקבוצת העמודות הזו.

cbt createfamily your-table cf1
cbt setgcpolicy your-table cf1 maxage=5d

המשך

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

import (
	"context"
	"fmt"
	"io"
	"time"

	admin "cloud.google.com/go/bigtable/admin/apiv2"
	"cloud.google.com/go/bigtable/admin/apiv2/adminpb"
	"google.golang.org/protobuf/types/known/durationpb"
)

func createFamilyGCMaxAge(w io.Writer, projectID, instanceID string, tableName string) error {
	// projectID := "my-project-id"
	// instanceID := "my-instance-id"
	// tableName := "my-table-name"

	ctx := context.Background()

	adminClient, err := admin.NewBigtableTableAdminClient(ctx)
	if err != nil {
		return fmt.Errorf("admin.NewBigtableTableAdminClient: %w", err)
	}
	defer adminClient.Close()

	// Set a garbage collection policy of 5 days.
	maxAge := time.Hour * 24 * 5
	policy := &adminpb.GcRule{
		Rule: &adminpb.GcRule_MaxAge{
			MaxAge: durationpb.New(maxAge),
		},
	}

	columnFamilyName := "cf1"
	req := &adminpb.ModifyColumnFamiliesRequest{
		Name: fmt.Sprintf("projects/%s/instances/%s/tables/%s", projectID, instanceID, tableName),
		Modifications: []*adminpb.ModifyColumnFamiliesRequest_Modification{
			{
				Id: columnFamilyName,
				Mod: &adminpb.ModifyColumnFamiliesRequest_Modification_Create{
					Create: &adminpb.ColumnFamily{
						GcRule: policy,
					},
				},
			},
		},
	}
	if _, err := adminClient.ModifyColumnFamilies(ctx, req); err != nil {
		return fmt.Errorf("ModifyColumnFamilies(%s): %w", columnFamilyName, err)
	}

	fmt.Fprintf(w, "created column family %s with policy: %v\n", columnFamilyName, policy)
	return nil
}

Java

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

// Creates a column family with GC policy : maximum age
// where age = current time minus cell timestamp

// Defines the GC rule to retain data with max age of 5 days.
GcRule maxAgeRule = GcRuleBuilder.maxAge(Duration.ofDays(5));

// Creates column family with given GC rule.
try {
  String tableName =
      "projects/" + projectId + "/instances/" + instanceId + "/tables/" + tableId;
  ModifyColumnFamiliesRequest request =
      ModifyColumnFamiliesRequest.newBuilder()
          .setName(tableName)
          .addModifications(
              ModifyColumnFamiliesRequest.Modification.newBuilder()
                  .setId(COLUMN_FAMILY_1)
                  .setCreate(ColumnFamily.newBuilder().setGcRule(maxAgeRule)))
          .build();
  adminClient.modifyColumnFamilies(request);
  System.out.println("Created column family: " + COLUMN_FAMILY_1);
} catch (AlreadyExistsException e) {
  System.err.println(
      "Failed to create column family with rule, already exists: " + e.getMessage());
}

‫Python asyncio

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

from google.protobuf import duration_pb2

from google.cloud import bigtable_admin_v2

async with bigtable_admin_v2.BigtableTableAdminAsyncClient() as client:
    table_path = client.table_path(project_id, instance_id, table_id)

    print("Creating column family cf1 with MaxAge GC Rule...")
    # Create a column family with GC policy : maximum age
    # where age = current time minus cell timestamp

    # Define the GC rule to retain data with max age of 5 days
    max_age_rule = bigtable_admin_v2.GcRule(
        max_age=duration_pb2.Duration(seconds=5 * 86400)
    )
    cf1 = bigtable_admin_v2.ColumnFamily(gc_rule=max_age_rule)
    mod1 = bigtable_admin_v2.ModifyColumnFamiliesRequest.Modification(
        id="cf1", create=cf1
    )
    await client.modify_column_families(name=table_path, modifications=[mod1])
    print("Created column family cf1 with MaxAge GC Rule.")

Python

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

from google.protobuf import duration_pb2

from google.cloud import bigtable_admin_v2

client = bigtable_admin_v2.BigtableTableAdminClient()
table_path = client.table_path(project_id, instance_id, table_id)

print("Creating column family cf1 with MaxAge GC Rule...")
# Create a column family with GC policy : maximum age
# where age = current time minus cell timestamp

# Define the GC rule to retain data with max age of 5 days
max_age_rule = bigtable_admin_v2.GcRule(
    max_age=duration_pb2.Duration(seconds=5 * 86400)
)
cf1 = bigtable_admin_v2.ColumnFamily(gc_rule=max_age_rule)
mod1 = bigtable_admin_v2.ModifyColumnFamiliesRequest.Modification(
    id="cf1", create=cf1
)
client.modify_column_families(name=table_path, modifications=[mod1])
print("Created column family cf1 with MaxAge GC Rule.")

C#‎

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

// Create a column family with GC policy : maximum age
// where age = current time minus cell timestamp
// Initialize request argument(s).
// Define the GC rule to retain data with max age of 5 days
GcRule MaxAgeRule = new GcRule { MaxAge = Duration.FromTimeSpan(TimeSpan.FromDays(5.0)) };

// Column family to create
ColumnFamily columnFamily = new ColumnFamily { GcRule = MaxAgeRule };

TableName tableName = new TableName(projectId, instanceId, tableId);

// Modification to create column family
ModifyColumnFamiliesRequest.Types.Modification modification = new ModifyColumnFamiliesRequest.Types.Modification
{
    Create = columnFamily,
    Id = "cf1"
};

ModifyColumnFamiliesRequest request = new ModifyColumnFamiliesRequest
{
    TableName = tableName,
    Modifications = { modification }
};
try
{
    // Make the request
    Table response = bigtableTableAdminClient.ModifyColumnFamilies(request);
    Console.WriteLine("Created column family");
    // Print table information.
    GetTable(tableId);
}
catch (Exception ex)
{
    Console.WriteLine($"Error creating column family {ex.Message}");
}

C++‎

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

namespace cbt = ::google::cloud::bigtable;
namespace cbta = ::google::cloud::bigtable_admin;
using ::google::bigtable::admin::v2::ModifyColumnFamiliesRequest;
using ::google::cloud::StatusOr;
[](cbta::BigtableTableAdminClient admin, std::string const& project_id,
   std::string const& instance_id, std::string const& table_id,
   std::string const& family_name) {
  std::string table_name = cbt::TableName(project_id, instance_id, table_id);
  auto constexpr kSecondsPerDay =
      std::chrono::seconds(std::chrono::hours(24)).count();

  ModifyColumnFamiliesRequest::Modification mod;
  mod.set_id(family_name);
  mod.mutable_create()->mutable_gc_rule()->mutable_max_age()->set_seconds(
      5 * kSecondsPerDay);

  StatusOr<google::bigtable::admin::v2::Table> schema =
      admin.ModifyColumnFamilies(table_name, {std::move(mod)});

  if (!schema) throw std::move(schema).status();
  std::cout << "Schema modified to: " << schema->DebugString() << "\n";
}

Node.js

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

// Create a column family with GC policy : maximum age
// where age = current time minus cell timestamp

// Define the GC rule to retain data with max age of 5 days
const maxAgeRule = GcRuleBuilder.rule({
  maxAge: {
    // Value must be atleast 1 millisecond
    seconds: 60 * 60 * 24 * 5,
    nanos: 0,
  },
});
let [family] = await adminClient.modifyColumnFamilies({
  name: table.name,
  modifications: [
    {
      id: 'cf1',
      create: {
        gcRule: maxAgeRule,
      },
    },
  ],
});
console.log(`Created column family ${family.name}`);

PHP

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

use Google\Cloud\Bigtable\Admin\V2\Client\BigtableTableAdminClient;
use Google\Cloud\Bigtable\Admin\V2\ColumnFamily;
use Google\Cloud\Bigtable\Admin\V2\GcRule;
use Google\Cloud\Bigtable\Admin\V2\ModifyColumnFamiliesRequest;
use Google\Cloud\Bigtable\Admin\V2\ModifyColumnFamiliesRequest\Modification;
use Google\Protobuf\Duration;

/**
 * Create a new column family with a max age GC rule
 *
 * @param string $projectId The Google Cloud project ID
 * @param string $instanceId The ID of the Bigtable instance where the table resides
 * @param string $tableId The ID of the table in which the rule needs to be created
 */
function create_family_gc_max_age(
    string $projectId,
    string $instanceId,
    string $tableId
): void {
    $tableAdminClient = new BigtableTableAdminClient();

    $tableName = $tableAdminClient->tableName($projectId, $instanceId, $tableId);

    print('Creating column family cf1 with MaxAge GC Rule...' . PHP_EOL);
    // Create a column family with GC policy : maximum age
    // where age = current time minus cell timestamp

    $columnFamily1 = new ColumnFamily();
    $duration = new Duration();
    $duration->setSeconds(3600 * 24 * 5);
    $MaxAgeRule = (new GcRule())->setMaxAge($duration);
    $columnFamily1->setGcRule($MaxAgeRule);

    $columnModification = new Modification();
    $columnModification->setId('cf1');
    $columnModification->setCreate($columnFamily1);
    $modifyColumnFamiliesRequest = (new ModifyColumnFamiliesRequest())
        ->setName($tableName)
        ->setModifications([$columnModification]);
    $tableAdminClient->modifyColumnFamilies($modifyColumnFamiliesRequest);
    print('Created column family cf1 with MaxAge GC Rule.' . PHP_EOL);
}

Ruby

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

# Create a column family with GC policy : maximum age
# where age = current time minus cell timestamp
# NOTE: Age value must be atleast 1 millisecond
max_age_rule = Google::Cloud::Bigtable::GcRule.max_age 60 * 60 * 24 * 5
column_families = table.column_families do |cfs|
  cfs.add "cf1", gc_rule: max_age_rule
end
family = column_families["cf1"]

איסוף אשפה בהתבסס על מספר הגרסאות

בקטע הבא מוסבר איך ליצור קבוצת עמודות עם מדיניות איסוף אשפה שמציינת את מספר הגרסאות של הנתונים, או את מספר התאים, שצריך לשמור.

המסוף

כדי להגדיר את מספר התאים, או הגרסאות, שיישמרו בקבוצת עמודות:

  1. במסוף Cloud de Confiance , פותחים את רשימת המכונות של Bigtable.

    פתיחת רשימת המכונות

  2. לוחצים על המכונה שרוצים לראות את הטבלאות שלה.

  3. בחלונית הימנית, לוחצים על Tables.

    בדף Tables מוצגת רשימת הטבלאות במכונה.

  4. לוחצים על Edit בשורה של הטבלה.

  5. לוחצים על Open ליד קבוצת העמודות שרוצים לערוך.

  6. בוחרים באפשרות מדיניות מבוססת-גרסה.

  7. מזינים את מספר התאים שרוצים לשמור בכל עמודה בקבוצת העמודות.

  8. לוחצים על Save.

cbt

בדוגמה הזו נוצרת קבוצת עמודות בשם cf2, ואז מוגדר מספר הגרסאות שיישמרו בקבוצת העמודות לשתיים. ההגדרה הזו מורה ל-Bigtable להסיר את כל התאים מלבד שני התאים האחרונים בכל העמודות בקבוצת העמודות הזו.

cbt createfamily your-table cf2
cbt setgcpolicy your-table cf2 maxversions=2

בדוגמה הזו, המדיניות מוגדרת להסיר את כל התאים מלבד החדש ביותר.

cbt setgcpolicy your-table cf2 maxversions=1

המשך

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

import (
	"context"
	"fmt"
	"io"

	admin "cloud.google.com/go/bigtable/admin/apiv2"
	"cloud.google.com/go/bigtable/admin/apiv2/adminpb"
)

func createFamilyGCMaxVersions(w io.Writer, projectID, instanceID string, tableName string) error {
	// projectID := "my-project-id"
	// instanceID := "my-instance-id"
	// tableName := "my-table-name"

	ctx := context.Background()

	adminClient, err := admin.NewBigtableTableAdminClient(ctx)
	if err != nil {
		return fmt.Errorf("admin.NewBigtableTableAdminClient: %w", err)
	}
	defer adminClient.Close()

	// Set a garbage collection policy of 2 versions.
	policy := &adminpb.GcRule{
		Rule: &adminpb.GcRule_MaxNumVersions{
			MaxNumVersions: 2,
		},
	}

	columnFamilyName := "cf2"
	req := &adminpb.ModifyColumnFamiliesRequest{
		Name: fmt.Sprintf("projects/%s/instances/%s/tables/%s", projectID, instanceID, tableName),
		Modifications: []*adminpb.ModifyColumnFamiliesRequest_Modification{
			{
				Id: columnFamilyName,
				Mod: &adminpb.ModifyColumnFamiliesRequest_Modification_Create{
					Create: &adminpb.ColumnFamily{
						GcRule: policy,
					},
				},
			},
		},
	}
	if _, err := adminClient.ModifyColumnFamilies(ctx, req); err != nil {
		return fmt.Errorf("ModifyColumnFamilies(%s): %w", columnFamilyName, err)
	}

	fmt.Fprintf(w, "created column family %s with policy: %v\n", columnFamilyName, policy)
	return nil
}

Java

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

// Creates a column family with GC policy : most recent N versions
// where 1 = most recent version

// Defines the GC policy to retain only the most recent 2 versions.
GcRule versionRule = GcRuleBuilder.maxVersions(2);

// Creates column family with given GC rule.
try {
  String tableName =
      "projects/" + projectId + "/instances/" + instanceId + "/tables/" + tableId;
  ModifyColumnFamiliesRequest request =
      ModifyColumnFamiliesRequest.newBuilder()
          .setName(tableName)
          .addModifications(
              ModifyColumnFamiliesRequest.Modification.newBuilder()
                  .setId(COLUMN_FAMILY_2)
                  .setCreate(ColumnFamily.newBuilder().setGcRule(versionRule)))
          .build();
  adminClient.modifyColumnFamilies(request);
  System.out.println("Created column family: " + COLUMN_FAMILY_2);
} catch (AlreadyExistsException e) {
  System.err.println(
      "Failed to create column family with rule, already exists: " + e.getMessage());
}

‫Python asyncio

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

from google.cloud import bigtable_admin_v2

async with bigtable_admin_v2.BigtableTableAdminAsyncClient() as client:
    table_path = client.table_path(project_id, instance_id, table_id)

    print("Creating column family cf2 with max versions GC rule...")
    # Create a column family with GC policy : most recent N versions
    # where 1 = most recent version

    # Define the GC policy to retain only the most recent 2 versions
    max_versions_rule = bigtable_admin_v2.GcRule(max_num_versions=2)
    cf2 = bigtable_admin_v2.ColumnFamily(gc_rule=max_versions_rule)
    mod2 = bigtable_admin_v2.ModifyColumnFamiliesRequest.Modification(
        id="cf2", create=cf2
    )
    await client.modify_column_families(name=table_path, modifications=[mod2])
    print("Created column family cf2 with Max Versions GC Rule.")

Python

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

from google.cloud import bigtable_admin_v2

client = bigtable_admin_v2.BigtableTableAdminClient()
table_path = client.table_path(project_id, instance_id, table_id)

print("Creating column family cf2 with max versions GC rule...")
# Create a column family with GC policy : most recent N versions
# where 1 = most recent version

# Define the GC policy to retain only the most recent 2 versions
max_versions_rule = bigtable_admin_v2.GcRule(max_num_versions=2)
cf2 = bigtable_admin_v2.ColumnFamily(gc_rule=max_versions_rule)
mod2 = bigtable_admin_v2.ModifyColumnFamiliesRequest.Modification(
    id="cf2", create=cf2
)
client.modify_column_families(name=table_path, modifications=[mod2])
print("Created column family cf2 with Max Versions GC Rule.")

C#‎

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

// Create a column family with GC policy : most recent N versions
// where 1 = most recent version
// Initialize request argument(s).
// Define the GC policy to retain only the most recent 2 versions
GcRule maxVersionsRule = new GcRule { MaxNumVersions = 2 };

// Column family to create
ColumnFamily columnFamily = new ColumnFamily { GcRule = maxVersionsRule };

TableName tableName = new TableName(projectId, instanceId, tableId);

// Modification to create column family
ModifyColumnFamiliesRequest.Types.Modification modification = new ModifyColumnFamiliesRequest.Types.Modification
{
    Create = columnFamily,
    Id = "cf2"
};

ModifyColumnFamiliesRequest request = new ModifyColumnFamiliesRequest
{
    TableName = tableName,
    Modifications = { modification }
};
try
{
    // Make the request
    Table response = bigtableTableAdminClient.ModifyColumnFamilies(request);
    Console.WriteLine("Created column family");
}
catch (Exception ex)
{
    Console.WriteLine($"Error creating column family {ex.Message}");
}

C++‎

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

namespace cbt = ::google::cloud::bigtable;
namespace cbta = ::google::cloud::bigtable_admin;
using ::google::bigtable::admin::v2::ModifyColumnFamiliesRequest;
using ::google::cloud::StatusOr;
[](cbta::BigtableTableAdminClient admin, std::string const& project_id,
   std::string const& instance_id, std::string const& table_id,
   std::string const& family_name) {
  std::string table_name = cbt::TableName(project_id, instance_id, table_id);

  ModifyColumnFamiliesRequest::Modification mod;
  mod.set_id(family_name);
  mod.mutable_create()->mutable_gc_rule()->set_max_num_versions(2);

  StatusOr<google::bigtable::admin::v2::Table> schema =
      admin.ModifyColumnFamilies(table_name, {std::move(mod)});

  if (!schema) throw std::move(schema).status();
  std::cout << "Schema modified to: " << schema->DebugString() << "\n";
}

Node.js

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

// Create a column family with GC policy : most recent N versions
// where 1 = most recent version

// Define the GC policy to retain only the most recent 2 versions
const maxVersionsRule = GcRuleBuilder.rule({
  maxVersions: 2,
});

// Create a column family with given GC rule
[family] = await adminClient.modifyColumnFamilies({
  name: table.name,
  modifications: [
    {
      id: 'cf2',
      create: {
        gcRule: maxVersionsRule,
      },
    },
  ],
});
console.log(`Created column family ${family.name}`);

PHP

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

use Google\Cloud\Bigtable\Admin\V2\Client\BigtableTableAdminClient;
use Google\Cloud\Bigtable\Admin\V2\ColumnFamily;
use Google\Cloud\Bigtable\Admin\V2\GcRule;
use Google\Cloud\Bigtable\Admin\V2\ModifyColumnFamiliesRequest;
use Google\Cloud\Bigtable\Admin\V2\ModifyColumnFamiliesRequest\Modification;

/**
 * Create a new column family with a max versions GC rule
 *
 * @param string $projectId The Google Cloud project ID
 * @param string $instanceId The ID of the Bigtable instance where the table resides
 * @param string $tableId The ID of the table in which the rule needs to be created
 */
function create_family_gc_max_versions(
    string $projectId,
    string $instanceId,
    string $tableId
): void {
    $tableAdminClient = new BigtableTableAdminClient();

    $tableName = $tableAdminClient->tableName($projectId, $instanceId, $tableId);

    print('Creating column family cf2 with max versions GC rule...' . PHP_EOL);
    $columnFamily2 = new ColumnFamily();
    $maxVersionRule = (new GcRule())->setMaxNumVersions(2);
    $columnFamily2->setGCRule($maxVersionRule);

    $columnModification = new Modification();
    $columnModification->setId('cf2');
    $columnModification->setCreate($columnFamily2);
    $modifyColumnFamiliesRequest = (new ModifyColumnFamiliesRequest())
        ->setName($tableName)
        ->setModifications([$columnModification]);
    $tableAdminClient->modifyColumnFamilies($modifyColumnFamiliesRequest);

    print('Created column family cf2 with Max Versions GC Rule.' . PHP_EOL);
}

Ruby

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

# Create a column family with GC policy : most recent N versions
# where 1 = most recent version
max_versions_rule = Google::Cloud::Bigtable::GcRule.max_versions 2
column_families = table.column_families do |cfs|
  cfs.add "cf2", gc_rule: max_versions_rule
end
family = column_families["cf2"]

איסוף אשפה על סמך כמה קריטריונים

בקטע הבא מוסבר איך ליצור קבוצת עמודות עם מדיניות איסוף אשפה מסוג intersection.

המסוף

כדי להגדיר מדיניות intersection garbage-collection לתאים בקבוצת עמודות:

  1. במסוף Cloud de Confiance , פותחים את רשימת המכונות של Bigtable.

    פתיחת רשימת המכונות

  2. לוחצים על המכונה שרוצים לראות את הטבלאות שלה.

  3. בחלונית הימנית, לוחצים על Tables.

    בדף Tables מוצגת רשימת הטבלאות במכונה.

  4. לוחצים על עריכה בשורה של הטבלה.

  5. לוחצים על Open ליד קבוצת העמודות שרוצים לערוך.

  6. בוחרים באפשרות מדיניות בהתאמה אישית.

  7. מזינים כלל איסוף אשפה באזור הטקסט, ומגדירים ערכים ל-maxage, ל-maxversions או לשניהם. יחידות הגיל הקבילות הן ms,‏ s,‏ m,‏ h ו-d, שמייצגות אלפיות השנייה, שניות, דקות, שעות וימים.

    לדוגמה, כדי להסיר תאים שנוצרו לפני יותר מחמישה ימים וגם לפני שני התאים האחרונים, מזינים את הפקודה הבאה: התאים צריכים לעמוד בשני הקריטריונים כדי שהם יוסרו.

    maxage=5d and maxversions=2
    
  8. לוחצים על Save.

cbt

בדוגמה הזו נוצרת קבוצת עמודות בשם cf4, ואז מוגדרת מדיניות איסוף אשפה שמסירה תאים שנוצרו לפני יותר מחמישה ימים וגם תאים שנוצרו לפני שני התאים האחרונים בכל העמודות בקבוצת העמודות. התאים צריכים לעמוד בשני הקריטריונים כדי שיוסרו.

cbt createfamily your-table cf4
cbt setgcpolicy your-table cf4 maxage=5d and maxversions=2

בדוגמה הזו מוגדרת מדיניות שמסירה את כל התאים שנוצרו לפני יותר מ-14 ימים, חוץ מהתא החדש ביותר.

cbt setgcpolicy your-table cf4 maxage=14d and maxversions=1

המשך

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

import (
	"context"
	"fmt"
	"io"
	"time"

	admin "cloud.google.com/go/bigtable/admin/apiv2"
	"cloud.google.com/go/bigtable/admin/apiv2/adminpb"
	"google.golang.org/protobuf/types/known/durationpb"
)

func createFamilyGCIntersect(w io.Writer, projectID, instanceID string, tableName string) error {
	// projectID := "my-project-id"
	// instanceID := "my-instance-id"
	// tableName := "my-table-name"

	ctx := context.Background()

	adminClient, err := admin.NewBigtableTableAdminClient(ctx)
	if err != nil {
		return fmt.Errorf("admin.NewBigtableTableAdminClient: %w", err)
	}
	defer adminClient.Close()

	// GC rule: Drop cells older than 5 days AND older than the most recent 2 versions
	maxAge := time.Hour * 24 * 5
	policy := &adminpb.GcRule{
		Rule: &adminpb.GcRule_Intersection_{
			Intersection: &adminpb.GcRule_Intersection{
				Rules: []*adminpb.GcRule{
					{
						Rule: &adminpb.GcRule_MaxNumVersions{
							MaxNumVersions: 2,
						},
					},
					{
						Rule: &adminpb.GcRule_MaxAge{
							MaxAge: durationpb.New(maxAge),
						},
					},
				},
			},
		},
	}

	columnFamilyName := "cf4"
	req := &adminpb.ModifyColumnFamiliesRequest{
		Name: fmt.Sprintf("projects/%s/instances/%s/tables/%s", projectID, instanceID, tableName),
		Modifications: []*adminpb.ModifyColumnFamiliesRequest_Modification{
			{
				Id: columnFamilyName,
				Mod: &adminpb.ModifyColumnFamiliesRequest_Modification_Create{
					Create: &adminpb.ColumnFamily{
						GcRule: policy,
					},
				},
			},
		},
	}
	if _, err := adminClient.ModifyColumnFamilies(ctx, req); err != nil {
		return fmt.Errorf("ModifyColumnFamilies(%s): %w", columnFamilyName, err)
	}

	fmt.Fprintf(w, "created column family %s with policy: %v\n", columnFamilyName, policy)
	return nil
}

Java

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

// Creates a column family with GC policy to drop data that matches all conditions.

// Defines a GC rule to drop cells older than 5 days AND older than the most recent 2 versions.
GcRule intersectionRule =
    GcRuleBuilder.intersection()
        .add(GcRuleBuilder.maxAge(Duration.ofDays(5)))
        .add(GcRuleBuilder.maxVersions(2))
        .build();

// Creates column family with given GC rule.
try {
  String tableName =
      "projects/" + projectId + "/instances/" + instanceId + "/tables/" + tableId;
  ModifyColumnFamiliesRequest request =
      ModifyColumnFamiliesRequest.newBuilder()
          .setName(tableName)
          .addModifications(
              ModifyColumnFamiliesRequest.Modification.newBuilder()
                  .setId(COLUMN_FAMILY_4)
                  .setCreate(ColumnFamily.newBuilder().setGcRule(intersectionRule)))
          .build();
  adminClient.modifyColumnFamilies(request);
  System.out.println("Created column family: " + COLUMN_FAMILY_4);
} catch (AlreadyExistsException e) {
  System.err.println(
      "Failed to create column family with rule, already exists: " + e.getMessage());
}

‫Python asyncio

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

from google.protobuf import duration_pb2

from google.cloud import bigtable_admin_v2

async with bigtable_admin_v2.BigtableTableAdminAsyncClient() as client:
    table_path = client.table_path(project_id, instance_id, table_id)

    print("Creating column family cf4 with Intersection GC rule...")
    # Create a column family with GC policy to drop data that matches
    # all conditions
    # GC rule: Drop cells older than 5 days AND older than the most
    # recent 2 versions
    intersection_rule = bigtable_admin_v2.GcRule(
        intersection=bigtable_admin_v2.GcRule.Intersection(
            rules=[
                bigtable_admin_v2.GcRule(
                    max_age=duration_pb2.Duration(seconds=5 * 86400)
                ),
                bigtable_admin_v2.GcRule(max_num_versions=2),
            ]
        )
    )
    cf4 = bigtable_admin_v2.ColumnFamily(gc_rule=intersection_rule)
    mod4 = bigtable_admin_v2.ModifyColumnFamiliesRequest.Modification(
        id="cf4", create=cf4
    )
    await client.modify_column_families(name=table_path, modifications=[mod4])
    print("Created column family cf4 with Intersection GC rule.")

Python

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

from google.protobuf import duration_pb2

from google.cloud import bigtable_admin_v2

client = bigtable_admin_v2.BigtableTableAdminClient()
table_path = client.table_path(project_id, instance_id, table_id)

print("Creating column family cf4 with Intersection GC rule...")
# Create a column family with GC policy to drop data that matches
# all conditions
# GC rule: Drop cells older than 5 days AND older than the most
# recent 2 versions
intersection_rule = bigtable_admin_v2.GcRule(
    intersection=bigtable_admin_v2.GcRule.Intersection(
        rules=[
            bigtable_admin_v2.GcRule(
                max_age=duration_pb2.Duration(seconds=5 * 86400)
            ),
            bigtable_admin_v2.GcRule(max_num_versions=2),
        ]
    )
)
cf4 = bigtable_admin_v2.ColumnFamily(gc_rule=intersection_rule)
mod4 = bigtable_admin_v2.ModifyColumnFamiliesRequest.Modification(
    id="cf4", create=cf4
)
client.modify_column_families(name=table_path, modifications=[mod4])
print("Created column family cf4 with Intersection GC rule.")

C#‎

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

// Create a column family with GC policy to drop data that matches all conditions.
// Initialize request argument(s).
// GC rule: Drop cells older than 5 days AND older than the most recent 2 versions.
GcRule.Types.Intersection intersectionRule = new GcRule.Types.Intersection
{
    Rules =
    {
        new GcRule { MaxNumVersions = 2 },
        new GcRule { MaxAge = Duration.FromTimeSpan(TimeSpan.FromDays(5)) }
    }
};
GcRule gcRule = new GcRule { Intersection = intersectionRule };

// Column family to create
ColumnFamily columnFamily = new ColumnFamily { GcRule = gcRule };

TableName tableName = new TableName(projectId, instanceId, tableId);

// Modification to create column family
ModifyColumnFamiliesRequest.Types.Modification modification = new ModifyColumnFamiliesRequest.Types.Modification
{
    Create = columnFamily,
    Id = "cf4"
};

ModifyColumnFamiliesRequest request = new ModifyColumnFamiliesRequest
{
    TableName = tableName,
    Modifications = { modification }
};
try
{
    // Make the request
    Table response = bigtableTableAdminClient.ModifyColumnFamilies(request);
    Console.WriteLine("Created column family");
}
catch (Exception ex)
{
    Console.WriteLine($"Error creating column family {ex.Message}");
}

C++‎

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

namespace cbt = ::google::cloud::bigtable;
namespace cbta = ::google::cloud::bigtable_admin;
using ::google::bigtable::admin::v2::ModifyColumnFamiliesRequest;
using ::google::cloud::StatusOr;
[](cbta::BigtableTableAdminClient admin, std::string const& project_id,
   std::string const& instance_id, std::string const& table_id,
   std::string const& family_name) {
  std::string table_name = cbt::TableName(project_id, instance_id, table_id);
  auto constexpr kSecondsPerDay =
      std::chrono::seconds(std::chrono::hours(24)).count();

  ModifyColumnFamiliesRequest::Modification mod;
  mod.set_id(family_name);
  auto& gc_int =
      *mod.mutable_create()->mutable_gc_rule()->mutable_intersection();
  gc_int.add_rules()->set_max_num_versions(1);
  gc_int.add_rules()->mutable_max_age()->set_seconds(5 * kSecondsPerDay);

  StatusOr<google::bigtable::admin::v2::Table> schema =
      admin.ModifyColumnFamilies(table_name, {std::move(mod)});

  if (!schema) throw std::move(schema).status();
  std::cout << "Schema modified to: " << schema->DebugString() << "\n";
}

Node.js

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

// Create a column family with GC policy to drop data that matches all conditions

// GC rule: Drop cells older than 5 days AND older than the most recent 2 versions
const intersectionRule = GcRuleBuilder.intersection(
  GcRuleBuilder.rule({
    maxVersions: 2,
  }),
  GcRuleBuilder.rule({
    maxAge: {
      seconds: 60 * 60 * 24 * 5,
      nanos: 0,
    },
  }),
);
[family] = await adminClient.modifyColumnFamilies({
  name: table.name,
  modifications: [
    {
      id: 'cf4',
      create: {
        gcRule: intersectionRule,
      },
    },
  ],
});
console.log(`Created column family ${family.name}`);

PHP

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

use Google\Cloud\Bigtable\Admin\V2\Client\BigtableTableAdminClient;
use Google\Cloud\Bigtable\Admin\V2\ColumnFamily;
use Google\Cloud\Bigtable\Admin\V2\GcRule;
use Google\Cloud\Bigtable\Admin\V2\GcRule\Intersection as GcRuleIntersection;
use Google\Cloud\Bigtable\Admin\V2\ModifyColumnFamiliesRequest;
use Google\Cloud\Bigtable\Admin\V2\ModifyColumnFamiliesRequest\Modification;
use Google\Protobuf\Duration;

/**
 * Create a new column family with an intersection GC rule
 *
 * @param string $projectId The Google Cloud project ID
 * @param string $instanceId The ID of the Bigtable instance where the table resides
 * @param string $tableId The ID of the table in which the rule needs to be created
 */
function create_family_gc_intersection(
    string $projectId,
    string $instanceId,
    string $tableId
): void {
    $tableAdminClient = new BigtableTableAdminClient();

    $tableName = $tableAdminClient->tableName($projectId, $instanceId, $tableId);

    print('Creating column family cf4 with Intersection GC rule...' . PHP_EOL);
    $columnFamily4 = new ColumnFamily();

    $intersectionRule = new GcRuleIntersection();
    $intersectionArray = [
        (new GcRule())->setMaxAge((new Duration())->setSeconds(3600 * 24 * 5)),
        (new GcRule())->setMaxNumVersions(2)
    ];
    $intersectionRule->setRules($intersectionArray);

    $intersection = new GcRule();
    $intersection->setIntersection($intersectionRule);

    $columnFamily4->setGCRule($intersection);

    $columnModification = new Modification();
    $columnModification->setId('cf4');
    $columnModification->setCreate($columnFamily4);
    $modifyColumnFamiliesRequest = (new ModifyColumnFamiliesRequest())
        ->setName($tableName)
        ->setModifications([$columnModification]);
    $tableAdminClient->modifyColumnFamilies($modifyColumnFamiliesRequest);

    print('Created column family cf4 with Union GC rule' . PHP_EOL);
}

Ruby

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

# Create a column family with GC policy to drop data that matches at least
# one condition
max_age_rule = Google::Cloud::Bigtable::GcRule.max_age 60 * 60 * 24 * 5
max_versions_rule = Google::Cloud::Bigtable::GcRule.max_versions 2
intersection_gc_rule = Google::Cloud::Bigtable::GcRule.intersection max_age_rule, max_versions_rule
column_families = table.column_families do |cfs|
  cfs.add "cf4", gc_rule: intersection_gc_rule
end
family = column_families["cf4"]

בקטע הבא מוסבר איך ליצור קבוצת עמודות עם מדיניות איסוף אשפה מסוג union.

המסוף

כדי להגדיר מדיניות איחוד של איסוף אשפה לתאים בקבוצת עמודות:

  1. במסוף Cloud de Confiance , פותחים את רשימת המכונות של Bigtable.

    פתיחת רשימת המכונות

  2. לוחצים על המכונה שרוצים לראות את הטבלאות שלה.

  3. בחלונית הימנית, לוחצים על Tables.

    בדף Tables מוצגת רשימת הטבלאות במכונה.

  4. לוחצים על עריכה בשורה של הטבלה.

  5. לוחצים על Open ליד קבוצת העמודות שרוצים לערוך.

  6. בוחרים באפשרות מדיניות בהתאמה אישית.

  7. מזינים כלל איסוף אשפה באזור הטקסט, ומגדירים ערכים ל-maxage, ל-maxversions או לשניהם. יחידות הגיל הקבילות הן ms,‏ s,‏ m,‏ h ו-d, שמייצגות אלפיות השנייה, שניות, דקות, שעות וימים.

    לדוגמה, כדי להסיר תאים שנוצרו לפני יותר מ-5 ימים או שהם ישנים יותר משני התאים האחרונים, מזינים את הפרטים הבאים: תאים שיוסרו צריכים לעמוד באחד מהקריטריונים.

    maxage=5d or maxversions=2
    
  8. לוחצים על Save.

cbt

בדוגמה הזו נוצרת קבוצת עמודות בשם cf3, ואז מוגדרת מדיניות איסוף אשפה שמסירה תאים שנוצרו לפני יותר מחמישה ימים או שהם ישנים יותר משני התאים האחרונים. כדי להסיר תאים, הם צריכים לעמוד באחד מהתנאים.

cbt createfamily your-table cf3
cbt setgcpolicy your-table cf3 maxage=5d or maxversions=2

בדוגמה הזו מוגדרת מדיניות שמסירה את כל ערכי התאים מלבד הערך החדש ביותר, אבל מסירה גם את התא החדש ביותר אם הוא ישן יותר משנייה אחת.

cbt setgcpolicy your-table cf3 maxversions=1 or maxage=1s

המשך

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

import (
	"context"
	"fmt"
	"io"
	"time"

	admin "cloud.google.com/go/bigtable/admin/apiv2"
	"cloud.google.com/go/bigtable/admin/apiv2/adminpb"
	"google.golang.org/protobuf/types/known/durationpb"
)

func createFamilyGCUnion(w io.Writer, projectID, instanceID string, tableName string) error {
	// projectID := "my-project-id"
	// instanceID := "my-instance-id"
	// tableName := "my-table-name"

	ctx := context.Background()

	adminClient, err := admin.NewBigtableTableAdminClient(ctx)
	if err != nil {
		return fmt.Errorf("admin.NewBigtableTableAdminClient: %w", err)
	}
	defer adminClient.Close()

	// Define a GC rule to drop cells older than 5 days or not the most recent version
	maxAge := time.Hour * 24 * 5
	policy := &adminpb.GcRule{
		Rule: &adminpb.GcRule_Union_{
			Union: &adminpb.GcRule_Union{
				Rules: []*adminpb.GcRule{
					{
						Rule: &adminpb.GcRule_MaxNumVersions{
							MaxNumVersions: 2,
						},
					},
					{
						Rule: &adminpb.GcRule_MaxAge{
							MaxAge: durationpb.New(maxAge),
						},
					},
				},
			},
		},
	}

	columnFamilyName := "cf3"
	req := &adminpb.ModifyColumnFamiliesRequest{
		Name: fmt.Sprintf("projects/%s/instances/%s/tables/%s", projectID, instanceID, tableName),
		Modifications: []*adminpb.ModifyColumnFamiliesRequest_Modification{
			{
				Id: columnFamilyName,
				Mod: &adminpb.ModifyColumnFamiliesRequest_Modification_Create{
					Create: &adminpb.ColumnFamily{
						GcRule: policy,
					},
				},
			},
		},
	}
	if _, err := adminClient.ModifyColumnFamilies(ctx, req); err != nil {
		return fmt.Errorf("ModifyColumnFamilies(%s): %w", columnFamilyName, err)
	}

	fmt.Fprintf(w, "created column family %s with policy: %v\n", columnFamilyName, policy)
	return nil
}

Java

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

// Creates a column family with GC policy to drop data that matches at least one condition.

// Defines a list of GC rules to drop cells older than 5 days OR not the most recent
// version.
GcRule unionRule =
    GcRuleBuilder.union()
        .add(GcRuleBuilder.maxAge(Duration.ofDays(5)))
        .add(GcRuleBuilder.maxVersions(1))
        .build();

// Creates column family with given GC rule.
try {
  String tableName =
      "projects/" + projectId + "/instances/" + instanceId + "/tables/" + tableId;
  ModifyColumnFamiliesRequest request =
      ModifyColumnFamiliesRequest.newBuilder()
          .setName(tableName)
          .addModifications(
              ModifyColumnFamiliesRequest.Modification.newBuilder()
                  .setId(COLUMN_FAMILY_3)
                  .setCreate(ColumnFamily.newBuilder().setGcRule(unionRule)))
          .build();
  adminClient.modifyColumnFamilies(request);
  System.out.println("Created column family: " + COLUMN_FAMILY_3);
} catch (AlreadyExistsException e) {
  System.err.println(
      "Failed to create column family with rule, already exists: " + e.getMessage());
}

‫Python asyncio

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

from google.protobuf import duration_pb2

from google.cloud import bigtable_admin_v2

async with bigtable_admin_v2.BigtableTableAdminAsyncClient() as client:
    table_path = client.table_path(project_id, instance_id, table_id)

    print("Creating column family cf3 with union GC rule...")
    # Create a column family with GC policy to drop data that matches
    # at least one condition.
    # Define a GC rule to drop cells older than 5 days or not the
    # most recent version
    union_rule = bigtable_admin_v2.GcRule(
        union=bigtable_admin_v2.GcRule.Union(
            rules=[
                bigtable_admin_v2.GcRule(
                    max_age=duration_pb2.Duration(seconds=5 * 86400)
                ),
                bigtable_admin_v2.GcRule(max_num_versions=2),
            ]
        )
    )
    cf3 = bigtable_admin_v2.ColumnFamily(gc_rule=union_rule)
    mod3 = bigtable_admin_v2.ModifyColumnFamiliesRequest.Modification(
        id="cf3", create=cf3
    )
    await client.modify_column_families(name=table_path, modifications=[mod3])
    print("Created column family cf3 with Union GC rule")

Python

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

from google.protobuf import duration_pb2

from google.cloud import bigtable_admin_v2

client = bigtable_admin_v2.BigtableTableAdminClient()
table_path = client.table_path(project_id, instance_id, table_id)

print("Creating column family cf3 with union GC rule...")
# Create a column family with GC policy to drop data that matches
# at least one condition.
# Define a GC rule to drop cells older than 5 days or not the
# most recent version
union_rule = bigtable_admin_v2.GcRule(
    union=bigtable_admin_v2.GcRule.Union(
        rules=[
            bigtable_admin_v2.GcRule(
                max_age=duration_pb2.Duration(seconds=5 * 86400)
            ),
            bigtable_admin_v2.GcRule(max_num_versions=2),
        ]
    )
)
cf3 = bigtable_admin_v2.ColumnFamily(gc_rule=union_rule)
mod3 = bigtable_admin_v2.ModifyColumnFamiliesRequest.Modification(
    id="cf3", create=cf3
)
client.modify_column_families(name=table_path, modifications=[mod3])
print("Created column family cf3 with Union GC rule")

C#‎

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

// Create a column family with GC policy to drop data that matches at least one condition.
// Initialize request argument(s).
// Define a GC rule to drop cells older than 5 days or not the most recent version.
GcRule.Types.Union unionRule = new GcRule.Types.Union
{
    Rules =
    {
        new GcRule { MaxNumVersions = 1 },
        new GcRule { MaxAge = Duration.FromTimeSpan(TimeSpan.FromDays(5)) }
    }
};
GcRule gcRule = new GcRule { Union = unionRule };

// Column family to create
ColumnFamily columnFamily = new ColumnFamily { GcRule = gcRule };

TableName tableName = new TableName(projectId, instanceId, tableId);

// Modification to create column family
ModifyColumnFamiliesRequest.Types.Modification modification = new ModifyColumnFamiliesRequest.Types.Modification
{
    Create = columnFamily,
    Id = "cf3"
};

ModifyColumnFamiliesRequest request = new ModifyColumnFamiliesRequest
{
    TableName = tableName,
    Modifications = { modification }
};
try
{
    // Make the request
    Table response = bigtableTableAdminClient.ModifyColumnFamilies(request);
    Console.WriteLine("Created column family");
}
catch (Exception ex)
{
    Console.WriteLine($"Error creating column family {ex.Message}");
}

C++‎

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

namespace cbt = ::google::cloud::bigtable;
namespace cbta = ::google::cloud::bigtable_admin;
using ::google::bigtable::admin::v2::ModifyColumnFamiliesRequest;
using ::google::cloud::StatusOr;
[](cbta::BigtableTableAdminClient admin, std::string const& project_id,
   std::string const& instance_id, std::string const& table_id,
   std::string const& family_name) {
  std::string table_name = cbt::TableName(project_id, instance_id, table_id);
  auto constexpr kSecondsPerDay =
      std::chrono::seconds(std::chrono::hours(24)).count();

  ModifyColumnFamiliesRequest::Modification mod;
  mod.set_id(family_name);
  auto& gc_union = *mod.mutable_create()->mutable_gc_rule()->mutable_union_();
  gc_union.add_rules()->set_max_num_versions(1);
  gc_union.add_rules()->mutable_max_age()->set_seconds(5 * kSecondsPerDay);

  StatusOr<google::bigtable::admin::v2::Table> schema =
      admin.ModifyColumnFamilies(table_name, {std::move(mod)});

  if (!schema) throw std::move(schema).status();
  std::cout << "Schema modified to: " << schema->DebugString() << "\n";
}

Node.js

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

// Create a column family with GC policy to drop data that matches at least one condition.

// Define a GC rule to drop cells older than 5 days or not the most recent version
const unionRule = GcRuleBuilder.union(
  GcRuleBuilder.rule({
    maxVersions: 1,
  }),
  GcRuleBuilder.rule({
    maxAge: {
      seconds: 60 * 60 * 24 * 5,
      nanos: 0,
    },
  }),
);

[family] = await adminClient.modifyColumnFamilies({
  name: table.name,
  modifications: [
    {
      id: 'cf3',
      create: {
        gcRule: unionRule,
      },
    },
  ],
});
console.log(`Created column family ${family.name}`);

PHP

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

use Google\Cloud\Bigtable\Admin\V2\Client\BigtableTableAdminClient;
use Google\Cloud\Bigtable\Admin\V2\ColumnFamily;
use Google\Cloud\Bigtable\Admin\V2\GcRule;
use Google\Cloud\Bigtable\Admin\V2\GcRule\Union as GcRuleUnion;
use Google\Cloud\Bigtable\Admin\V2\ModifyColumnFamiliesRequest;
use Google\Cloud\Bigtable\Admin\V2\ModifyColumnFamiliesRequest\Modification;
use Google\Protobuf\Duration;

/**
 * Create a new column family with a union GC rule
 *
 * @param string $projectId The Google Cloud project ID
 * @param string $instanceId The ID of the Bigtable instance where the table resides
 * @param string $tableId The ID of the table in which the rule needs to be created
 */
function create_family_gc_union(
    string $projectId,
    string $instanceId,
    string $tableId
): void {
    $tableAdminClient = new BigtableTableAdminClient();

    $tableName = $tableAdminClient->tableName($projectId, $instanceId, $tableId);

    print('Creating column family cf3 with union GC rule...' . PHP_EOL);
    // Create a column family with GC policy to drop data that matches
    // at least one condition.
    // Define a GC rule to drop cells older than 5 days or not the
    // most recent version

    $columnFamily3 = new ColumnFamily();

    $ruleUnion = new GcRuleUnion();
    $ruleUnionArray = [
        (new GcRule())->setMaxNumVersions(2),
        (new GcRule())->setMaxAge((new Duration())->setSeconds(3600 * 24 * 5))
    ];
    $ruleUnion->setRules($ruleUnionArray);
    $union = new GcRule();
    $union->setUnion($ruleUnion);

    $columnFamily3->setGCRule($union);

    $columnModification = new Modification();
    $columnModification->setId('cf3');
    $columnModification->setCreate($columnFamily3);
    $modifyColumnFamiliesRequest = (new ModifyColumnFamiliesRequest())
        ->setName($tableName)
        ->setModifications([$columnModification]);
    $tableAdminClient->modifyColumnFamilies($modifyColumnFamiliesRequest);

    print('Created column family cf3 with Union GC rule.' . PHP_EOL);
}

Ruby

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

# Create a column family with GC policy to drop data that matches at least
# one condition
max_age_rule = Google::Cloud::Bigtable::GcRule.max_age 60 * 60 * 24 * 5
max_versions_rule = Google::Cloud::Bigtable::GcRule.max_versions 2
union_gc_rule = Google::Cloud::Bigtable::GcRule.union max_age_rule, max_versions_rule
column_families = table.column_families do |cfs|
  cfs.add "cf3", gc_rule: union_gc_rule
end
family = column_families["cf3"]

בקטע הבא מוסבר איך ליצור קבוצת עמודות עם מדיניות איסוף אשפה מקוננת. מדיניות איסוף אשפה בתצוגת עץ כוללת שילוב של כללי איחוד וחיתוך.

המסוף

כדי להגדיר מדיניות איסוף אשפה בתצורה של עץ למשבצות בקבוצת עמודות:

  1. במסוף Cloud de Confiance , פותחים את רשימת המכונות של Bigtable.

    פתיחת רשימת המכונות

  2. לוחצים על המכונה שרוצים לראות את הטבלאות שלה.

  3. בחלונית הימנית, לוחצים על Tables.

    בדף Tables מוצגת רשימת הטבלאות במכונה.

  4. לוחצים על עריכה בשורה של הטבלה.

  5. לוחצים על Open ליד קבוצת העמודות שרוצים לערוך.

  6. בוחרים באפשרות מדיניות בהתאמה אישית.

  7. מזינים כלל איסוף אשפה באזור הטקסט, ומגדירים ערכים ל-maxage, ל-maxversions או לשניהם. יחידות הגיל הקבילות הן ms,‏ s,‏ m,‏ h ו-d, שמייצגות אלפיות השנייה, שניות, דקות, שעות וימים.

    לדוגמה, כדי לשמור את שני התאים החדשים ביותר גם אם הם בני יותר מדקה, או לשמור את עשרת התאים החדשים ביותר כל עוד הם בני פחות מדקה, מזינים את הפרטים הבאים:

    (maxage=1m and maxversions=2) or maxversions=10
    
  8. לוחצים על Save.

cbt

בדוגמה הזו נוצרת קבוצת עמודות בשם cf5, ואז מוגדרת מדיניות איסוף אשפה שמסירה תאים בקבוצת העמודות שעומדים באחד מהתנאים הבאים:

  • ישנים יותר מ-10 התאים האחרונים
  • ישן יותר מדקה אחת וגם ישן יותר משני התאים האחרונים

במילים אחרות, המדיניות הזו שומרת את שני התאים החדשים ביותר גם אם הם בני יותר מדקה, או שומרת את עשרת התאים החדשים ביותר כל עוד הם בני פחות מדקה.

cbt createfamily your-table cf5
cbt setgcpolicy your-table cf5 "(maxage=1m and maxversions=2) or
maxversions=10"

המשך

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

import (
	"context"
	"fmt"
	"io"
	"time"

	admin "cloud.google.com/go/bigtable/admin/apiv2"
	"cloud.google.com/go/bigtable/admin/apiv2/adminpb"
	"google.golang.org/protobuf/types/known/durationpb"
)

func createFamilyGCNested(w io.Writer, projectID, instanceID string, tableName string) error {
	// projectID := "my-project-id"
	// instanceID := "my-instance-id"
	// tableName := "my-table-name"

	ctx := context.Background()

	adminClient, err := admin.NewBigtableTableAdminClient(ctx)
	if err != nil {
		return fmt.Errorf("admin.NewBigtableTableAdminClient: %w", err)
	}
	defer adminClient.Close()

	// Create a nested GC rule:
	// Drop cells that are either older than the 10 recent versions
	// OR
	// Drop cells that are older than a month AND older than the 2 recent versions
	maxAge := time.Hour * 24 * 5
	policy := &adminpb.GcRule{
		Rule: &adminpb.GcRule_Union_{
			Union: &adminpb.GcRule_Union{
				Rules: []*adminpb.GcRule{
					{
						Rule: &adminpb.GcRule_MaxNumVersions{
							MaxNumVersions: 10,
						},
					},
					{
						Rule: &adminpb.GcRule_Intersection_{
							Intersection: &adminpb.GcRule_Intersection{
								Rules: []*adminpb.GcRule{
									{
										Rule: &adminpb.GcRule_MaxNumVersions{
											MaxNumVersions: 2,
										},
									},
									{
										Rule: &adminpb.GcRule_MaxAge{
											MaxAge: durationpb.New(maxAge),
										},
									},
								},
							},
						},
					},
				},
			},
		},
	}

	columnFamilyName := "cf5"
	req := &adminpb.ModifyColumnFamiliesRequest{
		Name: fmt.Sprintf("projects/%s/instances/%s/tables/%s", projectID, instanceID, tableName),
		Modifications: []*adminpb.ModifyColumnFamiliesRequest_Modification{
			{
				Id: columnFamilyName,
				Mod: &adminpb.ModifyColumnFamiliesRequest_Modification_Create{
					Create: &adminpb.ColumnFamily{
						GcRule: policy,
					},
				},
			},
		},
	}
	if _, err := adminClient.ModifyColumnFamilies(ctx, req); err != nil {
		return fmt.Errorf("ModifyColumnFamilies(%s): %w", columnFamilyName, err)
	}

	fmt.Fprintf(w, "created column family %s with policy: %v\n", columnFamilyName, policy)
	return nil
}

Java

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

// Creates a nested GC rule:
// Drop cells that are either older than the 10 recent versions
// OR
// Drop cells that are older than a month AND older than the 2 recent versions
GcRule intersectionRule =
    GcRuleBuilder.intersection()
        .add(GcRuleBuilder.maxAge(Duration.ofDays(30)))
        .add(GcRuleBuilder.maxVersions(2))
        .build();
GcRule unionRule =
    GcRuleBuilder.union().add(intersectionRule).add(GcRuleBuilder.maxVersions(10)).build();

// Creates column family with given GC rule.
try {
  String tableName =
      "projects/" + projectId + "/instances/" + instanceId + "/tables/" + tableId;
  ModifyColumnFamiliesRequest request =
      ModifyColumnFamiliesRequest.newBuilder()
          .setName(tableName)
          .addModifications(
              ModifyColumnFamiliesRequest.Modification.newBuilder()
                  .setId(COLUMN_FAMILY_5)
                  .setCreate(ColumnFamily.newBuilder().setGcRule(unionRule)))
          .build();
  adminClient.modifyColumnFamilies(request);
  System.out.println("Created column family: " + COLUMN_FAMILY_5);
} catch (AlreadyExistsException e) {
  System.err.println(
      "Failed to create column family with rule, already exists: " + e.getMessage());
}

‫Python asyncio

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

from google.protobuf import duration_pb2

from google.cloud import bigtable_admin_v2

async with bigtable_admin_v2.BigtableTableAdminAsyncClient() as client:
    table_path = client.table_path(project_id, instance_id, table_id)

    print("Creating column family cf5 with a Nested GC rule...")
    # Create a column family with nested GC policies.
    # Create a nested GC rule:
    # Drop cells that are either older than the 10 recent versions
    # OR
    # Drop cells that are older than a month AND older than the
    # 2 recent versions
    rule1 = bigtable_admin_v2.GcRule(max_num_versions=10)
    rule2 = bigtable_admin_v2.GcRule(
        intersection=bigtable_admin_v2.GcRule.Intersection(
            rules=[
                bigtable_admin_v2.GcRule(
                    max_age=duration_pb2.Duration(seconds=30 * 86400)
                ),
                bigtable_admin_v2.GcRule(max_num_versions=2),
            ]
        )
    )
    nested_rule = bigtable_admin_v2.GcRule(
        union=bigtable_admin_v2.GcRule.Union(rules=[rule1, rule2])
    )
    cf5 = bigtable_admin_v2.ColumnFamily(gc_rule=nested_rule)
    mod5 = bigtable_admin_v2.ModifyColumnFamiliesRequest.Modification(
        id="cf5", create=cf5
    )
    await client.modify_column_families(name=table_path, modifications=[mod5])
    print("Created column family cf5 with a Nested GC rule.")

Python

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

from google.protobuf import duration_pb2

from google.cloud import bigtable_admin_v2

client = bigtable_admin_v2.BigtableTableAdminClient()
table_path = client.table_path(project_id, instance_id, table_id)

print("Creating column family cf5 with a Nested GC rule...")
# Create a column family with nested GC policies.
# Create a nested GC rule:
# Drop cells that are either older than the 10 recent versions
# OR
# Drop cells that are older than a month AND older than the
# 2 recent versions
rule1 = bigtable_admin_v2.GcRule(max_num_versions=10)
rule2 = bigtable_admin_v2.GcRule(
    intersection=bigtable_admin_v2.GcRule.Intersection(
        rules=[
            bigtable_admin_v2.GcRule(
                max_age=duration_pb2.Duration(seconds=30 * 86400)
            ),
            bigtable_admin_v2.GcRule(max_num_versions=2),
        ]
    )
)
nested_rule = bigtable_admin_v2.GcRule(
    union=bigtable_admin_v2.GcRule.Union(rules=[rule1, rule2])
)
cf5 = bigtable_admin_v2.ColumnFamily(gc_rule=nested_rule)
mod5 = bigtable_admin_v2.ModifyColumnFamiliesRequest.Modification(
    id="cf5", create=cf5
)
client.modify_column_families(name=table_path, modifications=[mod5])
print("Created column family cf5 with a Nested GC rule.")

C#‎

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

// Create a nested GC rule:
// Drop cells that are either older than the 10 recent versions
// OR
// Drop cells that are older than 5 days AND older than the 2 recent versions.
// Initialize request argument(s).
GcRule.Types.Intersection intersectionRule = new GcRule.Types.Intersection
{
    Rules =
    {
        new GcRule { MaxNumVersions = 2 },
        new GcRule { MaxAge = Duration.FromTimeSpan(TimeSpan.FromDays(5)) }
    }
};

GcRule.Types.Union nestedRule = new GcRule.Types.Union
{
    Rules =
    {
        new GcRule { MaxNumVersions = 10 },
        new GcRule { Intersection = intersectionRule }
    }
};

GcRule gcRule = new GcRule { Union = nestedRule };

// Column family to create
ColumnFamily columnFamily = new ColumnFamily { GcRule = gcRule };

TableName tableName = new TableName(projectId, instanceId, tableId);

// Modification to create column family
ModifyColumnFamiliesRequest.Types.Modification modification = new ModifyColumnFamiliesRequest.Types.Modification
{
    Create = columnFamily,
    Id = "cf5"
};

ModifyColumnFamiliesRequest request = new ModifyColumnFamiliesRequest
{
    TableName = tableName,
    Modifications = { modification }
};
try
{
    // Make the request
    Table response = bigtableTableAdminClient.ModifyColumnFamilies(request);
    Console.WriteLine("Created column family");
}
catch (Exception ex)
{
    Console.WriteLine($"Error creating column family {ex.Message}");
}

C++‎

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

namespace cbt = ::google::cloud::bigtable;
namespace cbta = ::google::cloud::bigtable_admin;
using ::google::bigtable::admin::v2::ModifyColumnFamiliesRequest;
using ::google::cloud::StatusOr;
[](cbta::BigtableTableAdminClient admin, std::string const& project_id,
   std::string const& instance_id, std::string const& table_id,
   std::string const& family_name) {
  std::string table_name = cbt::TableName(project_id, instance_id, table_id);
  auto constexpr kSecondsPerDay =
      std::chrono::seconds(std::chrono::hours(24)).count();

  ModifyColumnFamiliesRequest::Modification mod;
  mod.set_id(family_name);
  auto& gc = *mod.mutable_create()->mutable_gc_rule();
  auto& gc_1 = *gc.mutable_union_()->add_rules();
  auto& gc_2 = *gc.mutable_union_()->add_rules();
  auto& gc_2_1 = *gc_2.mutable_intersection()->add_rules();
  auto& gc_2_2 = *gc_2.mutable_intersection()->add_rules();

  gc_1.set_max_num_versions(10);
  gc_2_1.set_max_num_versions(1);
  gc_2_2.mutable_max_age()->set_seconds(5 * kSecondsPerDay);

  StatusOr<google::bigtable::admin::v2::Table> schema =
      admin.ModifyColumnFamilies(table_name, {std::move(mod)});

  if (!schema) throw std::move(schema).status();
  std::cout << "Schema modified to: " << schema->DebugString() << "\n";
}

Node.js

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

// Create a nested GC rule:
// Drop cells that are either older than the 10 recent versions
// OR
// Drop cells that are older than a month AND older than the 2 recent versions
const nestedRule = GcRuleBuilder.union(
  GcRuleBuilder.rule({
    maxVersions: 10,
  }),
  GcRuleBuilder.intersection(
    GcRuleBuilder.rule({
      maxVersions: 2,
    }),
    GcRuleBuilder.rule({
      maxAge: {
        // one month
        seconds: 60 * 60 * 24 * 30,
        nanos: 0,
      },
    }),
  ),
);

[family] = await adminClient.modifyColumnFamilies({
  name: table.name,
  modifications: [
    {
      id: 'cf5',
      create: {
        gcRule: nestedRule,
      },
    },
  ],
});
console.log(`Created column family ${family.name}`);

PHP

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

use Google\Cloud\Bigtable\Admin\V2\Client\BigtableTableAdminClient;
use Google\Cloud\Bigtable\Admin\V2\ColumnFamily;
use Google\Cloud\Bigtable\Admin\V2\GcRule;
use Google\Cloud\Bigtable\Admin\V2\GcRule\Intersection as GcRuleIntersection;
use Google\Cloud\Bigtable\Admin\V2\GcRule\Union as GcRuleUnion;
use Google\Cloud\Bigtable\Admin\V2\ModifyColumnFamiliesRequest;
use Google\Cloud\Bigtable\Admin\V2\ModifyColumnFamiliesRequest\Modification;
use Google\Protobuf\Duration;

/**
 * Create a new column family with a nested GC rule
 *
 * @param string $projectId The Google Cloud project ID
 * @param string $instanceId The ID of the Bigtable instance where the table resides
 * @param string $tableId The ID of the table in which the rule needs to be created
 */
function create_family_gc_nested(
    string $projectId,
    string $instanceId,
    string $tableId
): void {
    $tableAdminClient = new BigtableTableAdminClient();

    $tableName = $tableAdminClient->tableName($projectId, $instanceId, $tableId);

    print('Creating column family cf5 with a Nested GC rule...' . PHP_EOL);
    // Create a column family with nested GC policies.
    // Create a nested GC rule:
    // Drop cells that are either older than the 10 recent versions
    // OR
    // Drop cells that are older than a month AND older than the
    // 2 recent versions
    $columnFamily5 = new ColumnFamily();
    $rule1 = (new GcRule())->setMaxNumVersions(10);

    $rule2Intersection = new GcRuleIntersection();
    $rule2Duration1 = new Duration();
    $rule2Duration1->setSeconds(3600 * 24 * 30);
    $rule2Array = [
        (new GcRule())->setMaxAge($rule2Duration1),
        (new GcRule())->setMaxNumVersions(2)
    ];
    $rule2Intersection->setRules($rule2Array);
    $rule2 = new GcRule();
    $rule2->setIntersection($rule2Intersection);

    $nestedRule = new GcRuleUnion();
    $nestedRule->setRules([
        $rule1,
        $rule2
    ]);
    $nestedRule = (new GcRule())->setUnion($nestedRule);

    $columnFamily5->setGCRule($nestedRule);

    $columnModification = new Modification();
    $columnModification->setId('cf5');
    $columnModification->setCreate($columnFamily5);
    $modifyColumnFamiliesRequest = (new ModifyColumnFamiliesRequest())
        ->setName($tableName)
        ->setModifications([$columnModification]);
    $tableAdminClient->modifyColumnFamilies($modifyColumnFamiliesRequest);

    print('Created column family cf5 with a Nested GC rule.' . PHP_EOL);
}

Ruby

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

# Create a nested GC rule:
# Drop cells that are either older than the 10 recent versions
# OR
# Drop cells that are older than a month AND older than the 2 recent versions
max_versions_rule1 = Google::Cloud::Bigtable::GcRule.max_versions 10
max_age_rule = Google::Cloud::Bigtable::GcRule.max_age 60 * 60 * 24 * 5
max_versions_rule2 = Google::Cloud::Bigtable::GcRule.max_versions 2
intersection_gc_rule = Google::Cloud::Bigtable::GcRule.intersection max_age_rule, max_versions_rule2
nested_gc_rule = Google::Cloud::Bigtable::GcRule.union max_versions_rule1, intersection_gc_rule

עדכון מדיניות איסוף האשפה

בקטע הבא מוסבר איך לשנות מדיניות קיימת של איסוף אשפה.

כדי להאריך את תקופת השמירה של קבוצת עמודות בטבלה שמשתמשת ברפליקציה, צריך לאשר אזהרה לגבי האפשרות שהאשכולות לא יהיו מסונכרנים. הערך החדש יכול להיות גדול ב-90 ימים לכל היותר מהערך הנוכחי. פרטים נוספים מופיעים במאמר שינוי כללי מדיניות שמבוססים על גיל.

המסוף

כדי לעדכן את מדיניות איסוף האשפה של קבוצת עמודות, פועלים לפי השלבים הבאים.

  1. במסוף Cloud de Confiance , פותחים את רשימת המכונות של Bigtable.

    פתיחת רשימת המכונות

  2. לוחצים על המכונה שרוצים לראות את הטבלאות שלה.

  3. בחלונית הימנית, לוחצים על Tables.

    בדף Tables מוצגת רשימת הטבלאות במכונה.

  4. לוחצים על עריכה בשורה של הטבלה.

  5. לוחצים על Open ליד קבוצת העמודות שרוצים לערוך.

  6. מגדירים את המדיניות.

  7. לוחצים על Save.

cbt

cbt setgcpolicy your-table cf1 maxage=1d

אם מגדילים את הערך של maxage בטבלה משוכפלת, צריך להשתמש בדגל האופציונלי force. הערך החדש יכול להיות גדול ב-90 ימים לכל היותר מהערך הנוכחי.

Java

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

// Updates the column family metadata to update the GC rule.
// Updates a column family GC rule.
GcRule versionRule = GcRuleBuilder.maxVersions(1);
try {
  String tableName =
      "projects/" + projectId + "/instances/" + instanceId + "/tables/" + tableId;
  ModifyColumnFamiliesRequest request =
      ModifyColumnFamiliesRequest.newBuilder()
          .setName(tableName)
          .addModifications(
              ModifyColumnFamiliesRequest.Modification.newBuilder()
                  .setId(COLUMN_FAMILY_1)
                  .setUpdate(ColumnFamily.newBuilder().setGcRule(versionRule)))
          .build();
  adminClient.modifyColumnFamilies(request);
  System.out.printf("Column family %s GC rule updated%n", COLUMN_FAMILY_1);
} catch (NotFoundException e) {
  System.err.println("Failed to modify a non-existent column family: " + e.getMessage());
}

‫Python asyncio

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

from google.cloud import bigtable_admin_v2

async with bigtable_admin_v2.BigtableTableAdminAsyncClient() as client:
    table_path = client.table_path(project_id, instance_id, table_id)

    print("Updating column family cf1 GC rule...")
    # Update the column family cf1 to update the GC rule
    updated_cf1 = bigtable_admin_v2.ColumnFamily(
        gc_rule=bigtable_admin_v2.GcRule(max_num_versions=1)
    )
    mod_update = bigtable_admin_v2.ModifyColumnFamiliesRequest.Modification(
        id="cf1", update=updated_cf1
    )
    await client.modify_column_families(
        name=table_path, modifications=[mod_update]
    )
    print("Updated column family cf1 GC rule\n")

Python

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

from google.cloud import bigtable_admin_v2

client = bigtable_admin_v2.BigtableTableAdminClient()
table_path = client.table_path(project_id, instance_id, table_id)

print("Updating column family cf1 GC rule...")
# Update the column family cf1 to update the GC rule
updated_cf1 = bigtable_admin_v2.ColumnFamily(
    gc_rule=bigtable_admin_v2.GcRule(max_num_versions=1)
)
mod_update = bigtable_admin_v2.ModifyColumnFamiliesRequest.Modification(
    id="cf1", update=updated_cf1
)
client.modify_column_families(name=table_path, modifications=[mod_update])
print("Updated column family cf1 GC rule\n")

C#‎

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

// Update the column family metadata to update the GC rule.
// Initialize request argument(s).
// Updated column family GC rule.
GcRule maxVersionsRule = new GcRule { MaxNumVersions = 1 };

// Column family to create
ColumnFamily columnFamily = new ColumnFamily { GcRule = maxVersionsRule };

TableName tableName = new TableName(projectId, instanceId, tableId);

// Modification to update column family
ModifyColumnFamiliesRequest.Types.Modification modification = new ModifyColumnFamiliesRequest.Types.Modification
{
    Update = columnFamily,
    Id = "cf1"
};

ModifyColumnFamiliesRequest request = new ModifyColumnFamiliesRequest
{
    TableName = tableName,
    Modifications = { modification }
};
try
{
    // Make the request
    Table response = bigtableTableAdminClient.ModifyColumnFamilies(request);
    Console.WriteLine("Updated column family");
}
catch (Exception ex)
{
    Console.WriteLine($"Error updating column family {ex.Message}");
}

C++‎

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

namespace cbt = ::google::cloud::bigtable;
namespace cbta = ::google::cloud::bigtable_admin;
using ::google::bigtable::admin::v2::ModifyColumnFamiliesRequest;
using ::google::cloud::StatusOr;
[](cbta::BigtableTableAdminClient admin, std::string const& project_id,
   std::string const& instance_id, std::string const& table_id,
   std::string const& family_name) {
  std::string table_name = cbt::TableName(project_id, instance_id, table_id);

  ModifyColumnFamiliesRequest::Modification mod;
  mod.set_id(family_name);
  mod.mutable_update()->mutable_gc_rule()->set_max_num_versions(1);

  StatusOr<google::bigtable::admin::v2::Table> schema =
      admin.ModifyColumnFamilies(table_name, {std::move(mod)});

  if (!schema) throw std::move(schema).status();
  std::cout << "Schema modified to: " << schema->DebugString() << "\n";
}

Node.js

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

// Update the column family metadata to update the GC rule

// Update a column family GC rule
const updatedMetadata = GcRuleBuilder.rule({
  maxNumVersions: 1,
});

const [apiResponse] = await adminClient.modifyColumnFamilies({
  name: table.name,
  modifications: [
    {
      id: 'cf1',
      update: {
        gcRule: updatedMetadata,
      },
    },
  ],
});
console.log(`Updated GC rule: ${JSON.stringify(apiResponse)}`);

PHP

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

use Google\ApiCore\ApiException;
use Google\Cloud\Bigtable\Admin\V2\Client\BigtableTableAdminClient;
use Google\Cloud\Bigtable\Admin\V2\ColumnFamily;
use Google\Cloud\Bigtable\Admin\V2\GcRule;
use Google\Cloud\Bigtable\Admin\V2\ModifyColumnFamiliesRequest;
use Google\Cloud\Bigtable\Admin\V2\ModifyColumnFamiliesRequest\Modification;

/**
 * Update the GC Rule for an existing column family in the table
 *
 * @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 where the rule needs to be updated
 * @param string $familyId The ID of the column family
 */
function update_gc_rule(
    string $projectId,
    string $instanceId,
    string $tableId,
    string $familyId = 'cf3'
): void {
    $tableAdminClient = new BigtableTableAdminClient();
    $tableName = $tableAdminClient->tableName($projectId, $instanceId, $tableId);
    $columnFamily1 = new ColumnFamily();

    printf('Updating column family %s GC rule...' . PHP_EOL, $familyId);
    $columnFamily1->setGcRule((new GcRule())->setMaxNumVersions(1));
    // Update the column family with ID $familyId to update the GC rule
    $columnModification = new Modification();
    $columnModification->setId($familyId);
    $columnModification->setUpdate($columnFamily1);

    try {
        $modifyColumnFamiliesRequest = (new ModifyColumnFamiliesRequest())
            ->setName($tableName)
            ->setModifications([$columnModification]);
        $tableAdminClient->modifyColumnFamilies($modifyColumnFamiliesRequest);
    } catch (ApiException $e) {
        if ($e->getStatus() === 'NOT_FOUND') {
            printf('Column family %s does not exist.' . PHP_EOL, $familyId);
            return;
        }
        throw $e;
    }

    printf('Print column family %s GC rule after update...' . PHP_EOL, $familyId);
    printf('Column Family: ' . $familyId . PHP_EOL);
    printf('%s' . PHP_EOL, $columnFamily1->serializeToJsonString());
}

Ruby

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לספריות לקוח.

לפני שמריצים דוגמאות קוד, צריך להגדיר את משתנה הסביבה GOOGLE_CLOUD_UNIVERSE_DOMAIN לערך s3nsapis.fr.

gc_rule = Google::Cloud::Bigtable::GcRule.max_versions 1
column_families = table.column_families do |cfs|
  cfs.update "cf1", gc_rule: gc_rule
end
p column_families["cf1"]

המאמרים הבאים