當前位置: 首頁>>代碼示例>>Golang>>正文


Golang SplitQueryResult.Splits方法代碼示例

本文整理匯總了Golang中github.com/youtube/vitess/go/vt/vtgate/proto.SplitQueryResult.Splits方法的典型用法代碼示例。如果您正苦於以下問題:Golang SplitQueryResult.Splits方法的具體用法?Golang SplitQueryResult.Splits怎麽用?Golang SplitQueryResult.Splits使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/youtube/vitess/go/vt/vtgate/proto.SplitQueryResult的用法示例。


在下文中一共展示了SplitQueryResult.Splits方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: SplitQuery

// SplitQuery splits a query into sub queries by appending keyranges and
// primary key range clauses. Rows corresponding to the sub queries
// are guaranteed to be non-overlapping and will add up to the rows of
// original query. Number of sub queries will be a multiple of N that is
// greater than or equal to SplitQueryRequest.SplitCount, where N is the
// number of shards.
func (vtg *VTGate) SplitQuery(ctx context.Context, req *proto.SplitQueryRequest, reply *proto.SplitQueryResult) error {
	sc := vtg.resolver.scatterConn
	keyspace, srvKeyspace, shards, err := getKeyspaceShards(ctx, sc.toposerv, sc.cell, req.Keyspace, topo.TYPE_RDONLY)
	if err != nil {
		return err
	}
	perShardSplitCount := int(math.Ceil(float64(req.SplitCount) / float64(len(shards))))
	if srvKeyspace.ShardingColumnName != "" {
		// we are using range-based sharding, so the result
		// will be a list of Splits with KeyRange clauses
		keyRangeByShard := map[string]kproto.KeyRange{}
		for _, shard := range shards {
			keyRangeByShard[shard.Name] = shard.KeyRange
		}
		splits, err := vtg.resolver.scatterConn.SplitQueryKeyRange(ctx, req.Query, req.SplitColumn, perShardSplitCount, keyRangeByShard, keyspace)
		if err != nil {
			return err
		}
		reply.Splits = splits
		return nil
	}

	// we are using custom sharding, so the result
	// will be a list of Splits with Shard clauses
	shardNames := make([]string, len(shards))
	for i, shard := range shards {
		shardNames[i] = shard.Name
	}
	splits, err := vtg.resolver.scatterConn.SplitQueryCustomSharding(ctx, req.Query, req.SplitColumn, perShardSplitCount, shardNames, keyspace)
	if err != nil {
		return err
	}
	reply.Splits = splits
	return nil
}
開發者ID:anusornc,項目名稱:vitess,代碼行數:41,代碼來源:vtgate.go

示例2: SplitQuery

// SplitQuery splits a query into sub queries by appending keyranges and
// primary key range clauses. Rows corresponding to the sub queries
// are guaranteed to be non-overlapping and will add up to the rows of
// original query. Number of sub queries will be a multiple of N that is
// greater than or equal to SplitQueryRequest.SplitCount, where N is the
// number of shards.
func (vtg *VTGate) SplitQuery(ctx context.Context, keyspace string, sql string, bindVariables map[string]interface{}, splitColumn string, splitCount int, reply *proto.SplitQueryResult) error {
	keyspace, srvKeyspace, shards, err := getKeyspaceShards(ctx, vtg.resolver.toposerv, vtg.resolver.cell, keyspace, pb.TabletType_RDONLY)
	if err != nil {
		return err
	}
	perShardSplitCount := int(math.Ceil(float64(splitCount) / float64(len(shards))))
	if srvKeyspace.ShardingColumnName != "" {
		// we are using range-based sharding, so the result
		// will be a list of Splits with KeyRange clauses
		keyRangeByShard := make(map[string]*pb.KeyRange)
		for _, shard := range shards {
			keyRangeByShard[shard.Name] = shard.KeyRange
		}
		splits, err := vtg.resolver.scatterConn.SplitQueryKeyRange(ctx, sql, bindVariables, splitColumn, perShardSplitCount, keyRangeByShard, keyspace)
		if err != nil {
			return err
		}
		reply.Splits = splits
		return nil
	}

	// we are using custom sharding, so the result
	// will be a list of Splits with Shard clauses
	shardNames := make([]string, len(shards))
	for i, shard := range shards {
		shardNames[i] = shard.Name
	}
	splits, err := vtg.resolver.scatterConn.SplitQueryCustomSharding(ctx, sql, bindVariables, splitColumn, perShardSplitCount, shardNames, keyspace)
	if err != nil {
		return err
	}
	reply.Splits = splits
	return nil
}
開發者ID:xgwubin,項目名稱:vitess,代碼行數:40,代碼來源:vtgate.go

