Skip to content

Commit

Permalink
fix: Adding double quotes to the column names (#1729)
Browse files Browse the repository at this point in the history
* adding quotes to the column name

* modifying the tests

---------

Co-authored-by: sfc-gh-kmaurya <[email protected]>
  • Loading branch information
sfc-gh-kumaurya and sfc-gh-kumaurya authored Apr 18, 2023
1 parent 66d88bd commit 791dd0b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pkg/snowflake/tag_association.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func NewTagAssociationBuilder(tagID string) *TagAssociationBuilder {
func (tb *TagAssociationBuilder) Create() string {
if strings.ToUpper(tb.objectType) == "COLUMN" {
tableName, columnName := tb.GetTableAndColumnName()
return fmt.Sprintf(`ALTER TABLE %v MODIFY COLUMN %v SET TAG "%v"."%v"."%v" = '%v'`, tableName, columnName, tb.databaseName, tb.schemaName, tb.tagName, EscapeString(tb.tagValue))
return fmt.Sprintf(`ALTER TABLE %v MODIFY COLUMN "%v" SET TAG "%v"."%v"."%v" = '%v'`, tableName, columnName, tb.databaseName, tb.schemaName, tb.tagName, EscapeString(tb.tagValue))
}
return fmt.Sprintf(`ALTER %v %v SET TAG "%v"."%v"."%v" = '%v'`, tb.objectType, tb.objectIdentifier, tb.databaseName, tb.schemaName, tb.tagName, EscapeString(tb.tagValue))
}
Expand All @@ -98,7 +98,7 @@ func (tb *TagAssociationBuilder) Create() string {
func (tb *TagAssociationBuilder) Drop() string {
if strings.ToUpper(tb.objectType) == "COLUMN" {
tableName, columnName := tb.GetTableAndColumnName()
return fmt.Sprintf(`ALTER TABLE %v MODIFY COLUMN %v UNSET TAG "%v"."%v"."%v"`, tableName, columnName, tb.databaseName, tb.schemaName, tb.tagName)
return fmt.Sprintf(`ALTER TABLE %v MODIFY COLUMN "%v" UNSET TAG "%v"."%v"."%v"`, tableName, columnName, tb.databaseName, tb.schemaName, tb.tagName)
}
return fmt.Sprintf(`ALTER %v %v UNSET TAG "%v"."%v"."%v"`, tb.objectType, tb.objectIdentifier, tb.databaseName, tb.schemaName, tb.tagName)
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/snowflake/tag_association_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ func TestTagAssociation(t *testing.T) {
},
{
Builder: NewTagAssociationBuilder("test_db|test_schema|sensitive").WithObjectIdentifier(`"test_db"."test_schema"."test_table.important"`).WithObjectType("COLUMN").WithTagValue("true"),
ExpectedCreate: `ALTER TABLE "test_db"."test_schema"."test_table" MODIFY COLUMN important SET TAG "test_db"."test_schema"."sensitive" = 'true'`,
ExpectedDrop: `ALTER TABLE "test_db"."test_schema"."test_table" MODIFY COLUMN important UNSET TAG "test_db"."test_schema"."sensitive"`,
ExpectedCreate: `ALTER TABLE "test_db"."test_schema"."test_table" MODIFY COLUMN "important" SET TAG "test_db"."test_schema"."sensitive" = 'true'`,
ExpectedDrop: `ALTER TABLE "test_db"."test_schema"."test_table" MODIFY COLUMN "important" UNSET TAG "test_db"."test_schema"."sensitive"`,
ExpectedShow: `SELECT SYSTEM$GET_TAG('"test_db"."test_schema"."sensitive"', '"test_db"."test_schema"."test_table"."important"', 'COLUMN') TAG_VALUE WHERE TAG_VALUE IS NOT NULL`,
},
{
Builder: NewTagAssociationBuilder("OPERATION_DB|SECURITY|PII_2").WithObjectIdentifier(`"OPERATION_DB"."SECURITY"."test_table.important"`).WithObjectType("COLUMN").WithTagValue("true"),
ExpectedCreate: `ALTER TABLE "OPERATION_DB"."SECURITY"."test_table" MODIFY COLUMN important SET TAG "OPERATION_DB"."SECURITY"."PII_2" = 'true'`,
ExpectedDrop: `ALTER TABLE "OPERATION_DB"."SECURITY"."test_table" MODIFY COLUMN important UNSET TAG "OPERATION_DB"."SECURITY"."PII_2"`,
ExpectedCreate: `ALTER TABLE "OPERATION_DB"."SECURITY"."test_table" MODIFY COLUMN "important" SET TAG "OPERATION_DB"."SECURITY"."PII_2" = 'true'`,
ExpectedDrop: `ALTER TABLE "OPERATION_DB"."SECURITY"."test_table" MODIFY COLUMN "important" UNSET TAG "OPERATION_DB"."SECURITY"."PII_2"`,
ExpectedShow: `SELECT SYSTEM$GET_TAG('"OPERATION_DB"."SECURITY"."PII_2"', '"OPERATION_DB"."SECURITY"."test_table"."important"', 'COLUMN') TAG_VALUE WHERE TAG_VALUE IS NOT NULL`,
},
}
Expand Down

0 comments on commit 791dd0b

Please sign in to comment.