Skip to content

Commit f0df2ab

Browse files
sfc-gh-sarurshreyassfc-gh-jmichalakgraphite-app[bot]
authored
feat: add semantic view resource - 1 (#4029)
Add a basic semantic view resource. - Add a schema for the required fields. - Do not enable the resource in the prod provider yet, as we expect a few more PRs before this resource is usable, and we don't want to block the releases. Do not enable the resource in the test provider yet, as it can't be created in its current form. It requires either the metrics or dimensions block, which will be implemented next. - Fix a typo in the Makefile. ## TODO - Add the other supported fields & add this resource to the test provider. - Handle external changes. - Handle object renaming. - Handle copy grants. - Write more acceptance tests. - Provide examples. - Add an entry to the migration guide. - Add a data source. - Extract common code, especially for block handling. --------- Co-authored-by: shreyas <[email protected]> Co-authored-by: Jakub Michalak <[email protected]> Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
1 parent 84568f0 commit f0df2ab

File tree

16 files changed

+1239
-4
lines changed

16 files changed

+1239
-4
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ generate-all-config-model-builders: generate-resource-model-builders generate-da
200200
generate-all-config-model-builders-check: clean-all-config-model-builders generate-all-config-model-builders ## check that generated config model builders are up-to-date
201201
git diff --exit-code -- pkg/acceptance/bettertestspoc/config/model
202202
git diff --exit-code -- pkg/acceptance/bettertestspoc/config/datasourcemodel
203-
git diff --exit-code -- pkg/acceptance/bettertestspoc/config/providelmodel
203+
git diff --exit-code -- pkg/acceptance/bettertestspoc/config/providermodel
204204

205205
clean-all-assertions-and-config-models: clean-snowflake-object-assertions clean-snowflake-object-parameters-assertions clean-resource-assertions clean-resource-parameters-assertions clean-resource-show-output-assertions clean-resource-model-builders clean-provider-model-builders clean-datasource-model-builders ## clean all generated assertions and config models
206206

pkg/acceptance/bettertestspoc/assert/objectassert/semantic_view_snowflake_gen.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/acceptance/bettertestspoc/assert/resourceassert/gen/resource_schema_def.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ var allResourceSchemaDefs = []ResourceSchemaDef{
206206
name: "SecretWithGenericString",
207207
schema: resources.SecretWithGenericString().Schema,
208208
},
209+
{
210+
name: "SemanticView",
211+
schema: resources.SemanticView().Schema,
212+
},
209213
{
210214
name: "Service",
211215
schema: resources.Service().Schema,

pkg/acceptance/bettertestspoc/assert/resourceassert/semantic_view_resource_gen.go

Lines changed: 135 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package resourceshowoutputassert
2+
3+
import (
4+
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/bettertestspoc/assert"
5+
)
6+
7+
func (c *SemanticViewShowOutputAssert) HasCreatedOnNotEmpty() *SemanticViewShowOutputAssert {
8+
c.AddAssertion(assert.ResourceShowOutputValuePresent("created_on"))
9+
return c
10+
}

pkg/acceptance/bettertestspoc/assert/resourceshowoutputassert/semantic_view_show_output_gen.go

Lines changed: 122 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package model
2+
3+
import (
4+
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
5+
tfconfig "github.com/hashicorp/terraform-plugin-testing/config"
6+
)
7+
8+
func (s *SemanticViewModel) WithTables(tables []sdk.LogicalTable) *SemanticViewModel {
9+
maps := make([]tfconfig.Variable, len(tables))
10+
for i, v := range tables {
11+
m := map[string]tfconfig.Variable{
12+
"table_name": tfconfig.StringVariable(v.TableName.FullyQualifiedName()),
13+
}
14+
if v.Comment != nil {
15+
m["comment"] = tfconfig.StringVariable(*v.Comment)
16+
}
17+
logicalTableAlias := v.GetLogicalTableAlias()
18+
if logicalTableAlias != nil {
19+
m["table_alias"] = tfconfig.StringVariable(logicalTableAlias.LogicalTableAlias)
20+
}
21+
primaryKeys := v.GetPrimaryKeys()
22+
if primaryKeys != nil {
23+
keys := make([]tfconfig.Variable, len(primaryKeys.PrimaryKey))
24+
for j, key := range primaryKeys.PrimaryKey {
25+
keys[j] = tfconfig.StringVariable(key.Name)
26+
}
27+
m["primary_key"] = tfconfig.ListVariable(keys...)
28+
}
29+
uniqueKeys := v.GetUniqueKeys()
30+
if uniqueKeys != nil {
31+
keys := make([]tfconfig.Variable, len(uniqueKeys))
32+
for j, key := range uniqueKeys {
33+
uniKeys := make([]tfconfig.Variable, len(key.Unique))
34+
for k, uniKey := range key.Unique {
35+
uniKeys[k] = tfconfig.StringVariable(uniKey.Name)
36+
}
37+
keys[j] = tfconfig.ObjectVariable(map[string]tfconfig.Variable{
38+
"values": tfconfig.ListVariable(uniKeys...),
39+
})
40+
}
41+
m["unique"] = tfconfig.ListVariable(keys...)
42+
}
43+
synonyms := v.GetSynonyms()
44+
if synonyms != nil {
45+
syns := make([]tfconfig.Variable, len(synonyms.WithSynonyms))
46+
for j, synonym := range synonyms.WithSynonyms {
47+
syns[j] = tfconfig.StringVariable(synonym.Synonym)
48+
}
49+
m["synonym"] = tfconfig.SetVariable(syns...)
50+
}
51+
maps[i] = tfconfig.ObjectVariable(m)
52+
}
53+
s.Tables = tfconfig.ListVariable(maps...)
54+
return s
55+
}
56+
57+
func LogicalTableWithProps(
58+
alias string,
59+
tableName sdk.SchemaObjectIdentifier,
60+
primaryKeys []sdk.SemanticViewColumn,
61+
uniqueKeys [][]sdk.SemanticViewColumn,
62+
synonyms []sdk.Synonym,
63+
comment string,
64+
) *sdk.LogicalTable {
65+
table := &sdk.LogicalTable{
66+
TableName: tableName,
67+
Comment: &comment,
68+
}
69+
if alias != "" {
70+
table.SetLogicalTableAlias(alias)
71+
}
72+
if primaryKeys != nil {
73+
table.SetPrimaryKeys(primaryKeys)
74+
}
75+
if uniqueKeys != nil {
76+
table.SetUniqueKeys(uniqueKeys)
77+
}
78+
if synonyms != nil {
79+
table.SetSynonyms(synonyms)
80+
}
81+
return table
82+
}

0 commit comments

Comments
 (0)