-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f673f4c
commit db5d399
Showing
7 changed files
with
118 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package sql | ||
|
||
import ( | ||
"fmt" | ||
"log/slog" | ||
"strings" | ||
) | ||
|
||
type Dialect interface { | ||
QuoteIdentifier(identifier string) string | ||
} | ||
|
||
type DefaultDialect struct{} | ||
|
||
func (DefaultDialect) QuoteIdentifier(identifier string) string { | ||
return fmt.Sprintf(`"%s"`, identifier) | ||
} | ||
|
||
type BigQueryDialect struct{} | ||
|
||
func (BigQueryDialect) QuoteIdentifier(identifier string) string { | ||
// BigQuery needs backticks to quote. | ||
return fmt.Sprintf("`%s`", identifier) | ||
} | ||
|
||
type RedshiftDialect struct{} | ||
|
||
func (rd RedshiftDialect) QuoteIdentifier(identifier string) string { | ||
// Preserve the existing behavior of Redshift identifiers being lowercased due to not being quoted. | ||
return fmt.Sprintf(`"%s"`, strings.ToLower(identifier)) | ||
} | ||
|
||
type SnowflakeDialect struct { | ||
UppercaseEscNames bool | ||
} | ||
|
||
func (sd SnowflakeDialect) QuoteIdentifier(identifier string) string { | ||
if sd.UppercaseEscNames { | ||
identifier = strings.ToUpper(identifier) | ||
} else { | ||
slog.Warn("Escaped Snowflake identifier is not being uppercased", | ||
slog.String("name", identifier), | ||
slog.Bool("uppercaseEscapedNames", sd.UppercaseEscNames), | ||
) | ||
} | ||
|
||
return fmt.Sprintf(`"%s"`, identifier) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package sql | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestDefaultDialect_QuoteIdentifier(t *testing.T) { | ||
dialect := DefaultDialect{} | ||
assert.Equal(t, `"foo"`, dialect.QuoteIdentifier("foo")) | ||
assert.Equal(t, `"FOO"`, dialect.QuoteIdentifier("FOO")) | ||
} | ||
|
||
func TestBigQueryDialect_QuoteIdentifier(t *testing.T) { | ||
dialect := BigQueryDialect{} | ||
assert.Equal(t, "`foo`", dialect.QuoteIdentifier("foo")) | ||
assert.Equal(t, "`FOO`", dialect.QuoteIdentifier("FOO")) | ||
} | ||
|
||
func TestRedshiftDialect_QuoteIdentifier(t *testing.T) { | ||
dialect := RedshiftDialect{} | ||
assert.Equal(t, `"foo"`, dialect.QuoteIdentifier("foo")) | ||
assert.Equal(t, `"foo"`, dialect.QuoteIdentifier("FOO")) | ||
} | ||
|
||
func TestSnowflakeDialect_QuoteIdentifier(t *testing.T) { | ||
{ | ||
// UppercaseEscNames enabled: | ||
dialect := SnowflakeDialect{UppercaseEscNames: true} | ||
assert.Equal(t, `"FOO"`, dialect.QuoteIdentifier("foo")) | ||
assert.Equal(t, `"FOO"`, dialect.QuoteIdentifier("FOO")) | ||
} | ||
{ | ||
// UppercaseEscNames disabled: | ||
dialect := SnowflakeDialect{UppercaseEscNames: false} | ||
assert.Equal(t, `"foo"`, dialect.QuoteIdentifier("foo")) | ||
assert.Equal(t, `"FOO"`, dialect.QuoteIdentifier("FOO")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters