|
| 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.export; |
| 11 | + |
| 12 | +import net.sf.jsqlparser.expression.Expression; |
| 13 | +import net.sf.jsqlparser.expression.operators.relational.ExpressionList; |
| 14 | +import net.sf.jsqlparser.statement.Statement; |
| 15 | +import net.sf.jsqlparser.statement.StatementVisitor; |
| 16 | +import net.sf.jsqlparser.statement.select.Select; |
| 17 | + |
| 18 | +/** |
| 19 | + * BigQuery's {@code EXPORT DATA [WITH CONNECTION connection] OPTIONS (option_list) AS query}. |
| 20 | + * |
| 21 | + * @see <a href= |
| 22 | + * "https://cloud.google.com/bigquery/docs/reference/standard-sql/export-statements">Export |
| 23 | + * statements</a> |
| 24 | + */ |
| 25 | +public class ExportDataStatement implements Statement { |
| 26 | + private String connectionName; |
| 27 | + private ExpressionList<Expression> options; |
| 28 | + private Select select; |
| 29 | + |
| 30 | + public String getConnectionName() { |
| 31 | + return connectionName; |
| 32 | + } |
| 33 | + |
| 34 | + public void setConnectionName(String connectionName) { |
| 35 | + this.connectionName = connectionName; |
| 36 | + } |
| 37 | + |
| 38 | + public ExportDataStatement withConnectionName(String connectionName) { |
| 39 | + setConnectionName(connectionName); |
| 40 | + return this; |
| 41 | + } |
| 42 | + |
| 43 | + public ExpressionList<Expression> getOptions() { |
| 44 | + return options; |
| 45 | + } |
| 46 | + |
| 47 | + public void setOptions(ExpressionList<Expression> options) { |
| 48 | + this.options = options; |
| 49 | + } |
| 50 | + |
| 51 | + public ExportDataStatement withOptions(ExpressionList<Expression> options) { |
| 52 | + setOptions(options); |
| 53 | + return this; |
| 54 | + } |
| 55 | + |
| 56 | + public Select getSelect() { |
| 57 | + return select; |
| 58 | + } |
| 59 | + |
| 60 | + public void setSelect(Select select) { |
| 61 | + this.select = select; |
| 62 | + } |
| 63 | + |
| 64 | + public ExportDataStatement withSelect(Select select) { |
| 65 | + setSelect(select); |
| 66 | + return this; |
| 67 | + } |
| 68 | + |
| 69 | + public StringBuilder appendTo(StringBuilder builder) { |
| 70 | + builder.append("EXPORT DATA"); |
| 71 | + if (connectionName != null) { |
| 72 | + builder.append(" WITH CONNECTION ").append(connectionName); |
| 73 | + } |
| 74 | + if (options != null) { |
| 75 | + builder.append(" OPTIONS (").append(options).append(")"); |
| 76 | + } |
| 77 | + builder.append(" AS ").append(select); |
| 78 | + return builder; |
| 79 | + } |
| 80 | + |
| 81 | + @Override |
| 82 | + public String toString() { |
| 83 | + return appendTo(new StringBuilder()).toString(); |
| 84 | + } |
| 85 | + |
| 86 | + @Override |
| 87 | + public <T, S> T accept(StatementVisitor<T> statementVisitor, S context) { |
| 88 | + return statementVisitor.visit(this, context); |
| 89 | + } |
| 90 | +} |
0 commit comments