Skip to content

Commit 88731e2

Browse files
committed
update data branch
1 parent 27858d0 commit 88731e2

File tree

2 files changed

+51
-25
lines changed

2 files changed

+51
-25
lines changed

pkg/frontend/data_branch.go

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -915,35 +915,43 @@ func writeReplaceRowValues(
915915
tblStuff tableStuff,
916916
row []any,
917917
buf *bytes.Buffer,
918-
) {
918+
) error {
919919
buf.WriteString("(")
920920
for i, idx := range tblStuff.def.visibleIdxes {
921-
formatValIntoString(ses, row[idx], tblStuff.def.colTypes[idx], buf)
921+
if err := formatValIntoString(ses, row[idx], tblStuff.def.colTypes[idx], buf); err != nil {
922+
return err
923+
}
922924
if i != len(tblStuff.def.visibleIdxes)-1 {
923925
buf.WriteString(",")
924926
}
925927
}
926928
buf.WriteString(")")
929+
930+
return nil
927931
}
928932

929933
func writeDeleteRowValues(
930934
ses *Session,
931935
tblStuff tableStuff,
932936
row []any,
933937
buf *bytes.Buffer,
934-
) {
938+
) error {
935939
if len(tblStuff.def.pkColIdxes) > 1 {
936940
buf.WriteString("(")
937941
}
938942
for i, colIdx := range tblStuff.def.pkColIdxes {
939-
formatValIntoString(ses, row[colIdx], tblStuff.def.colTypes[colIdx], buf)
943+
if err := formatValIntoString(ses, row[colIdx], tblStuff.def.colTypes[colIdx], buf); err != nil {
944+
return err
945+
}
940946
if i != len(tblStuff.def.pkColIdxes)-1 {
941947
buf.WriteString(",")
942948
}
943949
}
944950
if len(tblStuff.def.pkColIdxes) > 1 {
945951
buf.WriteString(")")
946952
}
953+
954+
return nil
947955
}
948956

