Skip to content

Commit

Permalink
Add function descriptions
Browse files Browse the repository at this point in the history
References: #3007
  • Loading branch information
sfc-gh-asawicki committed Aug 28, 2024
1 parent 20d51cf commit 0989f3d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/internal/util/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package util

import "strings"

// TrimAllPrefixes removes all prefixes from the input. Order matters.
func TrimAllPrefixes(text string, prefixes ...string) string {
result := text
for _, prefix := range prefixes {
Expand Down
4 changes: 4 additions & 0 deletions pkg/resources/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ func dataTypeDiffSuppressFunc(_, old, new string, _ *schema.ResourceData) bool {
return oldDT == newDT
}

// DataTypeIssue3007DiffSuppressFunc is a temporary solution to handle data type suppression problems.
// Currently, it handles only number and text data types.
// It falls back to Snowflake defaults for arguments if no arguments were provided for the data type.
// TODO [SNOW-1348103 or SNOW-1348106]: visit with functions and procedures rework
func DataTypeIssue3007DiffSuppressFunc(_, old, new string, _ *schema.ResourceData) bool {
oldDataType, err := sdk.ToDataType(old)
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions pkg/sdk/data_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ func IsStringType(_type string) bool {
strings.HasPrefix(t, "NCHAR")
}

// ParseNumberDataTypeRaw extracts precision and scale from the raw number data type input.
// It returns defaults if it can't parse arguments, data type is different, or no arguments were provided.
// TODO [SNOW-1348103 or SNOW-1348106]: visit with functions and procedures rework
func ParseNumberDataTypeRaw(rawDataType string) (int, int) {
r := util.TrimAllPrefixes(strings.TrimSpace(strings.ToUpper(rawDataType)), DataTypeNumberSynonyms...)
r = strings.TrimSpace(r)
Expand Down Expand Up @@ -144,6 +147,9 @@ func ParseNumberDataTypeRaw(rawDataType string) (int, int) {
return DefaultNumberPrecision, DefaultNumberScale
}

// ParseVarcharDataTypeRaw extracts length from the raw text data type input.
// It returns default if it can't parse arguments, data type is different, or no length argument was provided.
// TODO [SNOW-1348103 or SNOW-1348106]: visit with functions and procedures rework
func ParseVarcharDataTypeRaw(rawDataType string) int {
r := util.TrimAllPrefixes(strings.TrimSpace(strings.ToUpper(rawDataType)), DataTypeVarcharSynonyms...)
r = strings.TrimSpace(r)
Expand Down

0 comments on commit 0989f3d

Please sign in to comment.