本文整理汇总了Golang中github.com/pingcap/tidb/util/codec.EncodeInt函数的典型用法代码示例。如果您正苦于以下问题:Golang EncodeInt函数的具体用法?Golang EncodeInt怎么用?Golang EncodeInt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了EncodeInt函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: EncodeColumnKey
// EncodeColumnKey encodes the table id, row handle and columnID into a kv.Key
func EncodeColumnKey(tableID int64, handle int64, columnID int64) kv.Key {
buf := make([]byte, 0, recordRowKeyLen+idLen)
buf = appendTableRecordPrefix(buf, tableID)
buf = codec.EncodeInt(buf, handle)
buf = codec.EncodeInt(buf, columnID)
return buf
}
示例2: TestBuildHugeTasks
func (s *testCoprocessorSuite) TestBuildHugeTasks(c *C) {
cluster := mocktikv.NewCluster()
var splitKeys [][]byte
for ch := byte('a'); ch <= byte('z'); ch++ {
splitKeys = append(splitKeys, []byte{ch})
}
mocktikv.BootstrapWithMultiRegions(cluster, splitKeys...)
bo := NewBackoffer(3000)
cache := NewRegionCache(mocktikv.NewPDClient(cluster))
const rangesPerRegion = 1e6
ranges := make([]kv.KeyRange, 0, 26*rangesPerRegion)
for ch := byte('a'); ch <= byte('z'); ch++ {
for i := 0; i < rangesPerRegion; i++ {
start := make([]byte, 0, 9)
end := make([]byte, 0, 9)
ranges = append(ranges, kv.KeyRange{
StartKey: codec.EncodeInt(append(start, ch), int64(i*2)),
EndKey: codec.EncodeInt(append(end, ch), int64(i*2+1)),
})
}
}
_, err := buildCopTasks(bo, cache, &copRanges{mid: ranges}, false)
c.Assert(err, IsNil)
}
示例3: datumExpr
func datumExpr(d types.Datum) *tipb.Expr {
expr := new(tipb.Expr)
switch d.Kind() {
case types.KindInt64:
expr.Tp = tipb.ExprType_Int64
expr.Val = codec.EncodeInt(nil, d.GetInt64())
case types.KindUint64:
expr.Tp = tipb.ExprType_Uint64
expr.Val = codec.EncodeUint(nil, d.GetUint64())
case types.KindString:
expr.Tp = tipb.ExprType_String
expr.Val = d.GetBytes()
case types.KindBytes:
expr.Tp = tipb.ExprType_Bytes
expr.Val = d.GetBytes()
case types.KindFloat32:
expr.Tp = tipb.ExprType_Float32
expr.Val = codec.EncodeFloat(nil, d.GetFloat64())
case types.KindFloat64:
expr.Tp = tipb.ExprType_Float64
expr.Val = codec.EncodeFloat(nil, d.GetFloat64())
case types.KindMysqlDuration:
expr.Tp = tipb.ExprType_MysqlDuration
expr.Val = codec.EncodeInt(nil, int64(d.GetMysqlDuration().Duration))
case types.KindMysqlDecimal:
expr.Tp = tipb.ExprType_MysqlDecimal
expr.Val = codec.EncodeDecimal(nil, d)
default:
expr.Tp = tipb.ExprType_Null
}
return expr
}
示例4: EncodeRecordKey
// EncodeRecordKey encodes the recordPrefix, row handle and columnID into a kv.Key.
// TODO: Remove this function
func EncodeRecordKey(recordPrefix kv.Key, h int64, columnID int64) kv.Key {
buf := make([]byte, 0, len(recordPrefix)+16)
buf = append(buf, recordPrefix...)
buf = codec.EncodeInt(buf, h)
if columnID != 0 {
buf = codec.EncodeInt(buf, columnID)
}
return buf
}
示例5: TestTableCodec
// TODO: add more tests.
func (s *tableCodecSuite) TestTableCodec(c *C) {
key := EncodeRowKey(1, codec.EncodeInt(nil, 2))
h, err := DecodeRowKey(key)
c.Assert(err, IsNil)
c.Assert(h, Equals, int64(2))
key = EncodeColumnKey(1, codec.EncodeInt(nil, 2), 3)
h, err = DecodeRowKey(key)
c.Assert(err, IsNil)
c.Assert(h, Equals, int64(2))
}
示例6: tableRangesToPBRanges
func tableRangesToPBRanges(tableRanges []plan.TableRange) []*tipb.KeyRange {
hrs := make([]*tipb.KeyRange, 0, len(tableRanges))
for _, tableRange := range tableRanges {
pbRange := new(tipb.KeyRange)
pbRange.Low = codec.EncodeInt(nil, tableRange.LowVal)
hi := tableRange.HighVal
if hi != math.MaxInt64 {
hi++
}
pbRange.High = codec.EncodeInt(nil, hi)
hrs = append(hrs, pbRange)
}
return hrs
}
示例7: columnToPBExpr
func (b *executorBuilder) columnToPBExpr(client kv.Client, column *expression.Column, tbl *model.TableInfo) *tipb.Expr {
if !client.SupportRequestType(kv.ReqTypeSelect, int64(tipb.ExprType_ColumnRef)) {
return nil
}
switch column.GetType().Tp {
case mysql.TypeBit, mysql.TypeSet, mysql.TypeEnum, mysql.TypeDecimal, mysql.TypeGeometry,
mysql.TypeDate, mysql.TypeNewDate, mysql.TypeDatetime, mysql.TypeTimestamp, mysql.TypeYear:
return nil
}
id := int64(-1)
for _, col := range tbl.Columns {
if tbl.Name == column.TblName && col.Name == column.ColName {
id = col.ID
break
}
}
// Zero Column ID is not a column from table, can not support for now.
if id == 0 {
return nil
}
// TODO:If the column ID isn't in fields, it means the column is from an outer table,
// its value is available to use.
if id == -1 {
return nil
}
return &tipb.Expr{
Tp: tipb.ExprType_ColumnRef.Enum(),
Val: codec.EncodeInt(nil, id)}
}
示例8: encodeListDataKey
func (t *TxStructure) encodeListDataKey(key []byte, index int64) kv.Key {
ek := make([]byte, 0, len(t.prefix)+len(key)+36)
ek = append(ek, t.prefix...)
ek = codec.EncodeBytes(ek, key)
ek = codec.EncodeUint(ek, uint64(ListData))
return codec.EncodeInt(ek, index)
}
示例9: doTableRequest
func (e *NewXSelectIndexExec) doTableRequest(handles []int64) (*xapi.SelectResult, error) {
txn, err := e.ctx.GetTxn(false)
if err != nil {
return nil, errors.Trace(err)
}
// The handles are not in original index order, so we can't push limit here.
selTableReq := new(tipb.SelectRequest)
startTs := txn.StartTS()
selTableReq.StartTs = &startTs
selTableReq.TableInfo = &tipb.TableInfo{
TableId: proto.Int64(e.table.Meta().ID),
}
selTableReq.TableInfo.Columns = xapi.ColumnsToProto(e.indexPlan.Columns, e.table.Meta().PKIsHandle)
for _, h := range handles {
if h == math.MaxInt64 {
// We can't convert MaxInt64 into an left closed, right open range.
continue
}
pbRange := new(tipb.KeyRange)
pbRange.Low = codec.EncodeInt(nil, h)
pbRange.High = kv.Key(pbRange.Low).PrefixNext()
selTableReq.Ranges = append(selTableReq.Ranges, pbRange)
}
selTableReq.Where = e.where
// Aggregate Info
resp, err := xapi.Select(txn.GetClient(), selTableReq, defaultConcurrency)
if err != nil {
return nil, errors.Trace(err)
}
return resp, nil
}
示例10: setRow
func setRow(txn kv.Transaction, handle int64, tbl *simpleTableInfo, gen genValueFunc) error {
rowKey := tablecodec.EncodeRowKey(tbl.tID, codec.EncodeInt(nil, handle))
columnValues := gen(handle, tbl)
value, err := tablecodec.EncodeRow(columnValues, tbl.cIDs)
if err != nil {
return errors.Trace(err)
}
err = txn.Set(rowKey, value)
if err != nil {
return errors.Trace(err)
}
for i, idxCol := range tbl.indices {
idxVal := columnValues[idxCol]
encoded, err := codec.EncodeKey(nil, idxVal, types.NewDatum(handle))
if err != nil {
return errors.Trace(err)
}
idxKey := tablecodec.EncodeIndexSeekKey(tbl.tID, tbl.iIDs[i], encoded)
err = txn.Set(idxKey, []byte{0})
if err != nil {
return errors.Trace(err)
}
}
return nil
}
示例11: doTableRequest
func (e *NewXSelectIndexExec) doTableRequest(handles []int64) (xapi.SelectResult, error) {
// The handles are not in original index order, so we can't push limit here.
selTableReq := new(tipb.SelectRequest)
selTableReq.StartTs = e.txn.StartTS()
selTableReq.TableInfo = &tipb.TableInfo{
TableId: e.table.Meta().ID,
}
selTableReq.TableInfo.Columns = xapi.ColumnsToProto(e.indexPlan.Columns, e.table.Meta().PKIsHandle)
for _, h := range handles {
if h == math.MaxInt64 {
// We can't convert MaxInt64 into an left closed, right open range.
continue
}
pbRange := new(tipb.KeyRange)
pbRange.Low = codec.EncodeInt(nil, h)
pbRange.High = kv.Key(pbRange.Low).PrefixNext()
selTableReq.Ranges = append(selTableReq.Ranges, pbRange)
}
selTableReq.Where = e.where
// Aggregate Info
selTableReq.Aggregates = e.aggFuncs
selTableReq.GroupBy = e.byItems
// Aggregate Info
resp, err := xapi.Select(e.txn.GetClient(), selTableReq, defaultConcurrency, false)
if err != nil {
return nil, errors.Trace(err)
}
if e.aggregate {
// The returned rows should be aggregate partial result.
resp.SetFields(e.aggFields)
}
resp.Fetch()
return resp, nil
}
示例12: EncodeIndexSeekKey
// EncodeIndexSeekKey encodes an index value to kv.Key.
func EncodeIndexSeekKey(tableID int64, idxID int64, encodedValue []byte) kv.Key {
key := make([]byte, 0, prefixLen+len(encodedValue))
key = appendTableIndexPrefix(key, tableID)
key = codec.EncodeInt(key, idxID)
key = append(key, encodedValue...)
return key
}
示例13: columnNameToPBExpr
func (b *executorBuilder) columnNameToPBExpr(client kv.Client, column *ast.ColumnNameExpr, tn *ast.TableName) *tipb.Expr {
if !client.SupportRequestType(kv.ReqTypeSelect, int64(tipb.ExprType_ColumnRef)) {
return nil
}
// Zero Column ID is not a column from table, can not support for now.
if column.Refer.Column.ID == 0 {
return nil
}
switch column.Refer.Expr.GetType().Tp {
case mysql.TypeBit, mysql.TypeSet, mysql.TypeEnum, mysql.TypeDecimal, mysql.TypeGeometry,
mysql.TypeDate, mysql.TypeNewDate, mysql.TypeDatetime, mysql.TypeTimestamp, mysql.TypeYear:
return nil
}
matched := false
for _, f := range tn.GetResultFields() {
if f.TableName == column.Refer.TableName && f.Column.ID == column.Refer.Column.ID {
matched = true
break
}
}
if matched {
pbExpr := new(tipb.Expr)
pbExpr.Tp = tipb.ExprType_ColumnRef.Enum()
pbExpr.Val = codec.EncodeInt(nil, column.Refer.Column.ID)
return pbExpr
}
// If the column ID isn't in fields, it means the column is from an outer table,
// its value is available to use.
return b.datumToPBExpr(client, *column.Refer.Expr.GetDatum())
}
示例14: genTableIndexPrefix
// index prefix is "t[tableID]_i"
func genTableIndexPrefix(tableID int64) kv.Key {
buf := make([]byte, 0, len(TablePrefix)+8+len(indexPrefixSep))
buf = append(buf, TablePrefix...)
buf = codec.EncodeInt(buf, tableID)
buf = append(buf, indexPrefixSep...)
return buf
}
示例15: doTableRequest
func (e *XSelectIndexExec) doTableRequest(txn kv.Transaction, handles []int64) (*xapi.SelectResult, error) {
selTableReq := new(tipb.SelectRequest)
startTs := txn.StartTS()
selTableReq.StartTs = &startTs
selTableReq.TableInfo = tablecodec.TableToProto(e.indexPlan.Table)
selTableReq.Fields = resultFieldsToPBExpression(e.indexPlan.Fields())
for _, h := range handles {
if h == math.MaxInt64 {
// We can't convert MaxInt64 into an left closed, right open range.
continue
}
pbRange := new(tipb.KeyRange)
pbRange.Low = codec.EncodeInt(nil, h)
pbRange.High = codec.EncodeInt(nil, h)
selTableReq.Ranges = append(selTableReq.Ranges, pbRange)
}
selTableReq.Where = conditionsToPBExpression(e.indexPlan.FilterConditions...)
return xapi.Select(txn.GetClient(), selTableReq, 10)
}