MCPcopy
hub / github.com/pingcap/tidb / TestHashGroupKey

Function TestHashGroupKey

pkg/expression/util_test.go:336–369  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

334}
335
336func TestHashGroupKey(t *testing.T) {
337 ctx := mock.NewContext()
338 sc := stmtctx.NewStmtCtxWithTimeZone(time.Local)
339 eTypes := []types.EvalType{types.ETInt, types.ETReal, types.ETDecimal, types.ETString, types.ETTimestamp, types.ETDatetime, types.ETDuration}
340 tNames := []string{"int", "real", "decimal", "string", "timestamp", "datetime", "duration"}
341 for i := 0; i < len(tNames); i++ {
342 ft := eType2FieldType(eTypes[i])
343 if eTypes[i] == types.ETDecimal {
344 ft.SetFlen(0)
345 }
346 colExpr := &Column{Index: 0, RetType: ft}
347 input := chunk.New([]*types.FieldType{ft}, 1024, 1024)
348 fillColumnWithGener(eTypes[i], input, 0, nil)
349 colBuf := chunk.NewColumn(ft, 1024)
350 bufs := make([][]byte, 1024)
351 for j := 0; j < 1024; j++ {
352 bufs[j] = bufs[j][:0]
353 }
354 var err error
355 err = EvalExpr(ctx, ctx.GetSessionVars().EnableVectorizedExpression, colExpr, colExpr.GetType(ctx).EvalType(), input, colBuf)
356 require.NoError(t, err)
357 bufs, err = codec.HashGroupKey(sc.TimeZone(), 1024, colBuf, bufs, ft)
358 require.NoError(t, err)
359
360 var buf []byte
361 for j := 0; j < input.NumRows(); j++ {
362 d, err := colExpr.Eval(ctx, input.GetRow(j))
363 require.NoError(t, err)
364 buf, err = codec.EncodeValue(sc.TimeZone(), buf[:0], d)
365 require.NoError(t, err)
366 require.Equal(t, string(bufs[j]), string(buf))
367 }
368 }
369}
370
371func isLogicOrFunction(e Expression) bool {
372 if f, ok := e.(*ScalarFunction); ok {

Callers

nothing calls this directly

Calls 15

GetSessionVarsMethod · 0.95
GetTypeMethod · 0.95
EvalMethod · 0.95
NewContextFunction · 0.92
NewStmtCtxWithTimeZoneFunction · 0.92
NewFunction · 0.92
NewColumnFunction · 0.92
HashGroupKeyFunction · 0.92
EncodeValueFunction · 0.92
eType2FieldTypeFunction · 0.85
fillColumnWithGenerFunction · 0.85
EvalExprFunction · 0.85

Tested by

no test coverage detected