949957
func appendBatchRowsAsSQLValues(
@@ -1011,9 +1019,13 @@ func appendBatchRowsAsSQLValues(
10111019

10121020
tmpValsBuffer.Reset()
10131021
if wrapped.kind == diffDelete {
1014-
writeDeleteRowValues(ses, tblStuff, row, tmpValsBuffer)
1022+
if err = writeDeleteRowValues(ses, tblStuff, row, tmpValsBuffer); err != nil {
1023+
return
1024+
}
10151025
} else {
1016-
writeReplaceRowValues(ses, tblStuff, row, tmpValsBuffer)
1026+
if err = writeReplaceRowValues(ses, tblStuff, row, tmpValsBuffer); err != nil {
1027+
return
1028+
}
10171029
}
10181030

10191031
if tmpValsBuffer.Len() == 0 {
@@ -2588,7 +2600,12 @@ func hashDiffIfHasLCA(
25882600
}
25892601

25902602
buf := acquireBuffer(tblStuff.bufPool)
2591-
formatValIntoString(ses, tarRow[0], tblStuff.def.colTypes[tblStuff.def.pkColIdx], buf)
2603+
if err3 = formatValIntoString(
2604+
ses, tarRow[0], tblStuff.def.colTypes[tblStuff.def.pkColIdx], buf,
2605+
); err3 != nil {
2606+
releaseBuffer(tblStuff.bufPool, buf)
2607+
return
2608+
}
25922609

25932610
err3 = moerr.NewInternalErrorNoCtxf(
25942611
"conflict: %s %s and %s %s on pk(%v) with different values",
@@ -3017,7 +3034,10 @@ func checkConflictAndAppendToBat(
30173034
case tree.CONFLICT_FAIL:
30183035
buf := acquireBuffer(tblStuff.bufPool)
30193036
for i, idx := range tblStuff.def.pkColIdxes {
3020-
formatValIntoString(ses, tarTuple[idx], tblStuff.def.colTypes[idx], buf)
3037+
if err2 = formatValIntoString(ses, tarTuple[idx], tblStuff.def.colTypes[idx], buf); err2 != nil {
3038+
releaseBuffer(tblStuff.bufPool, buf)
3039+
return err2
3040+
}
30213041
if i < len(tblStuff.def.pkColIdxes)-1 {
30223042
buf.WriteString(",")
30233043
}
@@ -3325,7 +3345,11 @@ func handleDelsOnLCA(
33253345
valsBuf.WriteString(fmt.Sprintf("row(%d,", i))
33263346

33273347
for j := range tuple {
3328-
formatValIntoString(ses, tuple[j], colTypes[expandedPKColIdxes[j]], valsBuf)
3348+
if err = formatValIntoString(
3349+
ses, tuple[j], colTypes[expandedPKColIdxes[j]], valsBuf,
3350+
); err != nil {
3351+
return nil, err
3352+
}
33293353
if j != len(tuple)-1 {
33303354
valsBuf.WriteString(", ")
33313355
}
@@ -3473,10 +3497,10 @@ func handleDelsOnLCA(
34733497
return
34743498
}
34753499

3476-
func formatValIntoString(ses *Session, val any, t types.Type, buf *bytes.Buffer) {
3500+
func formatValIntoString(ses *Session, val any, t types.Type, buf *bytes.Buffer) error {
34773501
if val == nil {
34783502
buf.WriteString("NULL")
3479-
return
3503+
return nil
34803504
}
34813505

34823506
var scratch [64]byte
@@ -3507,30 +3531,30 @@ func formatValIntoString(ses *Session, val any, t types.Type, buf *bytes.Buffer)
35073531
strVal = x.String()
35083532
case *bytejson.ByteJson:
35093533
if x == nil {
3510-
panic(moerr.NewInternalErrorNoCtx("formatValIntoString: nil *bytejson.ByteJson"))
3534+
return moerr.NewInternalErrorNoCtx("formatValIntoString: nil *bytejson.ByteJson")
35113535
}
35123536
strVal = x.String()
35133537
case []byte:
35143538
strVal = string(x)
35153539
case string:
35163540
strVal = x
35173541
default:
3518-
panic(moerr.NewInternalErrorNoCtxf("formatValIntoString: unexpected json type %T", val))
3542+
return moerr.NewInternalErrorNoCtxf("formatValIntoString: unexpected json type %T", val)
35193543
}
35203544
jsonLiteral := escapeJSONControlBytes([]byte(strVal))
35213545
if !json.Valid(jsonLiteral) {
3522-
panic(moerr.NewInternalErrorNoCtxf("formatValIntoString: invalid json input %q", strVal))
3546+
return moerr.NewInternalErrorNoCtxf("formatValIntoString: invalid json input %q", strVal)
35233547
}
35243548
writeEscapedSQLString(buf, jsonLiteral)
3525-
return
3549+
return nil
35263550
}
35273551
switch x := val.(type) {
35283552
case []byte:
35293553
writeEscapedSQLString(buf, x)
35303554
case string:
35313555
writeEscapedSQLString(buf, []byte(x))
35323556
default:
3533-
panic(moerr.NewInternalErrorNoCtxf("formatValIntoString: unexpected string type %T", val))
3557+
return moerr.NewInternalErrorNoCtxf("formatValIntoString: unexpected string type %T", val)
35343558
}
35353559
case types.T_timestamp:
35363560
buf.WriteString("'")
@@ -3585,8 +3609,10 @@ func formatValIntoString(ses *Session, val any, t types.Type, buf *bytes.Buffer)
35853609
buf.WriteString(types.ArrayToString[float64](val.([]float64)))
35863610
buf.WriteString("'")
35873611
default:
3588-
panic(moerr.NewInternalErrorNoCtxf("formatValIntoString: unsupported type %v", t.Oid))
3612+
return moerr.NewNotSupportedNoCtxf("formatValIntoString: not support type %v", t.Oid)
35893613
}
3614+
3615+
return nil
35903616
}
35913617

35923618
// writeEscapedSQLString escapes special and control characters for SQL literal output.

pkg/frontend/data_branch_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func TestFormatValIntoString_StringEscaping(t *testing.T) {
4040
ses := &Session{}
4141

4242
val := "a'b\"c\\\n\t\r\x1a\x00"
43-
formatValIntoString(ses, val, types.New(types.T_varchar, 0, 0), &buf)
43+
require.NoError(t, formatValIntoString(ses, val, types.New(types.T_varchar, 0, 0), &buf))
4444
require.Equal(t, `'a\'b"c\\\n\t\r\Z\0'`, buf.String())
4545
}
4646

@@ -49,7 +49,7 @@ func TestFormatValIntoString_ByteEscaping(t *testing.T) {
4949
ses := &Session{}
5050

5151
val := []byte{'x', 0x00, '\\', 0x07, '\''}
52-
formatValIntoString(ses, val, types.New(types.T_varbinary, 0, 0), &buf)
52+
require.NoError(t, formatValIntoString(ses, val, types.New(types.T_varbinary, 0, 0), &buf))
5353
require.Equal(t, `'x\0\\\x07\''`, buf.String())
5454
}
5555

@@ -58,7 +58,7 @@ func TestFormatValIntoString_JSONEscaping(t *testing.T) {
5858
ses := &Session{}
5959

6060
val := `{"k":"` + string([]byte{0x01, '\n'}) + `"}`
61-
formatValIntoString(ses, val, types.New(types.T_json, 0, 0), &buf)
61+
require.NoError(t, formatValIntoString(ses, val, types.New(types.T_json, 0, 0), &buf))
6262
require.Equal(t, `'{"k":"\\u0001\\u000a"}'`, buf.String())
6363
}
6464

@@ -69,25 +69,25 @@ func TestFormatValIntoString_JSONByteJson(t *testing.T) {
6969
bj, err := types.ParseStringToByteJson(`{"a":1}`)
7070
require.NoError(t, err)
7171

72-
formatValIntoString(ses, bj, types.New(types.T_json, 0, 0), &buf)
72+
require.NoError(t, formatValIntoString(ses, bj, types.New(types.T_json, 0, 0), &buf))
7373
require.Equal(t, `'{"a": 1}'`, buf.String())
7474
}
7575

7676
func TestFormatValIntoString_Nil(t *testing.T) {
7777
var buf bytes.Buffer
7878
ses := &Session{}
7979

80-
formatValIntoString(ses, nil, types.New(types.T_varchar, 0, 0), &buf)
80+
require.NoError(t, formatValIntoString(ses, nil, types.New(types.T_varchar, 0, 0), &buf))
8181
require.Equal(t, "NULL", buf.String())
8282
}
8383

8484
func TestFormatValIntoString_UnsupportedType(t *testing.T) {
8585
var buf bytes.Buffer
8686
ses := &Session{}
8787

88-
require.Panics(t, func() {
89-
formatValIntoString(ses, true, types.New(types.T_bool, 0, 0), &buf)
90-
})
88+
err := formatValIntoString(ses, true, types.New(types.T_Rowid, 0, 0), &buf)
89+
require.Error(t, err)
90+
require.Contains(t, err.Error(), "not support type")
9191
}
9292

9393
func TestCompareSingleValInVector_AllTypes(t *testing.T) {

0 commit comments

Comments
 (0)