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

Replace CAST with TRY_CAST #885

Merged
merged 4 commits into from
Dec 23, 2023
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
5 changes: 5 additions & 0 deletions flow/activities/flowable.go
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,11 @@ func (a *FlowableActivity) getPostgresPeerConfigs(ctx context.Context) ([]*proto
}

func (a *FlowableActivity) SendWALHeartbeat(ctx context.Context) error {
if !peerdbenv.PeerDBEnableWALHeartbeat() {
slog.InfoContext(ctx, "wal heartbeat is disabled")
return nil
}

sendTimeout := 10 * time.Minute
ticker := time.NewTicker(sendTimeout)
defer ticker.Stop()
Expand Down
13 changes: 10 additions & 3 deletions flow/connectors/snowflake/snowflake.go
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,8 @@ func (c *SnowflakeConnector) generateAndExecuteMergeStatement(

flattenedCastsSQLArray := make([]string, 0, len(normalizedTableSchema.Columns))
for columnName, genericColumnType := range normalizedTableSchema.Columns {
sfType, err := qValueKindToSnowflakeType(qvalue.QValueKind(genericColumnType))
qvKind := qvalue.QValueKind(genericColumnType)
sfType, err := qValueKindToSnowflakeType(qvKind)
if err != nil {
return 0, fmt.Errorf("failed to convert column type %s to snowflake type: %w",
genericColumnType, err)
Expand All @@ -849,8 +850,14 @@ func (c *SnowflakeConnector) generateAndExecuteMergeStatement(
// "Microseconds*1000) "+
// "AS %s,", toVariantColumnName, columnName, columnName))
default:
flattenedCastsSQLArray = append(flattenedCastsSQLArray, fmt.Sprintf("CAST(%s:\"%s\" AS %s) AS %s,",
toVariantColumnName, columnName, sfType, targetColumnName))
if qvKind == qvalue.QValueKindNumeric {
flattenedCastsSQLArray = append(flattenedCastsSQLArray,
fmt.Sprintf("TRY_CAST((%s:\"%s\")::text AS %s) AS %s,",
toVariantColumnName, columnName, sfType, targetColumnName))
} else {
flattenedCastsSQLArray = append(flattenedCastsSQLArray, fmt.Sprintf("CAST(%s:\"%s\" AS %s) AS %s,",
toVariantColumnName, columnName, sfType, targetColumnName))
}
}
}
flattenedCastsSQL := strings.TrimSuffix(strings.Join(flattenedCastsSQLArray, ""), ",")
Expand Down
5 changes: 5 additions & 0 deletions flow/peerdbenv/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,8 @@ func PeerDBAlertingGapMinutesAsDuration() time.Duration {
func PeerDBOpenConnectionsAlertThreshold() uint32 {
return getEnvUint32("PEERDB_PGPEER_OPEN_CONNECTIONS_ALERT_THRESHOLD", 5)
}

// PEERDB_ENABLE_WAL_HEARTBEAT
func PeerDBEnableWALHeartbeat() bool {
return getEnvBool("PEERDB_ENABLE_WAL_HEARTBEAT", false)
}
17 changes: 17 additions & 0 deletions flow/peerdbenv/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,23 @@ func getEnvUint32(name string, defaultValue uint32) uint32 {
return uint32(i)
}

// getEnvBool returns the value of the environment variable with the given name
// or defaultValue if the environment variable is not set or is not a valid
// boolean value.
func getEnvBool(name string, defaultValue bool) bool {
val, ok := getEnv(name)
if !ok {
return defaultValue
}

b, err := strconv.ParseBool(val)
if err != nil {
return defaultValue
}

return b
}

// GetEnvString returns the value of the environment variable with the given name
// or defaultValue if the environment variable is not set.
func getEnvString(name string, defaultValue string) string {
Expand Down
Loading