MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / Format

Method Format

pkg/sql/sem/tree/expr.go:1381–1440  ·  view source on GitHub ↗

Format implements the NodeFormatter interface.

(ctx *FmtCtx)

Source from the content-addressed store, hash-verified

1379
1380// Format implements the NodeFormatter interface.
1381func (node *FuncExpr) Format(ctx *FmtCtx) {
1382 var typ string
1383 if node.Type != 0 {
1384 typ = funcTypeName[node.Type] + " "
1385 }
1386
1387 // We let anonymization and redaction flags pass through, which will cause
1388 // built-in functions to be redacted if we have not resolved them. This is
1389 // because we cannot distinguish between built-in functions and UDFs before
1390 // they are resolved. We conservatively redact function names if requested.
1391 // TODO(111385): Investigate ways to identify built-in functions before
1392 // type-checking.
1393 //
1394 // Instruct the pretty-printer not to wrap reserved keywords in quotes. Only
1395 // builtin functions can have reserved keywords as names, and it is not
1396 // necessary (or desirable) to quote them.
1397 ctx.WithFlags(ctx.flags|FmtBareReservedKeywords, func() {
1398 ctx.FormatNode(&node.Func)
1399 })
1400
1401 if !(ctx.HasFlags(FmtFuncOnlyName) && isOnlyNameFunc(node)) {
1402 ctx.WriteByte('(')
1403 ctx.WriteString(typ)
1404 ctx.FormatNode(&node.Exprs)
1405 if node.AggType == GeneralAgg && len(node.OrderBy) > 0 {
1406 ctx.WriteByte(' ')
1407 ctx.FormatNode(&node.OrderBy)
1408 }
1409 ctx.WriteByte(')')
1410 if ctx.HasFlags(FmtParsable) && node.typ != nil {
1411 if node.fnProps.AmbiguousReturnType {
1412 // There's no type annotation available for tuples.
1413 // TODO(jordan,knz): clean this up. AmbiguousReturnType should be set only
1414 // when we should and can put an annotation here. #28579
1415 if node.typ.Family() != types.TupleFamily {
1416 ctx.WriteString(":::")
1417 ctx.Buffer.WriteString(node.typ.SQLString())
1418 }
1419 }
1420 }
1421 if node.AggType == OrderedSetAgg && len(node.OrderBy) > 0 {
1422 ctx.WriteString(" WITHIN GROUP (")
1423 ctx.FormatNode(&node.OrderBy)
1424 ctx.WriteString(")")
1425 }
1426 if node.Filter != nil {
1427 ctx.WriteString(" FILTER (WHERE ")
1428 ctx.FormatNode(node.Filter)
1429 ctx.WriteString(")")
1430 }
1431 if window := node.WindowDef; window != nil {
1432 ctx.WriteString(" OVER ")
1433 if window.Name != "" {
1434 ctx.FormatNode(&window.Name)
1435 } else {
1436 ctx.FormatNode(window)
1437 }
1438 }

Callers

nothing calls this directly

Calls 6

isOnlyNameFuncFunction · 0.85
WithFlagsMethod · 0.80
FormatNodeMethod · 0.80
FamilyMethod · 0.80
SQLStringMethod · 0.65
HasFlagsMethod · 0.45

Tested by

no test coverage detected