diff --git a/pkg/internal/util/strings.go b/pkg/internal/util/strings.go index 0b5021ea51..2e8aadf014 100644 --- a/pkg/internal/util/strings.go +++ b/pkg/internal/util/strings.go @@ -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 { diff --git a/pkg/resources/helpers.go b/pkg/resources/helpers.go index 70a0c386ce..1b3f94f8da 100644 --- a/pkg/resources/helpers.go +++ b/pkg/resources/helpers.go @@ -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 { diff --git a/pkg/sdk/data_types.go b/pkg/sdk/data_types.go index cae4f322f7..011e6340fd 100644 --- a/pkg/sdk/data_types.go +++ b/pkg/sdk/data_types.go @@ -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) @@ -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)