feat: update chunk size for MSSQL processing and enhance error handling in transformation functions

This commit is contained in:
2026-04-08 20:48:36 -05:00
parent eeef3bc813
commit 853be4a5a6
4 changed files with 69 additions and 40 deletions

View File

@@ -6,26 +6,53 @@ import (
log "github.com/sirupsen/logrus"
)
func transformRowsMssql(columns []ColumnType, in <-chan []UnknownRowValues, out chan<- []UnknownRowValues) {
func transformRowsMssql(
columns []ColumnType,
chChunksIn <-chan []UnknownRowValues,
chChunksOut chan<- []UnknownRowValues,
chJobErrorsOut chan<- JobError,
) {
chunkCount := 0
totalRowsTransformed := 0
for rows := range in {
for rows := range chChunksIn {
chunkStartTime := time.Now()
log.Debugf("Chunk #%d received, transforming %d rows...", chunkCount+1, len(rows))
log.Debugf("Chunk received, transforming %d rows...", len(rows))
for _, rowValues := range rows {
for i, col := range columns {
value := rowValues[i]
if col.SystemType() == "uniqueidentifier" {
switch col.SystemType() {
case "uniqueidentifier":
if b, ok := value.([]byte); ok {
rowValues[i] = mssqlUuidToBigEndian(b)
pgUuid, err := mssqlUuidToBigEndian(b)
if err != nil {
jobError := JobError{
ShouldCancelJob: true,
Prev: err,
}
chJobErrorsOut <- jobError
return
}
rowValues[i] = pgUuid
}
} else if col.SystemType() == "geometry" || col.SystemType() == "geography" {
case "geometry", "geography":
if b, ok := value.([]byte); ok {
rowValues[i] = wkbToEwkbWithSrid(b, 4326)
ewkb, err := wkbToEwkbWithSrid(b, 4326)
if err != nil {
jobError := JobError{
ShouldCancelJob: true,
Prev: err,
}
chJobErrorsOut <- jobError
return
}
rowValues[i] = ewkb
}
} else if col.SystemType() == "datetime" || col.SystemType() == "datetime2" {
case "datetime", "datetime2":
if t, ok := value.(time.Time); ok {
rowValues[i] = ensureUTC(t)
}
@@ -37,26 +64,9 @@ func transformRowsMssql(columns []ColumnType, in <-chan []UnknownRowValues, out
totalRowsTransformed += len(rows)
chunkDuration := time.Since(chunkStartTime)
rowsPerSec := float64(len(rows)) / chunkDuration.Seconds()
log.Infof("Transformed chunk #%d: %d rows in %v (%.0f rows/sec) - Total: %d rows",
chunkCount, len(rows), chunkDuration, rowsPerSec, totalRowsTransformed)
log.Infof("Transformed chunk: %d rows in %v (%.0f rows/sec) - Total: %d rows",
len(rows), chunkDuration, rowsPerSec, totalRowsTransformed)
out <- rows
}
}
func ToInt64(v any) (int64, bool) {
switch t := v.(type) {
case int:
return int64(t), true
case int8:
return int64(t), true
case int16:
return int64(t), true
case int32:
return int64(t), true
case int64:
return int64(t), true
default:
return 0, false
chChunksOut <- rows
}
}