public void addFamilyWithMaxAgeRule ( ) { System . out . printf ( "%nCreating column family %s with max age GC rule%n" , COLUMN_FAMILY_1 ) ; // [START bigtable_create_family_gc_max_age] // 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. DurationRule maxAgeRule = GCRULES . maxAge ( 5 , TimeUnit . DAYS ) ; // Creates column family with given GC rule. try { // ModifyColumnFamiliesRequest can be used both for adding and modifying families, here it is // being used to add a family ModifyColumnFamiliesRequest columnFamiliesRequest = ModifyColumnFamiliesRequest . of ( tableId ) . addFamily ( COLUMN_FAMILY_1 , maxAgeRule ) ; adminClient . modifyFamilies ( columnFamiliesRequest ) ; 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 ( ) ) ; } // [END bigtable_create_family_gc_max_age] }
Demonstrates how to create a new instance of the DurationRule .