Skip to content

Commit

Permalink
fix: misc linting changes for 0.56.2 (#1509)
Browse files Browse the repository at this point in the history
* fix: tag-associations formatting

* fix: tag-associations formatting

* fix: tag-associations formatting
  • Loading branch information
sfc-gh-swinkler authored Feb 1, 2023
1 parent 3787657 commit e0d1ef5
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions pkg/snowflake/tag_association.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,11 @@ func (tb *TagAssociationBuilder) GetTagSchema() string {
func (tb *TagAssociationBuilder) GetTableAndColumnName() (string, string) {
if strings.ToUpper(tb.objectType) != "COLUMN" {
return tb.objectIdentifier, ""
} else {
splObjIdentifier := strings.Split(tb.objectIdentifier, ".")
tableName := strings.ReplaceAll(splObjIdentifier[2], "\"", "")
columnName := strings.ReplaceAll(splObjIdentifier[3], "\"", "")
return fmt.Sprintf(`"%s"."%s"."%s"`, tb.databaseName, tb.schemaName, tableName), columnName
}
splObjIdentifier := strings.Split(tb.objectIdentifier, ".")
tableName := strings.ReplaceAll(splObjIdentifier[2], "\"", "")
columnName := strings.ReplaceAll(splObjIdentifier[3], "\"", "")
return fmt.Sprintf(`"%s"."%s"."%s"`, tb.databaseName, tb.schemaName, tableName), columnName
}

// TagAssociation returns a pointer to a Builder that abstracts the DDL operations for a tag sssociation.
Expand All @@ -91,19 +90,17 @@ 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))
} else {
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))
}
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))
}

// Drop returns the SQL query that will remove a tag from an object.
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)
} else {
return fmt.Sprintf(`ALTER %v %v UNSET TAG "%v"."%v"."%v"`, tb.objectType, tb.objectIdentifier, 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)
}

// Show returns the SQL query that will show the current tag value on an object.
Expand All @@ -112,9 +109,8 @@ func (tb *TagAssociationBuilder) Show() string {
fqTableName, columnName := tb.GetTableAndColumnName()
fqColumnName := fmt.Sprintf(`%v."%v"`, fqTableName, columnName)
return fmt.Sprintf(`SELECT SYSTEM$GET_TAG('"%v"."%v"."%v"', '%v', '%v') TAG_VALUE WHERE TAG_VALUE IS NOT NULL`, tb.databaseName, tb.schemaName, tb.tagName, fqColumnName, tb.objectType)
} else {
return fmt.Sprintf(`SELECT SYSTEM$GET_TAG('"%v"."%v"."%v"', '%v', '%v') TAG_VALUE WHERE TAG_VALUE IS NOT NULL`, tb.databaseName, tb.schemaName, tb.tagName, tb.objectIdentifier, tb.objectType)
}
return fmt.Sprintf(`SELECT SYSTEM$GET_TAG('"%v"."%v"."%v"', '%v', '%v') TAG_VALUE WHERE TAG_VALUE IS NOT NULL`, tb.databaseName, tb.schemaName, tb.tagName, tb.objectIdentifier, tb.objectType)
}

func ScanTagAssociation(row *sqlx.Row) (*TagAssociation, error) {
Expand Down

0 comments on commit e0d1ef5

Please sign in to comment.