Skip to content

Commit 083550f

Browse files
authored
materialize-mysql: check for string before resizing varchar (#3564)
It is possible that the value is nil here, in that case we can skip any resizing.
1 parent cad37fe commit 083550f

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

materialize-mysql/driver.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -783,19 +783,21 @@ func (d *transactor) Store(it *m.StoreIterator) (_ m.StartCommitFunc, err error)
783783
for idx, c := range converted {
784784
varcharMeta := b.varcharColumnMetas[idx]
785785
if varcharMeta.identifier != "" {
786-
l := len(c.(string))
787-
788-
if l > varcharMeta.maxLength {
789-
log.WithFields(log.Fields{
790-
"table": b.target.Identifier,
791-
"column": varcharMeta.identifier,
792-
"currentColumnLength": varcharMeta.maxLength,
793-
"stringValueLength": l,
794-
}).Info("column will be altered to VARCHAR(stringLength) to accommodate large string value")
795-
b.varcharColumnMetas[idx].maxLength = l
786+
if v, ok := c.(string); ok {
787+
l := len(v)
796788

797-
if _, err := d.store.conn.ExecContext(ctx, fmt.Sprintf(varcharTableAlter, b.target.Identifier, varcharMeta.identifier, l)); err != nil {
798-
return nil, fmt.Errorf("altering size for column %s of table %s: %w", varcharMeta.identifier, b.target.Identifier, err)
789+
if l > varcharMeta.maxLength {
790+
log.WithFields(log.Fields{
791+
"table": b.target.Identifier,
792+
"column": varcharMeta.identifier,
793+
"currentColumnLength": varcharMeta.maxLength,
794+
"stringValueLength": l,
795+
}).Info("column will be altered to VARCHAR(stringLength) to accommodate large string value")
796+
b.varcharColumnMetas[idx].maxLength = l
797+
798+
if _, err := d.store.conn.ExecContext(ctx, fmt.Sprintf(varcharTableAlter, b.target.Identifier, varcharMeta.identifier, l)); err != nil {
799+
return nil, fmt.Errorf("altering size for column %s of table %s: %w", varcharMeta.identifier, b.target.Identifier, err)
800+
}
799801
}
800802
}
801803
}

0 commit comments

Comments
 (0)