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

Misc cleanup #535

Merged
merged 1 commit into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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