Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] type issue in databricks_sql_table #4422

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions catalog/resource_sql_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,10 +540,11 @@ var columnTypeAliases = map[string]string{

func getColumnType(columnType string) string {
caseInsensitiveColumnType := strings.ToLower(columnType)
if alias, ok := columnTypeAliases[caseInsensitiveColumnType]; ok {
normalizedColumnType := strings.Split(caseInsensitiveColumnType, " ")[0]
alexott marked this conversation as resolved.
Show resolved Hide resolved
if alias, ok := columnTypeAliases[normalizedColumnType]; ok {
return alias
}
return caseInsensitiveColumnType
return normalizedColumnType
Comment on lines -546 to +551
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this change, need to think how changes like decimal(12, 2) -> decimal(12,2) will affect the plan/apply and then read operations

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, let me know what you think the best approach is and I'm happy to implement.

}

func assertNoColumnTypeDiff(oldCols []interface{}, newColumnInfos []SqlColumnInfo) error {
Expand Down
13 changes: 13 additions & 0 deletions internal/acceptance/sql_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,19 @@ func TestUcAccResourceSqlTable_ChangeColumnTypeThrows(t *testing.T) {
})
}

func TestUcAccResourceSqlTable_ChangeColumnTypeWithMultipleWords(t *testing.T) {
if os.Getenv("GOOGLE_CREDENTIALS") != "" {
Skipf(t)("databricks_sql_table resource not available on GCP")
}
tableName := RandomName()

UnityWorkspaceLevel(t, Step{
Template: constructManagedSqlTableTemplate(tableName, []catalog.SqlColumnInfo{{Name: "name", Type: "TIMESTAMP DEFAULT current_timestamp()", Nullable: true, Comment: "comment"}}),
}, Step{
Template: constructManagedSqlTableTemplate(tableName, []catalog.SqlColumnInfo{{Name: "name", Type: "timestamp", Nullable: true, Comment: "comment"}}),
})
}

func TestUcAccResourceSqlTable_DropColumn(t *testing.T) {
if os.Getenv("GOOGLE_CREDENTIALS") != "" {
Skipf(t)("databricks_sql_table resource not available on GCP")
Expand Down