public void addFamilyWithIntersectionRule ( ) { System . out . printf ( "%nCreating column family %s with intersection GC rule%n" , COLUMN_FAMILY_4 ) ; // [START bigtable_create_family_gc_intersection] // 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. DurationRule maxAgeRule = GCRULES . maxAge ( 5 , TimeUnit . DAYS ) ; VersionRule versionRule = GCRULES . maxVersions ( 2 ) ; IntersectionRule intersectionRule = GCRULES . intersection ( ) . rule ( maxAgeRule ) . rule ( versionRule ) ; // 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_4 , intersectionRule ) ; adminClient . modifyFamilies ( columnFamiliesRequest ) ; 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 ( ) ) ; } // [END bigtable_create_family_gc_intersection] }
Demonstrates how to create a new instance of the IntersectionRule .