Format implements the NodeFormatter interface.
(ctx *FmtCtx)
| 369 | |
| 370 | // Format implements the NodeFormatter interface. |
| 371 | func (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. |
| 393 | func NewTypedComparisonExpr(op treecmp.ComparisonOperator, left, right TypedExpr) *ComparisonExpr { |
nothing calls this directly
no test coverage detected