// createFunctionCursor creates a new cursor that calls a function on one of the columns
// and returns the result.
507104
func createFunctionCursor(t *transpilerState, call *influxql.Call, in cursor, normalize bool) (cursor, error) {
	cur := &functionCursor{
		call:   call,
		parent: in,
	}
	switch call.Name {
	case "count", "min", "max", "sum", "first", "last", "mean":
		value, ok := in.Value(call.Args[0])
		if !ok {
			return nil, fmt.Errorf("undefined variable: %s", call.Args[0])
		}
		cur.expr = &ast.PipeExpression{
			Argument: in.Expr(),
			Call: &ast.CallExpression{
				Callee: &ast.Identifier{
					Name: call.Name,
				},
			},
		}
		cur.value = value
		cur.exclude = map[influxql.Expr]struct{}{call.Args[0]: {}}
	case "median":
		value, ok := in.Value(call.Args[0])
		if !ok {
			return nil, fmt.Errorf("undefined variable: %s", call.Args[0])
		}
		cur.expr = &ast.PipeExpression{
			Argument: in.Expr(),
			Call: &ast.CallExpression{
				Callee: &ast.Identifier{
					Name: "percentile",
				},
				Arguments: []ast.Expression{
					&ast.ObjectExpression{
						Properties: []*ast.Property{
							{
								Key: &ast.Identifier{
									Name: "percentile",
								},
								Value: &ast.FloatLiteral{
									Value: 0.5,
								},
							},
							{
								Key: &ast.Identifier{
									Name: "method",
								},
								Value: &ast.StringLiteral{
									Value: "exact_mean",
								},
							},
						},
					},
				},
			},
		}
		cur.value = value
		cur.exclude = map[influxql.Expr]struct{}{call.Args[0]: {}}
	case "percentile":
		if len(call.Args) != 2 {
			return nil, errors.New("percentile function requires two arguments field_key and N")
		}

		fieldName, ok := in.Value(call.Args[0])
		if !ok {
			return nil, fmt.Errorf("undefined variable: %s", call.Args[0])
		}

		var percentile float64
		switch arg := call.Args[1].(type) {
		case *influxql.NumberLiteral:
			percentile = arg.Val / 100.0
		case *influxql.IntegerLiteral:
			percentile = float64(arg.Val) / 100.0
		default:
			return nil, errors.New("argument N must be a float type")
		}

		if percentile < 0 || percentile > 1 {
			return nil, errors.New("argument N must be between 0 and 100")
		}

		args := []*ast.Property{
			{
				Key: &ast.Identifier{
					Name: "percentile",
				},
				Value: &ast.FloatLiteral{
					Value: percentile,
				},
			},
			{
				Key: &ast.Identifier{
					Name: "method",
				},
				Value: &ast.StringLiteral{
					Value: "exact_selector",
				},
			},
		}
		if fieldName != execute.DefaultValueColLabel {
			args = append(args, &ast.Property{
				Key: &ast.Identifier{
					Name: "columns",
				},
				Value: &ast.ArrayExpression{
					Elements: []ast.Expression{
						&ast.StringLiteral{Value: fieldName},
					},
				},
			})
		}
		cur.expr = &ast.PipeExpression{
			Argument: in.Expr(),
			Call: &ast.CallExpression{
				Callee: &ast.Identifier{
					Name: "percentile",
				},
				Arguments: []ast.Expression{
					&ast.ObjectExpression{
						Properties: args,
					},
				},
			},
		}
		cur.value = fieldName
		cur.exclude = map[influxql.Expr]struct{}{call.Args[0]: {}}
	default:
		return nil, fmt.Errorf("unimplemented function: %q", call.Name)
	}

	// If we have been told to normalize the time, we do it here.
	if normalize {
		if influxql.IsSelector(call) {
			cur.expr = &ast.PipeExpression{
				Argument: cur.expr,
				Call: &ast.CallExpression{
					Callee: &ast.Identifier{
						Name: "drop",
					},
					Arguments: []ast.Expression{
						&ast.ObjectExpression{
							Properties: []*ast.Property{{
								Key: &ast.Identifier{
									Name: "columns",
								},
								Value: &ast.ArrayExpression{
									Elements: []ast.Expression{
										&ast.StringLiteral{Value: execute.DefaultTimeColLabel},
									},
								},
							}},
						},
					},
				},
			}
		}
		cur.expr = &ast.PipeExpression{
			Argument: cur.expr,
			Call: &ast.CallExpression{
				Callee: &ast.Identifier{
					Name: "duplicate",
				},
				Arguments: []ast.Expression{
					&ast.ObjectExpression{
						Properties: []*ast.Property{
							{
								Key: &ast.Identifier{
									Name: "column",
								},
								Value: &ast.StringLiteral{
									Value: execute.DefaultStartColLabel,
								},
							},
							{
								Key: &ast.Identifier{
									Name: "as",
								},
								Value: &ast.StringLiteral{
									Value: execute.DefaultTimeColLabel,
								},
							},
						},
					},
				},
			},
		}
	}
	return cur, nil
}
296339
func (c *QueuesListCall) Cursor(cursor string) *QueuesListCall {
	c.urlParams_.Set("cursor", cursor)
	return c
}
355614
func SetCursor(c Cursor) {
	var cur *glfw.Cursor
	switch c {
	case CursorNone:
		cur = nil // just for the documentation, this isn't required
	case CursorArrow:
		cur = cursorArrow
	case CursorCrosshair:
		cur = cursorCrosshair
	case CursorHand:
		cur = cursorHand
	case CursorIBeam:
		cur = cursorIBeam
	case CursorHResize:
		cur = cursorHResize
	case CursorVResize:
		cur = cursorVResize
	}
	Window.SetCursor(cur)
}
1251847
func (tp *TicketPool) Cursor() int64 {
	tp.mtx.RLock()
	defer tp.mtx.RUnlock()
	return tp.cursor
}
774511
func NewFunctionInternal(ctx sessionctx.Context, funcName string, retType *types.FieldType, args ...Expression) Expression {
	expr, err := NewFunction(ctx, funcName, retType, args...)
	terror.Log(err)
	return expr
}
487064
func (m *MockLambdaAPI) CreateFunction(arg0 *lambda.CreateFunctionInput) (*lambda.FunctionConfiguration, error) {
	ret := m.ctrl.Call(m, "CreateFunction", arg0)
	ret0, _ := ret[0].(*lambda.FunctionConfiguration)
	ret1, _ := ret[1].(error)
	return ret0, ret1
}
286990
func (m *postgresMigrator) createTableIfNotExists() error {
	_, err := m.db.Exec(m.createTable())
	return err
}
1347534
func (b *Bucket) Cursor() (kv.Cursor, error) {
	return &Cursor{
		cursor: b.bucket.Cursor(),
	}, nil
}
1170685
func newKeyCursor(ctx context.Context, fs *FileStore, key []byte, t int64, ascending bool) *KeyCursor {
	c := &KeyCursor{
		key:       key,
		seeks:     fs.locations(key, t, ascending),
		ctx:       ctx,
		col:       metrics.GroupFromContext(ctx),
		ascending: ascending,
	}

	if ascending {
		sort.Sort(ascLocations(c.seeks))
	} else {
		sort.Sort(descLocations(c.seeks))
	}

	// Determine the distinct set of TSM files in use and mark then as in-use
	for _, f := range c.seeks {
		f.r.Ref()
	}

	c.seek(t)
	return c
}
904943
func (fm FunctionMap) AddFunction(name string, function Function) {
	fm[name] = function
}
380505
func (lu *LookupUnique) Create(vcursor VCursor, rowsColValues [][]sqltypes.Value, ksids [][]byte, ignoreMode bool) error {
	return lu.lkp.Create(vcursor, rowsColValues, ksidsToValues(ksids), ignoreMode)
}
996930
func (a *CellView) SetCursor(x, y int) {
	a.cursorX = x
	a.cursorY = y
	a.model.SetCursor(x, y)
}
663884
func (db *SQLDB) createTableTriggers(table *types.SQLTable) error {
	// If the adapter supports notification triggers
	dbNotify, ok := db.DBAdapter.(adapters.DBNotifyTriggerAdapter)
	if ok {
		for channel, columns := range table.NotifyChannels {
			function := fmt.Sprintf("%s_%s_notify_function", table.Name, channel)

			query := dbNotify.CreateNotifyFunctionQuery(function, channel, columns...)
			db.Log.Info("msg", "CREATE NOTIFICATION FUNCTION", "query", query)
			_, err := db.DB.Exec(query)
			if err != nil {
				return fmt.Errorf("could not create notification function: %v", err)
			}

			trigger := fmt.Sprintf("%s_%s_notify_trigger", table.Name, channel)
			query = dbNotify.CreateTriggerQuery(trigger, table.Name, function)
			db.Log.Info("msg", "CREATE NOTIFICATION TRIGGER", "query", query)
			_, err = db.DB.Exec(query)
			if err != nil {
				return fmt.Errorf("could not create notification trigger: %v", err)
			}
		}
	}
	return nil
}
479141
func (hd *HD44780) SetCursor(col, row int) error {
	return hd.SetDDRamAddr(byte(col) + hd.lcdRowOffset(row))
}
526148
func makeFunction(attributes []string) func(interface{}) string {
	return func(text interface{}) string {
		return fmt.Sprintf("\033[%sm%s\033[0m", strings.Join(attributes, ";"), text)
	}
}
1090133
func Cursor(cursor string) DeviceRequestOption {
	return func(opts *deviceRequestOpts) error {
		opts.Cursor = cursor
		return nil
	}
}
1200409
func newFunctionSelector(awsSession *session.Session,
	stackResources []*cloudformation.StackResource,
	app *tview.Application,
	lambdaAWSInfos []*LambdaAWSInfo,
	settings map[string]string,
	onChangeBroadcaster broadcast.Broadcaster,
	logger *logrus.Logger) (tview.Primitive, []tview.Primitive) {

	lambdaARN := func(stackID string, logicalName string) string {
		// stackID: arn:aws:cloudformation:us-west-2:123412341234:stack/MyHelloWorldStack-mweagle/54339e80-6686-11e8-90cd-503f20f2ad82
		// lambdaARN: arn:aws:lambda:us-west-2:123412341234:function:MyHelloWorldStack-mweagle_Hello_World
		stackParts := strings.Split(stackID, ":")
		lambdaARNParts := []string{
			"arn:aws:lambda:",
			stackParts[3],
			":",
			stackParts[4],
			":function:",
			logicalName,
		}
		return strings.Join(lambdaARNParts, "")
	}
	// Ok, walk the resources and assemble all the ARNs for the lambda functions
	lambdaFunctionARNs := []string{}
	for _, eachResource := range stackResources {
		if *eachResource.ResourceType == "AWS::Lambda::Function" {
			logger.WithField("Resource", *eachResource.LogicalResourceId).Debug("Found provisioned Lambda function")
			lambdaFunctionARNs = append(lambdaFunctionARNs, lambdaARN(*eachResource.StackId, *eachResource.PhysicalResourceId))
		}
	}
	sort.Strings(lambdaFunctionARNs)
	selectedARN := settings[settingSelectedARN]
	selectedIndex := 0
	for index, eachARN := range lambdaFunctionARNs {
		if eachARN == selectedARN {
			selectedIndex = index
			break
		}
	}
	dropdown := tview.NewDropDown().
		SetCurrentOption(selectedIndex).
		SetLabel("Function ARN: ").
		SetOptions(lambdaFunctionARNs, nil)
	dropdown.SetBorder(true).SetTitle("Select Function")

	dropdownDoneFunc := func(key tcell.Key) {
		selectedIndex, value := dropdown.GetCurrentOption()
		if selectedIndex != -1 {
			saveSetting(settingSelectedARN, value)
			onChangeBroadcaster.Submit(value)
		}
	}
	dropdown.SetDoneFunc(dropdownDoneFunc)
	// Populate it...
	dropdownDoneFunc(tcell.KeyEnter)
	return dropdown, []tview.Primitive{dropdown}
}