|
| 1 | +/*- |
| 2 | + * #%L |
| 3 | + * JSQLParser library |
| 4 | + * %% |
| 5 | + * Copyright (C) 2004 - 2026 JSQLParser |
| 6 | + * %% |
| 7 | + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 |
| 8 | + * #L% |
| 9 | + */ |
| 10 | +package net.sf.jsqlparser.statement; |
| 11 | + |
| 12 | +import net.sf.jsqlparser.expression.Expression; |
| 13 | +import net.sf.jsqlparser.expression.StringValue; |
| 14 | + |
| 15 | +/** |
| 16 | + * BigQuery's {@code ASSERT expression [AS description]}, which fails the script when the expression |
| 17 | + * does not evaluate to {@code TRUE}. |
| 18 | + * |
| 19 | + * @see <a href= |
| 20 | + * "https://cloud.google.com/bigquery/docs/reference/standard-sql/debugging-statements">Debugging |
| 21 | + * statements</a> |
| 22 | + */ |
| 23 | +public class AssertStatement implements Statement { |
| 24 | + private Expression expression; |
| 25 | + private StringValue description; |
| 26 | + |
| 27 | + public AssertStatement() {} |
| 28 | + |
| 29 | + public AssertStatement(Expression expression) { |
| 30 | + this.expression = expression; |
| 31 | + } |
| 32 | + |
| 33 | + public AssertStatement(Expression expression, StringValue description) { |
| 34 | + this.expression = expression; |
| 35 | + this.description = description; |
| 36 | + } |
| 37 | + |
| 38 | + public Expression getExpression() { |
| 39 | + return expression; |
| 40 | + } |
| 41 | + |
| 42 | + public void setExpression(Expression expression) { |
| 43 | + this.expression = expression; |
| 44 | + } |
| 45 | + |
| 46 | + public AssertStatement withExpression(Expression expression) { |
| 47 | + setExpression(expression); |
| 48 | + return this; |
| 49 | + } |
| 50 | + |
| 51 | + public StringValue getDescription() { |
| 52 | + return description; |
| 53 | + } |
| 54 | + |
| 55 | + public void setDescription(StringValue description) { |
| 56 | + this.description = description; |
| 57 | + } |
| 58 | + |
| 59 | + public AssertStatement withDescription(StringValue description) { |
| 60 | + setDescription(description); |
| 61 | + return this; |
| 62 | + } |
| 63 | + |
| 64 | + public StringBuilder appendTo(StringBuilder builder) { |
| 65 | + builder.append("ASSERT ").append(expression); |
| 66 | + if (description != null) { |
| 67 | + builder.append(" AS ").append(description); |
| 68 | + } |
| 69 | + return builder; |
| 70 | + } |
| 71 | + |
| 72 | + @Override |
| 73 | + public String toString() { |
| 74 | + return appendTo(new StringBuilder()).toString(); |
| 75 | + } |
| 76 | + |
| 77 | + @Override |
| 78 | + public <T, S> T accept(StatementVisitor<T> statementVisitor, S context) { |
| 79 | + return statementVisitor.visit(this, context); |
| 80 | + } |
| 81 | +} |
0 commit comments