Ejemplo n.º 1
0
        private static object CreateNestedFamily(string tableId)
        {
            // [START bigtable_create_bigtableTableAdminClient]
            BigtableTableAdminClient bigtableTableAdminClient = BigtableTableAdminClient.Create();

            // [END bigtable_create_bigtableTableAdminClient]

            Console.WriteLine("Creating column family cf5 with a nested GC rule...");
            // [START bigtable_create_family_gc_nested]
            // 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.
            // 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");
                // [END bigtable_create_family_gc_nested]
                // Print table information.
                GetTable(tableId);
                // [START bigtable_create_family_gc_nested]
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error creating column family {ex.Message}");
            }
            // [END bigtable_create_family_gc_nested]
            return(0);
        }
Ejemplo n.º 2
0
        private static object CreateUnionFamily(string tableId)
        {
            // [START bigtable_create_bigtableTableAdminClient]
            BigtableTableAdminClient bigtableTableAdminClient = BigtableTableAdminClient.Create();

            // [END bigtable_create_bigtableTableAdminClient]

            Console.WriteLine("Creating column family cf3 with union GC rule...");
            // [START bigtable_create_family_gc_union]
            // 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");
                // [END bigtable_create_family_gc_union]
                // Print table information.
                GetTable(tableId);
                // [START bigtable_create_family_gc_union]
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error creating column family {ex.Message}");
            }
            // [END bigtable_create_family_gc_union]
            return(0);
        }