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

Method Format

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

Format implements the NodeFormatter interface.

(ctx *FmtCtx)

Source from the content-addressed store, hash-verified

369
370// Format implements the NodeFormatter interface.
371func (node *ComparisonExpr) Format(ctx *FmtCtx) {
372 opStr := node.Operator.String()
373 // IS and IS NOT are equivalent to IS NOT DISTINCT FROM and IS DISTINCT
374 // FROM, respectively, when the RHS is true or false. We prefer the less
375 // verbose IS and IS NOT in those cases, unless we are in FmtHideConstants
376 // mode. In that mode we need the more verbose form in order to be able
377 // to re-parse the statement when reporting telemetry.
378 if !ctx.HasFlags(FmtHideConstants) {
379 if node.Operator.Symbol == treecmp.IsDistinctFrom && (node.Right == DBoolTrue || node.Right == DBoolFalse) {
380 opStr = "IS NOT"
381 } else if node.Operator.Symbol == treecmp.IsNotDistinctFrom && (node.Right == DBoolTrue || node.Right == DBoolFalse) {
382 opStr = "IS"
383 }
384 }
385 if node.Operator.Symbol.HasSubOperator() {
386 binExprFmtWithParenAndSubOp(ctx, node.Left, node.SubOperator.String(), opStr, node.Right)
387 } else {
388 binExprFmtWithParen(ctx, node.Left, opStr, node.Right, true)
389 }
390}
391
392// NewTypedComparisonExpr returns a new ComparisonExpr that is verified to be well-typed.
393func NewTypedComparisonExpr(op treecmp.ComparisonOperator, left, right TypedExpr) *ComparisonExpr {

Callers

nothing calls this directly

Calls 5

binExprFmtWithParenFunction · 0.85
HasSubOperatorMethod · 0.80
StringMethod · 0.65
HasFlagsMethod · 0.45

Tested by

no test coverage detected