Skip to content

Commit 0aac63a

Browse files
committed
fix ut
1 parent 3661438 commit 0aac63a

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

pkg/vm/engine/disttae/txn_test.go

+17
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,15 @@ package disttae
1616

1717
import (
1818
"bytes"
19+
"context"
1920
"sync"
2021
"testing"
2122

2223
"github.com/matrixorigin/matrixone/pkg/container/types"
2324
"github.com/matrixorigin/matrixone/pkg/objectio"
25+
"github.com/matrixorigin/matrixone/pkg/sql/parsers"
26+
"github.com/matrixorigin/matrixone/pkg/sql/parsers/dialect"
27+
"github.com/matrixorigin/matrixone/pkg/txn/client"
2428
"github.com/stretchr/testify/require"
2529
)
2630

@@ -62,3 +66,16 @@ func Test_GetUncommittedS3Tombstone(t *testing.T) {
6266
return true
6367
})
6468
}
69+
70+
func TestTransaction_StartStatement(t *testing.T) {
71+
var txn Transaction
72+
var fn func()
73+
ctx := context.Background()
74+
txn.op, fn = client.NewTestTxnOperator(ctx)
75+
defer fn()
76+
txn.StartStatement(nil)
77+
stmts, err := parsers.Parse(ctx, dialect.MYSQL, "show databases", 0)
78+
require.NoError(t, err)
79+
require.Equal(t, len(stmts), 1)
80+
txn.StartStatement(stmts[0])
81+
}

pkg/vm/engine/disttae/types.go

+11-3
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import (
1818
"bytes"
1919
"context"
2020
"encoding/hex"
21+
"flag"
2122
"fmt"
22-
"github.com/matrixorigin/matrixone/pkg/sql/parsers/tree"
2323
"math"
2424
"strconv"
2525
"sync"
@@ -45,6 +45,8 @@ import (
4545
"github.com/matrixorigin/matrixone/pkg/pb/timestamp"
4646
qclient "github.com/matrixorigin/matrixone/pkg/queryservice/client"
4747
"github.com/matrixorigin/matrixone/pkg/sql/colexec"
48+
"github.com/matrixorigin/matrixone/pkg/sql/parsers/dialect"
49+
"github.com/matrixorigin/matrixone/pkg/sql/parsers/tree"
4850
"github.com/matrixorigin/matrixone/pkg/txn/client"
4951
"github.com/matrixorigin/matrixone/pkg/txn/trace"
5052
"github.com/matrixorigin/matrixone/pkg/udf"
@@ -530,9 +532,15 @@ func (txn *Transaction) StartStatement(stmt tree.Statement) {
530532
if txn.startStatementCalled {
531533
var sql string
532534
if stmt != nil {
533-
sql = stmt.String()
535+
fmtCtx := tree.NewFmtCtx(dialect.MYSQL, tree.WithQuoteString(true))
536+
stmt.Format(fmtCtx)
537+
sql = fmtCtx.String()
538+
}
539+
log := logutil.Fatal
540+
if flag.Lookup("test.v") != nil {
541+
log = logutil.Error
534542
}
535-
logutil.Fatal("BUG: StartStatement called twice",
543+
log("BUG: StartStatement called twice",
536544
zap.String("txn", hex.EncodeToString(txn.op.Txn().ID)),
537545
zap.String("SQL", sql),
538546
)

0 commit comments

Comments
 (0)