示例3: SplitQuery

func (c *echoClient) SplitQuery(ctx context.Context, keyspace string, sql string, bindVariables map[string]interface{}, splitColumn string, splitCount int, reply *proto.SplitQueryResult) error {
	if strings.HasPrefix(sql, EchoPrefix) {
		reply.Splits = append(reply.Splits, proto.SplitQueryPart{
			Query: &proto.KeyRangeQuery{
				Sql:           fmt.Sprintf("%v:%v:%v", sql, splitColumn, splitCount),
				BindVariables: bindVariables,
				Keyspace:      keyspace,
			},
		})
		return nil
	}
	return c.fallback.SplitQuery(ctx, sql, keyspace, bindVariables, splitColumn, splitCount, reply)
}
開發者ID:yinyousong,項目名稱:vitess,代碼行數:13,代碼來源:echo.go

示例4: SplitQuery

// SplitQuery is the RPC version of vtgateservice.VTGateService method
func (vtg *VTGate) SplitQuery(ctx context.Context, request *proto.SplitQueryRequest, reply *proto.SplitQueryResult) (err error) {
	defer vtg.server.HandlePanic(&err)
	ctx, cancel := context.WithDeadline(ctx, time.Now().Add(*rpcTimeout))
	defer cancel()
	ctx = callerid.NewContext(ctx,
		callerid.GoRPCEffectiveCallerID(request.CallerID),
		callerid.NewImmediateCallerID("gorpc client"))
	splits, vtgErr := vtg.server.SplitQuery(ctx,
		request.Keyspace,
		request.Query.Sql,
		request.Query.BindVariables,
		request.SplitColumn,
		request.SplitCount)
	reply.Splits = splits
	vtgate.AddVtGateError(vtgErr, &reply.Err)
	return nil
}
開發者ID:hadmagic,項目名稱:vitess,代碼行數:18,代碼來源:server.go

示例5: SplitQuery

// SplitQuery splits a query into sub queries by appending keyranges and
// primary key range clauses. Rows corresponding to the sub queries
// are guaranteed to be non-overlapping and will add up to the rows of
// original query. Number of sub queries will be a multiple of N that is
// greater than or equal to SplitQueryRequest.SplitCount, where N is the
// number of shards.
func (vtg *VTGate) SplitQuery(context context.Context, req *proto.SplitQueryRequest, reply *proto.SplitQueryResult) (err error) {
	defer handlePanic(&err)
	sc := vtg.resolver.scatterConn
	keyspace, shards, err := getKeyspaceShards(sc.toposerv, sc.cell, req.Keyspace, topo.TYPE_RDONLY)
	if err != nil {
		return err
	}
	keyRangeByShard := map[string]kproto.KeyRange{}
	for _, shard := range shards {
		keyRangeByShard[shard.ShardName()] = shard.KeyRange
	}
	perShardSplitCount := int(math.Ceil(float64(req.SplitCount) / float64(len(shards))))
	splits, err := vtg.resolver.scatterConn.SplitQuery(context, req.Query, perShardSplitCount, keyRangeByShard, keyspace)
	if err != nil {
		return err
	}
	reply.Splits = splits
	return nil
}
開發者ID:plobsing,項目名稱:vitess,代碼行數:25,代碼來源:vtgate.go


注:本文中的github.com/youtube/vitess/go/vt/vtgate/proto.SplitQueryResult.Splits方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。