本文整理汇总了Golang中github.com/cockroachdb/cockroach/pkg/sql/sqlbase.EncDatumRows类的典型用法代码示例。如果您正苦于以下问题:Golang EncDatumRows类的具体用法?Golang EncDatumRows怎么用?Golang EncDatumRows使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EncDatumRows类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestSorter
func TestSorter(t *testing.T) {
defer leaktest.AfterTest(t)()
v := [6]sqlbase.EncDatum{}
for i := range v {
v[i].SetDatum(sqlbase.ColumnType_INT, parser.NewDInt(parser.DInt(i)))
}
asc := encoding.Ascending
desc := encoding.Descending
testCases := []struct {
spec SorterSpec
input sqlbase.EncDatumRows
expected sqlbase.EncDatumRows
}{
{
// No specified input ordering and unspecified limit.
spec: SorterSpec{
OutputOrdering: convertToSpecOrdering(
sqlbase.ColumnOrdering{
{ColIdx: 0, Direction: asc},
{ColIdx: 1, Direction: desc},
{ColIdx: 2, Direction: asc},
}),
},
input: sqlbase.EncDatumRows{
{v[1], v[0], v[4]},
{v[3], v[4], v[1]},
{v[4], v[4], v[4]},
{v[3], v[2], v[0]},
{v[4], v[4], v[5]},
{v[3], v[3], v[0]},
{v[0], v[0], v[0]},
},
expected: sqlbase.EncDatumRows{
{v[0], v[0], v[0]},
{v[1], v[0], v[4]},
{v[3], v[4], v[1]},
{v[3], v[3], v[0]},
{v[3], v[2], v[0]},
{v[4], v[4], v[4]},
{v[4], v[4], v[5]},
},
}, {
// No specified input ordering but specified limit.
spec: SorterSpec{
Limit: 4,
OutputOrdering: convertToSpecOrdering(
sqlbase.ColumnOrdering{
{ColIdx: 0, Direction: asc},
{ColIdx: 1, Direction: asc},
{ColIdx: 2, Direction: asc},
}),
},
input: sqlbase.EncDatumRows{
{v[3], v[3], v[0]},
{v[3], v[4], v[1]},
{v[1], v[0], v[4]},
{v[0], v[0], v[0]},
{v[4], v[4], v[4]},
{v[4], v[4], v[5]},
{v[3], v[2], v[0]},
},
expected: sqlbase.EncDatumRows{
{v[0], v[0], v[0]},
{v[1], v[0], v[4]},
{v[3], v[2], v[0]},
{v[3], v[3], v[0]},
},
}, {
// Specified match ordering length but no specified limit.
spec: SorterSpec{
OrderingMatchLen: 2,
OutputOrdering: convertToSpecOrdering(
sqlbase.ColumnOrdering{
{ColIdx: 0, Direction: asc},
{ColIdx: 1, Direction: asc},
{ColIdx: 2, Direction: asc},
}),
},
input: sqlbase.EncDatumRows{
{v[0], v[1], v[2]},
{v[0], v[1], v[0]},
{v[1], v[0], v[5]},
{v[1], v[1], v[5]},
{v[1], v[1], v[4]},
{v[3], v[4], v[3]},
{v[3], v[4], v[2]},
{v[3], v[5], v[1]},
{v[4], v[4], v[5]},
{v[4], v[4], v[4]},
},
expected: sqlbase.EncDatumRows{
{v[0], v[1], v[0]},
{v[0], v[1], v[2]},
{v[1], v[0], v[5]},
{v[1], v[1], v[4]},
{v[1], v[1], v[5]},
{v[3], v[4], v[2]},
{v[3], v[4], v[3]},
//.........这里部分代码省略.........
示例2: TestMergeJoiner
func TestMergeJoiner(t *testing.T) {
defer leaktest.AfterTest(t)()
v := [6]sqlbase.EncDatum{}
for i := range v {
v[i] = sqlbase.DatumToEncDatum(sqlbase.ColumnType_INT, parser.NewDInt(parser.DInt(i)))
}
null := sqlbase.EncDatum{Datum: parser.DNull}
testCases := []struct {
spec MergeJoinerSpec
inputs []sqlbase.EncDatumRows
expected sqlbase.EncDatumRows
}{
{
spec: MergeJoinerSpec{
LeftOrdering: convertToSpecOrdering(
sqlbase.ColumnOrdering{
{ColIdx: 0, Direction: encoding.Ascending},
}),
LeftTypes: []sqlbase.ColumnType_Kind{
sqlbase.ColumnType_INT,
sqlbase.ColumnType_INT,
},
RightOrdering: convertToSpecOrdering(
sqlbase.ColumnOrdering{
{ColIdx: 0, Direction: encoding.Ascending},
}),
RightTypes: []sqlbase.ColumnType_Kind{
sqlbase.ColumnType_INT,
sqlbase.ColumnType_INT,
sqlbase.ColumnType_INT,
},
Type: JoinType_INNER,
OutputColumns: []uint32{0, 3, 4},
// Implicit @1 = @3 constraint.
},
inputs: []sqlbase.EncDatumRows{
{
{v[0], v[0]},
{v[1], v[4]},
{v[2], v[4]},
{v[3], v[1]},
{v[4], v[5]},
{v[5], v[5]},
},
{
{v[1], v[0], v[4]},
{v[3], v[4], v[1]},
{v[4], v[4], v[5]},
},
},
expected: sqlbase.EncDatumRows{
{v[1], v[0], v[4]},
{v[3], v[4], v[1]},
{v[4], v[4], v[5]},
},
},
{
spec: MergeJoinerSpec{
LeftOrdering: convertToSpecOrdering(
sqlbase.ColumnOrdering{
{ColIdx: 0, Direction: encoding.Ascending},
}),
LeftTypes: []sqlbase.ColumnType_Kind{
sqlbase.ColumnType_INT,
sqlbase.ColumnType_INT,
},
RightOrdering: convertToSpecOrdering(
sqlbase.ColumnOrdering{
{ColIdx: 0, Direction: encoding.Ascending},
}),
RightTypes: []sqlbase.ColumnType_Kind{
sqlbase.ColumnType_INT,
sqlbase.ColumnType_INT,
sqlbase.ColumnType_INT,
},
Type: JoinType_INNER,
OutputColumns: []uint32{0, 1, 3},
// Implicit @1 = @3 constraint.
},
inputs: []sqlbase.EncDatumRows{
{
{v[0], v[0]},
{v[0], v[1]},
},
{
{v[0], v[4]},
{v[0], v[1]},
{v[0], v[0]},
{v[0], v[5]},
{v[0], v[4]},
},
},
expected: sqlbase.EncDatumRows{
{v[0], v[0], v[4]},
{v[0], v[0], v[1]},
{v[0], v[0], v[0]},
{v[0], v[0], v[5]},
{v[0], v[0], v[4]},
{v[0], v[1], v[4]},
//.........这里部分代码省略.........
示例3: TestOrderedSync
func TestOrderedSync(t *testing.T) {
defer leaktest.AfterTest(t)()
columnTypeInt := &sqlbase.ColumnType{Kind: sqlbase.ColumnType_INT}
v := [6]sqlbase.EncDatum{}
for i := range v {
v[i] = sqlbase.DatumToEncDatum(*columnTypeInt, parser.NewDInt(parser.DInt(i)))
}
asc := encoding.Ascending
desc := encoding.Descending
testCases := []struct {
sources []sqlbase.EncDatumRows
ordering sqlbase.ColumnOrdering
expected sqlbase.EncDatumRows
}{
{
sources: []sqlbase.EncDatumRows{
{
{v[0], v[1], v[4]},
{v[0], v[1], v[2]},
{v[0], v[2], v[3]},
{v[1], v[1], v[3]},
},
{
{v[1], v[0], v[4]},
},
{
{v[0], v[0], v[0]},
{v[4], v[4], v[4]},
},
},
ordering: sqlbase.ColumnOrdering{
{ColIdx: 0, Direction: asc},
{ColIdx: 1, Direction: asc},
},
expected: sqlbase.EncDatumRows{
{v[0], v[0], v[0]},
{v[0], v[1], v[4]},
{v[0], v[1], v[2]},
{v[0], v[2], v[3]},
{v[1], v[0], v[4]},
{v[1], v[1], v[3]},
{v[4], v[4], v[4]},
},
},
{
sources: []sqlbase.EncDatumRows{
{},
{
{v[1], v[0], v[4]},
},
{
{v[3], v[4], v[1]},
{v[4], v[4], v[4]},
{v[3], v[2], v[0]},
},
{
{v[4], v[4], v[5]},
{v[3], v[3], v[0]},
{v[0], v[0], v[0]},
},
},
ordering: sqlbase.ColumnOrdering{
{ColIdx: 1, Direction: desc},
{ColIdx: 0, Direction: asc},
{ColIdx: 2, Direction: asc},
},
expected: sqlbase.EncDatumRows{
{v[3], v[4], v[1]},
{v[4], v[4], v[4]},
{v[4], v[4], v[5]},
{v[3], v[3], v[0]},
{v[3], v[2], v[0]},
{v[0], v[0], v[0]},
{v[1], v[0], v[4]},
},
},
}
for testIdx, c := range testCases {
var sources []RowSource
for _, srcRows := range c.sources {
rowBuf := &RowBuffer{rows: srcRows}
sources = append(sources, rowBuf)
}
src, err := makeOrderedSync(c.ordering, sources)
if err != nil {
t.Fatal(err)
}
var retRows sqlbase.EncDatumRows
for {
row, err := src.NextRow()
if err != nil {
t.Fatal(err)
}
if row == nil {
break
}
retRows = append(retRows, row)
//.........这里部分代码省略.........
示例4: TestServer
func TestServer(t *testing.T) {
defer leaktest.AfterTest(t)()
s, sqlDB, kvDB := serverutils.StartServer(t, base.TestServerArgs{})
defer s.Stopper().Stop()
conn, err := s.RPCContext().GRPCDial(s.ServingAddr())
if err != nil {
t.Fatal(err)
}
r := sqlutils.MakeSQLRunner(t, sqlDB)
r.Exec(`CREATE DATABASE test`)
r.Exec(`CREATE TABLE test.t (a INT PRIMARY KEY, b INT)`)
r.Exec(`INSERT INTO test.t VALUES (1, 10), (2, 20), (3, 30)`)
td := sqlbase.GetTableDescriptor(kvDB, "test", "t")
ts := TableReaderSpec{
Table: *td,
IndexIdx: 0,
Reverse: false,
Spans: nil,
Filter: Expression{Expr: "$0 != 2"}, // a != 2
OutputColumns: []uint32{0, 1}, // a
}
txn := client.NewTxn(context.Background(), *kvDB)
req := &SetupFlowRequest{Txn: txn.Proto}
req.Flow = FlowSpec{
Processors: []ProcessorSpec{{
Core: ProcessorCoreUnion{TableReader: &ts},
Output: []OutputRouterSpec{{
Type: OutputRouterSpec_MIRROR,
Streams: []StreamEndpointSpec{{Mailbox: &MailboxSpec{SimpleResponse: true}}},
}},
}},
}
distSQLClient := NewDistSQLClient(conn)
stream, err := distSQLClient.RunSimpleFlow(context.Background(), req)
if err != nil {
t.Fatal(err)
}
var decoder StreamDecoder
var rows sqlbase.EncDatumRows
for {
msg, err := stream.Recv()
if err != nil {
if err == io.EOF {
break
}
t.Fatal(err)
}
err = decoder.AddMessage(msg)
if err != nil {
t.Fatal(err)
}
rows = testGetDecodedRows(t, &decoder, rows)
}
if done, trailerErr := decoder.IsDone(); !done {
t.Fatal("stream not done")
} else if trailerErr != nil {
t.Fatal("error in the stream trailer:", trailerErr)
}
str := rows.String()
expected := "[[1 10] [3 30]]"
if str != expected {
t.Errorf("invalid results: %s, expected %s'", str, expected)
}
}
示例5: TestClusterFlow
//.........这里部分代码省略.........
Input: []InputSyncSpec{{
Type: InputSyncSpec_ORDERED,
Ordering: Ordering{Columns: []Ordering_Column{{1, Ordering_Column_ASC}}},
Streams: []StreamEndpointSpec{
{StreamID: 0, Mailbox: &MailboxSpec{}},
{StreamID: 1, Mailbox: &MailboxSpec{}},
{StreamID: StreamID(2)},
},
}},
Core: ProcessorCoreUnion{JoinReader: &jr},
Output: []OutputRouterSpec{{
Type: OutputRouterSpec_MIRROR,
Streams: []StreamEndpointSpec{{Mailbox: &MailboxSpec{SimpleResponse: true}}},
}}},
},
}
if err := SetFlowRequestTrace(ctx, req1); err != nil {
t.Fatal(err)
}
if err := SetFlowRequestTrace(ctx, req2); err != nil {
t.Fatal(err)
}
if err := SetFlowRequestTrace(ctx, req3); err != nil {
t.Fatal(err)
}
var clients []DistSQLClient
for i := 0; i < 3; i++ {
s := tc.Server(i)
conn, err := s.RPCContext().GRPCDial(s.ServingAddr())
if err != nil {
t.Fatal(err)
}
clients = append(clients, NewDistSQLClient(conn))
}
if log.V(1) {
log.Infof(ctx, "Setting up flow on 0")
}
if resp, err := clients[0].SetupFlow(ctx, req1); err != nil {
t.Fatal(err)
} else if resp.Error != nil {
t.Fatal(resp.Error)
}
if log.V(1) {
log.Infof(ctx, "Setting up flow on 1")
}
if resp, err := clients[1].SetupFlow(ctx, req2); err != nil {
t.Fatal(err)
} else if resp.Error != nil {
t.Fatal(resp.Error)
}
if log.V(1) {
log.Infof(ctx, "Running flow on 2")
}
stream, err := clients[2].RunSimpleFlow(ctx, req3)
if err != nil {
t.Fatal(err)
}
var decoder StreamDecoder
var rows sqlbase.EncDatumRows
for {
msg, err := stream.Recv()
if err != nil {
if err == io.EOF {
break
}
t.Fatal(err)
}
err = decoder.AddMessage(msg)
if err != nil {
t.Fatal(err)
}
rows = testGetDecodedRows(t, &decoder, rows)
}
if done, trailerErr := decoder.IsDone(); !done {
t.Fatal("stream not done")
} else if trailerErr != nil {
t.Fatal("error in the stream trailer:", trailerErr)
}
// The result should be all the numbers in string form, ordered by the
// digit sum (and then by number).
var results []string
for sum := 1; sum <= 50; sum++ {
for i := 1; i <= numRows; i++ {
if int(*sumDigitsFn(i).(*parser.DInt)) == sum {
results = append(results, fmt.Sprintf("['%s']", sqlutils.IntToEnglish(i)))
}
}
}
expected := strings.Join(results, " ")
expected = "[" + expected + "]"
if rowStr := rows.String(); rowStr != expected {
t.Errorf("Result: %s\n Expected: %s\n", rowStr, expected)
}
}