public void addFamilyWithMaxVersionsRule ( ) { System . out . printf ( "%nCreating column family %s with max versions GC rule%n" , COLUMN_FAMILY_2 ) ; // [START bigtable_create_family_gc_max_versions] // 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. VersionRule versionRule = GCRULES . maxVersions ( 2 ) ; // 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_2 , versionRule ) ; adminClient . modifyFamilies ( columnFamiliesRequest ) ; 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 ( ) ) ; } // [END bigtable_create_family_gc_max_versions] }
Demonstrates how to create a new instance of the VersionRule .