Skip to content

Commit

Permalink
fix partition_by error in external table (Snowflake-Labs#609)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarusun authored and daniepett committed Feb 9, 2022
1 parent 39ae69c commit 912083a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pkg/resources/external_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ func CreateExternalTable(data *schema.ResourceData, meta interface{}) error {

// Set optionals
if v, ok := data.GetOk("partition_by"); ok {
partiionBys := expandStringList(v.(*schema.Set).List())
builder.WithPartitionBys(partiionBys)
partitionBys := expandStringList(v.([]interface{}))
builder.WithPartitionBys(partitionBys)
}

if v, ok := data.GetOk("pattern"); ok {
Expand Down
5 changes: 3 additions & 2 deletions pkg/snowflake/external_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,10 @@ func (tb *ExternalTableBuilder) Create() string {
q.WriteString(strings.Join(columnDefinitions, ", "))
q.WriteString(fmt.Sprintf(`)`))

if len(tb.partitionBys) > 1 {
q.WriteString(` PARTIION BY `)
if len(tb.partitionBys) > 0 {
q.WriteString(` PARTITION BY ( `)
q.WriteString(EscapeString(strings.Join(tb.partitionBys, ", ")))
q.WriteString(` )`)
}

q.WriteString(` WITH LOCATION = ` + EscapeString(tb.location))
Expand Down

0 comments on commit 912083a

Please sign in to comment.