Skip to content

add sqlAssertion rule #18559

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/11043.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
dataplex: added `sql_assertion` field to `google_dataplex_datascan` resource
```
63 changes: 63 additions & 0 deletions google/services/dataplex/resource_dataplex_datascan.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,21 @@ Only relevant if a minValue has been defined. Default = false.`,
},
},
},
"sql_assertion": {
Type: schema.TypeList,
Optional: true,
Description: `Table rule which evaluates whether any row matches invalid state.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"sql_statement": {
Type: schema.TypeString,
Required: true,
Description: `The SQL Statement.`,
},
},
},
},
"statistic_range_expectation": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -1223,6 +1238,7 @@ func flattenDataplexDatascanDataQualitySpecRules(v interface{}, d *schema.Resour
"statistic_range_expectation": flattenDataplexDatascanDataQualitySpecRulesStatisticRangeExpectation(original["statisticRangeExpectation"], d, config),
"row_condition_expectation": flattenDataplexDatascanDataQualitySpecRulesRowConditionExpectation(original["rowConditionExpectation"], d, config),
"table_condition_expectation": flattenDataplexDatascanDataQualitySpecRulesTableConditionExpectation(original["tableConditionExpectation"], d, config),
"sql_assertion": flattenDataplexDatascanDataQualitySpecRulesSqlAssertion(original["sqlAssertion"], d, config),
})
}
return transformed
Expand Down Expand Up @@ -1411,6 +1427,23 @@ func flattenDataplexDatascanDataQualitySpecRulesTableConditionExpectationSqlExpr
return v
}

func flattenDataplexDatascanDataQualitySpecRulesSqlAssertion(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return nil
}
original := v.(map[string]interface{})
if len(original) == 0 {
return nil
}
transformed := make(map[string]interface{})
transformed["sql_statement"] =
flattenDataplexDatascanDataQualitySpecRulesSqlAssertionSqlStatement(original["sqlStatement"], d, config)
return []interface{}{transformed}
}
func flattenDataplexDatascanDataQualitySpecRulesSqlAssertionSqlStatement(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenDataplexDatascanDataProfileSpec(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return nil
Expand Down Expand Up @@ -1854,6 +1887,13 @@ func expandDataplexDatascanDataQualitySpecRules(v interface{}, d tpgresource.Ter
transformed["tableConditionExpectation"] = transformedTableConditionExpectation
}

transformedSqlAssertion, err := expandDataplexDatascanDataQualitySpecRulesSqlAssertion(original["sql_assertion"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedSqlAssertion); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["sqlAssertion"] = transformedSqlAssertion
}

req = append(req, transformed)
}
return req, nil
Expand Down Expand Up @@ -2128,6 +2168,29 @@ func expandDataplexDatascanDataQualitySpecRulesTableConditionExpectationSqlExpre
return v, nil
}

func expandDataplexDatascanDataQualitySpecRulesSqlAssertion(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
return nil, nil
}
raw := l[0]
original := raw.(map[string]interface{})
transformed := make(map[string]interface{})

transformedSqlStatement, err := expandDataplexDatascanDataQualitySpecRulesSqlAssertionSqlStatement(original["sql_statement"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedSqlStatement); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["sqlStatement"] = transformedSqlStatement
}

return transformed, nil
}

func expandDataplexDatascanDataQualitySpecRulesSqlAssertionSqlStatement(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandDataplexDatascanDataProfileSpec(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,13 @@ resource "google_dataplex_datascan" "full_quality" {
sql_expression = "COUNT(*) > 0"
}
}

rules {
dimension = "VALIDITY"
sql_assertion {
sql_statement = "select * from bigquery-public-data.austin_bikeshare.bikeshare_stations where station_id is null"
}
}
}


Expand Down
18 changes: 18 additions & 0 deletions website/docs/r/dataplex_datascan.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,13 @@ resource "google_dataplex_datascan" "full_quality" {
sql_expression = "COUNT(*) > 0"
}
}

rules {
dimension = "VALIDITY"
sql_assertion {
sql_statement = "select * from bigquery-public-data.austin_bikeshare.bikeshare_stations where station_id is null"
}
}
}


Expand Down Expand Up @@ -450,6 +457,11 @@ The following arguments are supported:
Table rule which evaluates whether the provided expression is true.
Structure is [documented below](#nested_table_condition_expectation).

* `sql_assertion` -
(Optional)
Table rule which evaluates whether any row matches invalid state.
Structure is [documented below](#nested_sql_assertion).


<a name="nested_range_expectation"></a>The `range_expectation` block supports:

Expand Down Expand Up @@ -522,6 +534,12 @@ The following arguments are supported:
(Required)
The SQL expression.

<a name="nested_sql_assertion"></a>The `sql_assertion` block supports:

* `sql_statement` -
(Required)
The SQL Statement.

<a name="nested_data_profile_spec"></a>The `data_profile_spec` block supports:

* `sampling_percent` -
Expand Down