本文整理汇总了Golang中github.com/pingcap/tidb/kv.Client.SupportRequestType方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.SupportRequestType方法的具体用法?Golang Client.SupportRequestType怎么用?Golang Client.SupportRequestType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/pingcap/tidb/kv.Client
的用法示例。
在下文中一共展示了Client.SupportRequestType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: aggFuncToPBExpr
func aggFuncToPBExpr(sc *variable.StatementContext, client kv.Client, aggFunc expression.AggregationFunction) *tipb.Expr {
pc := pbConverter{client: client, sc: sc}
var tp tipb.ExprType
switch aggFunc.GetName() {
case ast.AggFuncCount:
tp = tipb.ExprType_Count
case ast.AggFuncFirstRow:
tp = tipb.ExprType_First
case ast.AggFuncGroupConcat:
tp = tipb.ExprType_GroupConcat
case ast.AggFuncMax:
tp = tipb.ExprType_Max
case ast.AggFuncMin:
tp = tipb.ExprType_Min
case ast.AggFuncSum:
tp = tipb.ExprType_Sum
case ast.AggFuncAvg:
tp = tipb.ExprType_Avg
}
if !client.SupportRequestType(kv.ReqTypeSelect, int64(tp)) {
return nil
}
children := make([]*tipb.Expr, 0, len(aggFunc.GetArgs()))
for _, arg := range aggFunc.GetArgs() {
pbArg := pc.exprToPB(arg)
if pbArg == nil {
return nil
}
children = append(children, pbArg)
}
return &tipb.Expr{Tp: tp, Children: children}
}
示例2: newAggFuncToPBExpr
func (b *executorBuilder) newAggFuncToPBExpr(client kv.Client, aggFunc expression.AggregationFunction,
tbl *model.TableInfo) *tipb.Expr {
var tp tipb.ExprType
switch aggFunc.GetName() {
case ast.AggFuncCount:
tp = tipb.ExprType_Count
case ast.AggFuncFirstRow:
tp = tipb.ExprType_First
case ast.AggFuncGroupConcat:
tp = tipb.ExprType_GroupConcat
case ast.AggFuncMax:
tp = tipb.ExprType_Max
case ast.AggFuncMin:
tp = tipb.ExprType_Min
case ast.AggFuncSum:
tp = tipb.ExprType_Sum
case ast.AggFuncAvg:
tp = tipb.ExprType_Avg
}
if !client.SupportRequestType(kv.ReqTypeSelect, int64(tp)) {
return nil
}
children := make([]*tipb.Expr, 0, len(aggFunc.GetArgs()))
for _, arg := range aggFunc.GetArgs() {
pbArg := b.newExprToPBExpr(client, arg, tbl)
if pbArg == nil {
return nil
}
children = append(children, pbArg)
}
return &tipb.Expr{Tp: tp.Enum(), Children: children}
}
示例3: 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())
}
示例4: 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)}
}
示例5: aggFuncToPBExpr
func (b *executorBuilder) aggFuncToPBExpr(client kv.Client, af *ast.AggregateFuncExpr, tn *ast.TableName) *tipb.Expr {
name := strings.ToLower(af.F)
var tp tipb.ExprType
switch name {
case ast.AggFuncCount:
tp = tipb.ExprType_Count
case ast.AggFuncFirstRow:
tp = tipb.ExprType_First
case ast.AggFuncGroupConcat:
tp = tipb.ExprType_GroupConcat
case ast.AggFuncMax:
tp = tipb.ExprType_Max
case ast.AggFuncMin:
tp = tipb.ExprType_Min
case ast.AggFuncSum:
tp = tipb.ExprType_Sum
case ast.AggFuncAvg:
tp = tipb.ExprType_Avg
}
if !client.SupportRequestType(kv.ReqTypeSelect, int64(tp)) {
return nil
}
// convert it to pb
children := make([]*tipb.Expr, 0, len(af.Args))
for _, arg := range af.Args {
pbArg := b.exprToPBExpr(client, arg, tn)
if pbArg == nil {
return nil
}
children = append(children, pbArg)
}
return &tipb.Expr{Tp: tp.Enum(), Children: children}
}
示例6: bitwiseFuncToPBExpr
func bitwiseFuncToPBExpr(client kv.Client, expr *expression.ScalarFunction) *tipb.Expr {
var tp tipb.ExprType
switch expr.FuncName.L {
case ast.And:
tp = tipb.ExprType_BitAnd
case ast.Or:
tp = tipb.ExprType_BitOr
case ast.Xor:
tp = tipb.ExprType_BitXor
case ast.LeftShift:
tp = tipb.ExprType_LeftShift
case ast.RightShift:
tp = tipb.ExprType_RighShift
case ast.BitNeg:
return bitNegToPBExpr(client, expr)
}
if !client.SupportRequestType(kv.ReqTypeSelect, int64(tp)) {
return nil
}
expr0 := exprToPB(client, expr.Args[0])
if expr0 == nil {
return nil
}
expr1 := exprToPB(client, expr.Args[1])
if expr1 == nil {
return nil
}
return &tipb.Expr{
Tp: tp,
Children: []*tipb.Expr{expr0, expr1}}
}
示例7: logicalOpsToPBExpr
func logicalOpsToPBExpr(client kv.Client, expr *expression.ScalarFunction) *tipb.Expr {
var tp tipb.ExprType
switch expr.FuncName.L {
case ast.AndAnd:
tp = tipb.ExprType_And
case ast.OrOr:
tp = tipb.ExprType_Or
case ast.LogicXor:
tp = tipb.ExprType_Xor
case ast.UnaryNot:
return notToPBExpr(client, expr)
}
if !client.SupportRequestType(kv.ReqTypeSelect, int64(tp)) {
return nil
}
expr0 := exprToPB(client, expr.Args[0])
if expr0 == nil {
return nil
}
expr1 := exprToPB(client, expr.Args[1])
if expr1 == nil {
return nil
}
return &tipb.Expr{
Tp: tp,
Children: []*tipb.Expr{expr0, expr1}}
}
示例8: arithmeticalOpsToPBExpr
func arithmeticalOpsToPBExpr(client kv.Client, expr *expression.ScalarFunction) *tipb.Expr {
var tp tipb.ExprType
switch expr.FuncName.L {
case ast.Plus:
tp = tipb.ExprType_Plus
case ast.Minus:
tp = tipb.ExprType_Minus
case ast.Mul:
tp = tipb.ExprType_Mul
case ast.Div:
tp = tipb.ExprType_Div
case ast.Mod:
tp = tipb.ExprType_Mod
case ast.IntDiv:
tp = tipb.ExprType_IntDiv
}
if !client.SupportRequestType(kv.ReqTypeSelect, int64(tp)) {
return nil
}
expr0 := exprToPB(client, expr.Args[0])
if expr0 == nil {
return nil
}
expr1 := exprToPB(client, expr.Args[1])
if expr1 == nil {
return nil
}
return &tipb.Expr{
Tp: tp,
Children: []*tipb.Expr{expr0, expr1}}
}
示例9: compareOpsToPBExpr
func compareOpsToPBExpr(client kv.Client, expr *expression.ScalarFunction) *tipb.Expr {
var tp tipb.ExprType
switch expr.FuncName.L {
case ast.LT:
tp = tipb.ExprType_LT
case ast.LE:
tp = tipb.ExprType_LE
case ast.EQ:
tp = tipb.ExprType_EQ
case ast.NE:
tp = tipb.ExprType_NE
case ast.GE:
tp = tipb.ExprType_GE
case ast.GT:
tp = tipb.ExprType_GT
case ast.NullEQ:
tp = tipb.ExprType_NullEQ
case ast.In:
return inToPBExpr(client, expr)
case ast.Like:
// Only patterns like 'abc', '%abc', 'abc%', '%abc%' can be converted to *tipb.Expr for now.
escape := expr.Args[2].(*expression.Constant).Value
if escape.IsNull() || byte(escape.GetInt64()) != '\\' {
return nil
}
pattern, ok := expr.Args[1].(*expression.Constant)
if !ok || pattern.Value.Kind() != types.KindString {
return nil
}
for i, b := range pattern.Value.GetString() {
switch b {
case '\\', '_':
return nil
case '%':
if i != 0 && i != len(pattern.Value.GetString())-1 {
return nil
}
}
}
tp = tipb.ExprType_Like
}
if !client.SupportRequestType(kv.ReqTypeSelect, int64(tp)) {
return nil
}
expr0 := exprToPB(client, expr.Args[0])
if expr0 == nil {
return nil
}
expr1 := exprToPB(client, expr.Args[1])
if expr1 == nil {
return nil
}
return &tipb.Expr{
Tp: tp,
Children: []*tipb.Expr{expr0, expr1}}
}
示例10: scalarFuncToPBExpr
func (b *executorBuilder) scalarFuncToPBExpr(client kv.Client, expr *expression.ScalarFunction,
tbl *model.TableInfo) *tipb.Expr {
var tp tipb.ExprType
switch expr.FuncName.L {
case ast.LT:
tp = tipb.ExprType_LT
case ast.LE:
tp = tipb.ExprType_LE
case ast.EQ:
tp = tipb.ExprType_EQ
case ast.NE:
tp = tipb.ExprType_NE
case ast.GE:
tp = tipb.ExprType_GE
case ast.GT:
tp = tipb.ExprType_GT
case ast.NullEQ:
tp = tipb.ExprType_NullEQ
case ast.And:
tp = tipb.ExprType_And
case ast.Or:
tp = tipb.ExprType_Or
// It's the operation for unary operator.
case ast.UnaryNot:
tp = tipb.ExprType_Not
default:
return nil
}
if !client.SupportRequestType(kv.ReqTypeSelect, int64(tp)) {
return nil
}
if len(expr.Args) == 1 {
child := b.newExprToPBExpr(client, expr.Args[0], tbl)
if child == nil {
return nil
}
return &tipb.Expr{
Tp: tp.Enum(),
Children: []*tipb.Expr{child}}
}
leftExpr := b.newExprToPBExpr(client, expr.Args[0], tbl)
if leftExpr == nil {
return nil
}
rightExpr := b.newExprToPBExpr(client, expr.Args[1], tbl)
if rightExpr == nil {
return nil
}
return &tipb.Expr{
Tp: tp.Enum(),
Children: []*tipb.Expr{leftExpr, rightExpr}}
}
示例11: notToPBExpr
func notToPBExpr(client kv.Client, expr *expression.ScalarFunction) *tipb.Expr {
if !client.SupportRequestType(kv.ReqTypeSelect, int64(tipb.ExprType_Not)) {
return nil
}
child := exprToPB(client, expr.Args[0])
if child == nil {
return nil
}
return &tipb.Expr{
Tp: tipb.ExprType_Not,
Children: []*tipb.Expr{child}}
}
示例12: notToPBExpr
func (b *executorBuilder) notToPBExpr(client kv.Client, expr *expression.ScalarFunction, tbl *model.TableInfo) *tipb.Expr {
if !client.SupportRequestType(kv.ReqTypeSelect, int64(tipb.ExprType_Not)) {
return nil
}
child := b.newExprToPBExpr(client, expr.Args[0], tbl)
if child == nil {
return nil
}
return &tipb.Expr{
Tp: tipb.ExprType_Not.Enum(),
Children: []*tipb.Expr{child}}
}
示例13: unaryToPBExpr
func (b *executorBuilder) unaryToPBExpr(client kv.Client, expr *ast.UnaryOperationExpr, tn *ast.TableName) *tipb.Expr {
switch expr.Op {
case opcode.Not:
if !client.SupportRequestType(kv.ReqTypeSelect, int64(tipb.ExprType_Not)) {
return nil
}
default:
return nil
}
child := b.exprToPBExpr(client, expr.V, tn)
if child == nil {
return nil
}
return &tipb.Expr{Tp: tipb.ExprType_Not.Enum(), Children: []*tipb.Expr{child}}
}
示例14: inToPBExpr
func (b *executorBuilder) inToPBExpr(client kv.Client, expr *expression.ScalarFunction, tbl *model.TableInfo) *tipb.Expr {
if !client.SupportRequestType(kv.ReqTypeSelect, int64(tipb.ExprType_In)) {
return nil
}
pbExpr := b.newExprToPBExpr(client, expr.Args[0], tbl)
if pbExpr == nil {
return nil
}
listExpr := b.constListToPBExpr(client, expr.Args[1:], tbl)
if listExpr == nil {
return nil
}
return &tipb.Expr{
Tp: tipb.ExprType_In.Enum(),
Children: []*tipb.Expr{pbExpr, listExpr}}
}
示例15: inToPBExpr
func inToPBExpr(client kv.Client, expr *expression.ScalarFunction) *tipb.Expr {
if !client.SupportRequestType(kv.ReqTypeSelect, int64(tipb.ExprType_In)) {
return nil
}
pbExpr := exprToPB(client, expr.Args[0])
if pbExpr == nil {
return nil
}
listExpr := constListToPB(client, expr.Args[1:])
if listExpr == nil {
return nil
}
return &tipb.Expr{
Tp: tipb.ExprType_In,
Children: []*tipb.Expr{pbExpr, listExpr}}
}