{"id":18414199,"url":"https://github.com/sdojjy/tikv-coprocessor-client","last_synced_at":"2025-10-31T02:31:14.623Z","repository":{"id":57575304,"uuid":"188174678","full_name":"sdojjy/tikv-coprocessor-client","owner":"sdojjy","description":"A tikv client for testing tikv coprocessor ","archived":false,"fork":false,"pushed_at":"2019-05-28T14:32:55.000Z","size":143,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-24T16:13:32.561Z","etag":null,"topics":["coprocessor","database","tikv"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sdojjy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-05-23T06:29:09.000Z","updated_at":"2024-12-19T07:10:32.000Z","dependencies_parsed_at":"2022-09-26T19:01:54.349Z","dependency_job_id":null,"html_url":"https://github.com/sdojjy/tikv-coprocessor-client","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sdojjy%2Ftikv-coprocessor-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sdojjy%2Ftikv-coprocessor-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sdojjy%2Ftikv-coprocessor-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sdojjy%2Ftikv-coprocessor-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sdojjy","download_url":"https://codeload.github.com/sdojjy/tikv-coprocessor-client/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239092776,"owners_count":19580215,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["coprocessor","database","tikv"],"created_at":"2024-11-06T03:49:07.872Z","updated_at":"2025-10-31T02:31:14.187Z","avatar_url":"https://github.com/sdojjy.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tikv-coprocessor-client\n\n\nThis client is based on [client-go](https://github.com/tikv/client-go), it's designed to test tikv coprocessor directly.\n\n## Feature\n\n- Insert table record and index record into tikv using tikv grpc interface.\n- Send coprocessor request to tikv and parse the response.\n\n\n\n## Init the client\nTo init the coprocessor client we need the pd address.\n```go\nclient, err := coprocessor.NewClient([]string{\"127.0.0.1:2379\"}, config.Security{})\nif err != nil {\n\tt.Fatal(\"create client failed\")\n}\n```\n\n## Insert data to tikv\nBefore you insert the data, you need a table id and index id, you can assign it manually or get it by calling [CopClient.GetTableInfo](coprocessor/table.go) method\nExamples see: [record_test](./coprocessor/record_test.go) \n\n## Send Coprocessor Request\nCheck comment in [cop](coprocessor/cop.go) file, that file defined a lot methods you can call to send coprocessor request.\nExample: see [cop_test](coprocessor/cop_test.go)\n\n## Examples\n\n- Insert data to a table with index.\n```go\npackage main\n\nimport (\n\t\"github.com/pingcap/tidb/config\"\n\t\"github.com/pingcap/tidb/types\"\n\t\"github.com/prometheus/common/log\"\n\t\"github.com/sdojjy/tikv-coprocessor-client/coprocessor\"\n)\n\nfunc main() {\n\tclient, err := coprocessor.NewClient([]string{\"127.0.0.1:2379\"}, config.Security{})\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tdefer client.Close()\n\t//create table t2 (id int , name varchar(25), key `name` (`name`));\n\ttableInfo, _ := client.GetTableInfo(\"test\", \"t2\")\n\trawData := []types.Datum{types.NewIntDatum(1), types.NewStringDatum(\"jerry\")}\n\tlog.Info(client.AddTableRecord(tableInfo.ID, 1, rawData))\n\n\tindexData := []types.Datum{types.NewStringDatum(\"jerry\")}\n\tlog.Info(client.AddIndexRecord(tableInfo.ID, tableInfo.Indices[0].ID, 1, indexData, false))\n\t//result\n\t/**\n\t  mysql\u003e  select name from t2 where name in ('jerry','ttt');\n\t  +-------+\n\t  | name  |\n\t  +-------+\n\t  | jerry |\n\t  +-------+\n\t*/\n}\n\n```\n\n- Send table scan with conditions\n\n```go\n\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"github.com/pingcap/tidb/config\"\n\t\"github.com/pingcap/tidb/types\"\n\t\"github.com/prometheus/common/log\"\n\t\"github.com/sdojjy/tikv-coprocessor-client/coprocessor\"\n)\n\nfunc main() {\n\tc, err := coprocessor.NewClient([]string{\"127.0.0.1:2379\"}, config.Security{})\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tdefer c.Close()\n\t//create table t2 (id int , name varchar(25), key `name` (`name`));\n\ttableInfo, _ := c.GetTableInfo(\"test\", \"t2\")\n\tret, _ := c.ScanTableWithConditionsAndTableInfo(context.Background(), tableInfo)\n\tprintDatum(ret)\n\tfmt.Println(\"mock table info scan\")\n\tret, _ = c.ScanTableWithConditions(context.Background(), coprocessor.InnerTableInfoToMockTableInfo(tableInfo), \"id!=1\")\n\tprintDatum(ret)\n}\n\nfunc printDatum(values [][]types.Datum) {\n\tfor _, row := range values {\n\t\tfor _, col := range row {\n\t\t\tstr, _ := col.ToString()\n\t\t\tfmt.Printf(\"%s\\t\", str)\n\t\t}\n\t\tfmt.Println()\n\t}\n}\n\n```\n\n- Send Coprocessor executors\n```go\n    ... \n\tagg, err := c.GenAggExprPB(ast.AggFuncMax, []expression.Expression{col}, false)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\treturnTypes := []*types.FieldType{types.NewFieldType(mysql.TypeFloat), types.NewFieldType(mysql.TypeVarchar)}\n\texecutors := []*tipb.Executor{\n\t\tNewTableScanExecutorWithTypes(tableInfo.ID, tableInfo.Types, false),\n\t\tNewSelectionScanExecutor([]*tipb.Expr{expr}),\n\t\tNewAggregationExecutor([]*tipb.Expr{agg}, []*tipb.Expr{c.GetGroupByPB(groupById)}),\n\t\tNewLimitExecutor(2),\n\t}\n\t...\n\tc.SendCoprocessorRequest(context.Background(), tableInfo.ID, returnTypes, executors, rangeFunc, decodeTableRow)\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsdojjy%2Ftikv-coprocessor-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsdojjy%2Ftikv-coprocessor-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsdojjy%2Ftikv-coprocessor-client/lists"}