// ToPB implements PhysicalPlan ToPB interface.
422961
func (p *PhysicalLimit) ToPB(ctx sessionctx.Context) (*tipb.Executor, error) {
	limitExec := &tipb.Limit{
		Limit: p.Count,
	}
	return &tipb.Executor{Tp: tipb.ExecType_TypeLimit, Limit: limitExec}, nil
}
735014
func (a Announcement) ToProto() *pb.Announcement {
	metadata := make([]*pb.Metadata, 0, len(a.Metadata))
	for _, meta := range a.Metadata {
		metadata = append(metadata, meta.ToProto())
	}
	return &pb.Announcement{
		ID:             a.ID,
		ServiceName:    a.ServiceName,
		ServiceVersion: a.ServiceVersion,
		Description:    a.Description,
		Url:            a.URL,
		Public:         a.Public,
		NetAddress:     a.NetAddress,
		PublicKey:      a.PublicKey,
		Certificate:    a.Certificate,
		ApiAddress:     a.APIAddress,
		MqttAddress:    a.MQTTAddress,
		AmqpAddress:    a.AMQPAddress,
		Metadata:       metadata,
	}
}
1216692
func populateDB(db *sql.DB) error {
	tx, err := db.Begin()
	if err != nil {
		return err
	}
	defer tx.Rollback()
	stmt, err := tx.Prepare(pq.CopyIn("waypoints", "name", "geom"))
	if err != nil {
		return err
	}
	for _, waypoint := range []struct {
		name string
		geom *geom.Point
	}{
		{"London", geom.NewPoint(geom.XY).MustSetCoords([]float64{0.1275, 51.50722}).SetSRID(4326)},
	} {
		ewkbhexGeom, err := ewkbhex.Encode(waypoint.geom, ewkbhex.NDR)
		if err != nil {
			return err
		}
		if _, err := stmt.Exec(waypoint.name, ewkbhexGeom); err != nil {
			return err
		}
	}
	if _, err := stmt.Exec(); err != nil {
		return err
	}
	return tx.Commit()
}
827531
func (p *Apply) convert2PhysicalPlan(prop *requiredProperty) (*physicalPlanInfo, error) {
	info, err := p.getPlanInfo(prop)
	if err != nil {
		return info, errors.Trace(err)
	}
	if info != nil {
		return info, nil
	}
	if p.JoinType == InnerJoin {
		info, err = p.Join.convert2PhysicalPlanLeft(prop, true)
	} else {
		info, err = p.Join.convert2PhysicalPlanSemi(prop)
	}
	if err != nil {
		return info, errors.Trace(err)
	}
	switch info.p.(type) {
	case *PhysicalHashJoin, *PhysicalHashSemiJoin:
		ap := &PhysicalApply{
			PhysicalJoin: info.p,
			OuterSchema:  p.corCols,
		}
		ap.tp = App
		ap.allocator = p.allocator
		ap.initIDAndContext(p.ctx)
		ap.SetChildren(info.p.GetChildren()...)
		ap.SetSchema(info.p.GetSchema())
		info.p = ap
	default:
		info.cost = math.MaxFloat64
		info.p = nil
	}
	p.storePlanInfo(prop, info)
	return info, nil
}
628723
func (api tagApi) GetTopAlbums(args map[string]interface{}) (result TagGetTopAlbums, err error) {
	defer func() { appendCaller(err, "lastfm.Tag.GetTopAlbums") }()
	err = callGet("tag.gettopalbums", api.params, args, &result, P{
		"plain": []string{"tag", "limit", "page"},
	})
	return
}
696577
func (m AppIDMetadata) ToProto() *pb.Metadata {
	return &pb.Metadata{
		Metadata: &pb.Metadata_AppID{
			AppID: m.AppID,
		},
	}
}
788252
func (q *Queue) Top() *Package {
	q.lock.Lock()
	defer q.lock.Unlock()

	if len(q.jobs) > 0 {
		j := q.jobs[0]
		q.jobs = q.jobs[1:]
		return j
	}

	return nil
}
806021
func (s *nodeStack) top() *Node {
	if i := len(*s); i > 0 {
		return (*s)[i-1]
	}
	return nil
}
49775
func (c *lruCache) Top() []bitmapPair {
	a := make([]bitmapPair, 0, len(c.counts))
	for id, n := range c.counts {
		a = append(a, bitmapPair{
			ID:    id,
			Count: n,
		})
	}
	sort.Sort(bitmapPairs(a))
	return a
}
263340
func (pc PbConverter) ExprToPB(expr Expression) *tipb.Expr {
	switch x := expr.(type) {
	case *Constant, *CorrelatedColumn:
		return pc.conOrCorColToPBExpr(expr)
	case *Column:
		return pc.columnToPBExpr(x)
	case *ScalarFunction:
		return pc.scalarFuncToPBExpr(x)
	}
	return nil
}
1203960
func (p *baseLogicalPlan) findBestTask(prop *property.PhysicalProperty) (bestTask task, err error) {
	// If p is an inner plan in an IndexJoin, the IndexJoin will generate an inner plan by itself,
	// and set inner child prop nil, so here we do nothing.
	if prop == nil {
		return nil, nil
	}
	// Look up the task with this prop in the task map.
	// It's used to reduce double counting.
	bestTask = p.getTask(prop)
	if bestTask != nil {
		return bestTask, nil
	}

	if prop.TaskTp != property.RootTaskType {
		// Currently all plan cannot totally push down.
		p.storeTask(prop, invalidTask)
		return invalidTask, nil
	}

	bestTask = invalidTask
	childTasks := make([]task, 0, len(p.children))

	// If prop.enforced is true, cols of prop as parameter in exhaustPhysicalPlans should be nil
	// And reset it for enforcing task prop and storing map<prop,task>
	oldPropCols := prop.Items
	if prop.Enforced {
		// First, get the bestTask without enforced prop
		prop.Enforced = false
		bestTask, err = p.findBestTask(prop)
		if err != nil {
			return nil, err
		}
		prop.Enforced = true
		// Next, get the bestTask with enforced prop
		prop.Items = []property.Item{}
	}
	physicalPlans := p.self.exhaustPhysicalPlans(prop)
	prop.Items = oldPropCols

	for _, pp := range physicalPlans {
		// find best child tasks firstly.
		childTasks = childTasks[:0]
		for i, child := range p.children {
			childTask, err := child.findBestTask(pp.GetChildReqProps(i))
			if err != nil {
				return nil, err
			}
			if childTask != nil && childTask.invalid() {
				break
			}
			childTasks = append(childTasks, childTask)
		}

		// This check makes sure that there is no invalid child task.
		if len(childTasks) != len(p.children) {
			continue
		}

		// combine best child tasks with parent physical plan.
		curTask := pp.attach2Task(childTasks...)

		// enforce curTask property
		if prop.Enforced {
			curTask = enforceProperty(prop, curTask, p.basePlan.ctx)
		}

		// get the most efficient one.
		if curTask.cost() < bestTask.cost() {
			bestTask = curTask
		}
	}

	p.storeTask(prop, bestTask)
	return bestTask, nil
}
1223533
func (def *Synthdef) topsortr(root *Ugen, stack *stack, depth int) {
	stack.Push(root)

	var (
		inputs    = root.inputs
		numInputs = len(inputs)
	)
	for i := numInputs - 1; i >= 0; i-- {
		def.processUgenInput(inputs[i], stack, depth)
	}
}
92753
func (r *Rets) ToParams() []*Param {
	ps := make([]*Param, 0)
	if len(r.Name) > 0 {
		ps = append(ps, &Param{Name: r.Name, Type: r.Type})
	}
	if r.ReturnsError {
		ps = append(ps, &Param{Name: "err", Type: "error"})
	}
	return ps
}
1207416
func (p *parser) topLevelSegments() ([]segment, error) {
	glog.V(1).Infof("Parsing %q", p.tokens)
	segs, err := p.segments()
	if err != nil {
		return nil, err
	}
	glog.V(2).Infof("accept segments: %q; %q", p.accepted, p.tokens)
	if _, err := p.accept(typeEOF); err != nil {
		return nil, fmt.Errorf("unexpected token %q after segments %q", p.tokens[0], strings.Join(p.accepted, ""))
	}
	glog.V(2).Infof("accept eof: %q; %q", p.accepted, p.tokens)
	return segs, nil
}
420305
func (scope *Scope) ToParam() string {
	if scope.Param != "" {
		return scope.Param
	}
	return utils.ToParamString(scope.Name)
}
1224099
func (his *MemoryHistory) Top() *State {
	if his.list.Len() == 0 {
		return nil
	}
	return his.list.Front().Value.(*State)
}
595039
func flattenPushDownPlan(p PhysicalPlan) []PhysicalPlan {
	plans := make([]PhysicalPlan, 0, 5)
	for {
		plans = append(plans, p)
		if len(p.Children()) == 0 {
			break
		}
		p = p.Children()[0]
	}
	for i := 0; i < len(plans)/2; i++ {
		j := len(plans) - i - 1
		plans[i], plans[j] = plans[j], plans[i]
	}
	return plans
}