@@ -62,6 +62,8 @@ type Exclude struct {
6262 Datasets []string `json:"datasets" yaml:"datasets" mapstructure:"datasets"`
6363 // list of tableNames in format - datasetID.tableID
6464 Tables []string `json:"tables" yaml:"tables" mapstructure:"tables"`
65+ // list of label key-value pairs; tables matching any label are excluded
66+ Labels map [string ]string `json:"labels" yaml:"labels" mapstructure:"labels"`
6567}
6668
6769const (
@@ -83,6 +85,8 @@ exclude:
8385 - dataset_b
8486 tables:
8587 - dataset_c.table_a
88+ labels:
89+ env: staging
8690max_page_size: 100
8791include_column_profile: true
8892build_view_lineage: true
@@ -334,6 +338,14 @@ func (e *Extractor) extractTable(ctx context.Context, ds *bigquery.Dataset, emit
334338 e .logger .Error ("failed to fetch table metadata" , "err" , err , "table" , tableFQN )
335339 return nil
336340 }
341+ if IsExcludedByLabels (tmd .Labels , e .config .Exclude .Labels ) {
342+ e .excludedTableCtr .Add (ctx , 1 , metric .WithAttributes (
343+ attribute .String ("bq.project_id" , e .config .ProjectID ),
344+ attribute .String ("bq.dataset_id" , ds .DatasetID ),
345+ ))
346+ e .logger .Debug ("excluding table by labels" , "dataset_id" , ds .DatasetID , "table_id" , table .TableID )
347+ return nil
348+ }
337349 record , err := e .buildRecord (ctx , table , tmd )
338350 if err != nil {
339351 e .logger .Error ("failed to build record" , "err" , err , "table" , tableFQN )
@@ -799,6 +811,21 @@ func IsExcludedTable(datasetID, tableID string, excludedTables []string) bool {
799811 return false
800812}
801813
814+ // isExcludedByLabels returns true if the table's labels match any of the
815+ // configured exclude labels. A match means the table has the same key with
816+ // the same value.
817+ func IsExcludedByLabels (tableLabels , excludeLabels map [string ]string ) bool {
818+ if len (excludeLabels ) == 0 {
819+ return false
820+ }
821+ for k , v := range excludeLabels {
822+ if tableLabels [k ] == v {
823+ return true
824+ }
825+ }
826+ return false
827+ }
828+
802829// getMaxPageSize returns max_page_size if configured in recipe, otherwise returns default value
803830func (e * Extractor ) getMaxPageSize () int {
804831 if e .config .MaxPageSize > 0 {
0 commit comments