Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan-artie committed May 1, 2024
1 parent cf0f030 commit 02779a5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 20 deletions.
27 changes: 9 additions & 18 deletions lib/sql/dialect.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@ type Dialect interface {
QuoteIdentifier(identifier string) string
}

type MSSQLDialect struct{}

func (MSSQLDialect) NeedsEscaping(_ string) bool { return true }

func (MSSQLDialect) QuoteIdentifier(identifier string) string {
return fmt.Sprintf(`"%s"`, identifier)
}

type BigQueryDialect struct{}

func (BigQueryDialect) NeedsEscaping(_ string) bool { return true }
Expand All @@ -32,6 +24,14 @@ func (BigQueryDialect) QuoteIdentifier(identifier string) string {
return fmt.Sprintf("`%s`", identifier)
}

type MSSQLDialect struct{}

func (MSSQLDialect) NeedsEscaping(_ string) bool { return true }

func (MSSQLDialect) QuoteIdentifier(identifier string) string {
return fmt.Sprintf(`"%s"`, identifier)
}

type RedshiftDialect struct{}

func (RedshiftDialect) NeedsEscaping(_ string) bool { return true }
Expand All @@ -45,25 +45,16 @@ type SnowflakeDialect struct {
UppercaseEscNames bool
}

// symbolsToEscape are additional keywords that we need to escape
var symbolsToEscape = []string{":"}

func (sd SnowflakeDialect) NeedsEscaping(name string) bool {
if sd.UppercaseEscNames {
// If uppercaseEscNames is true then we will escape all identifiers that do not start with the Artie priefix.
// Since they will be uppercased afer they are escaped then they will result in the same value as if we
// we were to use them in a query without any escaping at all.
return true
} else {
if slices.Contains(constants.ReservedKeywords, name) {
if slices.Contains(constants.ReservedKeywords, name) || strings.Contains(name, ":") {
return true
}
// If it does not contain any reserved words, does it contain any symbols that need to be escaped?
for _, symbol := range symbolsToEscape {
if strings.Contains(name, symbol) {
return true
}
}
// If it still doesn't need to be escaped, we should check if it's a number.
if _, err := strconv.Atoi(name); err == nil {
return true
Expand Down
2 changes: 0 additions & 2 deletions lib/typing/columns/columns.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ func (c *Column) RawName() string {
}

// Name will give you c.name and escape it if necessary.
// Plus we will escape it if the column name is part of the reserved words from destinations.
// If so, it'll change from `start` => `"start"` as suggested by Snowflake.
func (c *Column) Name(dialect sql.Dialect) string {
return sql.EscapeNameIfNecessary(c.name, dialect)
}
Expand Down

0 comments on commit 02779a5

Please sign in to comment.