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

mixed case support for CDC mirrors in Snowflake and Postgres #589

Closed
wants to merge 2 commits into from

Conversation

heavycrystal
Copy link
Contributor

No description provided.

@@ -497,6 +497,7 @@ func (c *PostgresConnector) generateFallbackStatements(destinationTableIdentifie
}
}
flattenedCastsSQL := strings.TrimSuffix(strings.Join(flattenedCastsSQLArray, ","), ",")
parsedDstTable, _ := utils.ParseSchemaTable(destinationTableIdentifier)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put this at top before normalizedTableSchema would probably run into a nil dereference & handle errors

@@ -529,6 +530,7 @@ func (c *PostgresConnector) generateMergeStatement(destinationTableIdentifier st
for i, columnName := range columnNames {
columnNames[i] = fmt.Sprintf("\"%s\"", columnName)
}
parsedDstTable, _ := utils.ParseSchemaTable(destinationTableIdentifier)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On one level it feels like this could be made more efficient with a utils.SanitizeSchemaTable where it'd avoid allocations in case where destinationTableIdentifier == parsedDstTable.String() but in another level it seems like you're already too late here if for stranger names like those containing a period. But maybe character stripping avoids that for now

Copy link
Contributor

@serprex serprex Nov 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

func SanitizeSchemaTable(dirty string) {
  var sb strings.Builder
  sb.Grow(len(dirty) + 4)
  sb.WriteRune('"')
  sb.WriteString(strings.Replace(dirty, ".", "\".\"", 1))
  sb.WriteRune('"')
  return sb.String()
}

Something like this. Would have to profile to see if it actually brings any benefit. Probably over optimizing. This draft also fails to include the return dirty if dirty matches [a-zA-Z0-9.]+ logic

// https://www.alberton.info/dbms_identifiers_and_case_sensitivity.html
// Snowflake follows the SQL standard, but Postgres does the opposite.
// Ergo, we suffer.
if strings.ToLower(identifier) == identifier {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A utils.IsLower(string) / utils.IsUpper(string) could be implemented using unicode package's IsLetter / IsUpper / IsLower

https://pkg.go.dev/unicode

}
}

switch appendMode {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
switch appendMode {
if appendMode {

@serprex serprex deleted the pg-sf-mixed-case branch July 19, 2024 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants