From 02779a5a85154b6ff9febdbcaf4b912cd58d76f4 Mon Sep 17 00:00:00 2001 From: Nathan Villaescusa Date: Wed, 1 May 2024 16:33:44 -0700 Subject: [PATCH] Clean up --- lib/sql/dialect.go | 27 +++++++++------------------ lib/typing/columns/columns.go | 2 -- 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/lib/sql/dialect.go b/lib/sql/dialect.go index c46cb14bd..9a7fcfa22 100644 --- a/lib/sql/dialect.go +++ b/lib/sql/dialect.go @@ -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 } @@ -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 } @@ -45,9 +45,6 @@ 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. @@ -55,15 +52,9 @@ func (sd SnowflakeDialect) NeedsEscaping(name string) bool { // 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 diff --git a/lib/typing/columns/columns.go b/lib/typing/columns/columns.go index e9dac6272..6623d61c6 100644 --- a/lib/typing/columns/columns.go +++ b/lib/typing/columns/columns.go @@ -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) }