Repository navigation
Expand file tree
/
Copy pathLoadDataStatement.java
More file actions
177 lines (148 loc) · 5.32 KB
/
Copy pathLoadDataStatement.java
File metadata and controls
177 lines (148 loc) · 5.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2026 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.statement.load;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.operators.relational.ExpressionList;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
import net.sf.jsqlparser.schema.Table;
import net.sf.jsqlparser.statement.Statement;
import net.sf.jsqlparser.statement.StatementVisitor;
import net.sf.jsqlparser.statement.create.table.ColumnDefinition;
import net.sf.jsqlparser.statement.select.PlainSelect;
import java.util.List;
import java.util.function.Consumer;
/**
* BigQuery's {@code LOAD DATA {INTO | OVERWRITE} table [(column_definitions)] [OPTIONS
* (option_list)] FROM FILES (file_options) [WITH PARTITION COLUMNS] [WITH CONNECTION connection]}.
*
* @see <a href=
* "https://cloud.google.com/bigquery/docs/reference/standard-sql/load-statements">Load
* statements</a>
*/
public class LoadDataStatement extends ASTNodeAccessImpl implements Statement {
private boolean overwrite;
private Table table;
private List<ColumnDefinition> columnDefinitions;
private ExpressionList<?> options;
private ExpressionList<?> fileOptions;
private boolean withPartitionColumns;
private String connectionName;
public boolean isOverwrite() {
return overwrite;
}
public void setOverwrite(boolean overwrite) {
this.overwrite = overwrite;
}
public LoadDataStatement withOverwrite(boolean overwrite) {
setOverwrite(overwrite);
return this;
}
public Table getTable() {
return table;
}
public void setTable(Table table) {
this.table = table;
}
public LoadDataStatement withTable(Table table) {
setTable(table);
return this;
}
public List<ColumnDefinition> getColumnDefinitions() {
return columnDefinitions;
}
public void setColumnDefinitions(List<ColumnDefinition> columnDefinitions) {
this.columnDefinitions = columnDefinitions;
}
public LoadDataStatement withColumnDefinitions(List<ColumnDefinition> columnDefinitions) {
setColumnDefinitions(columnDefinitions);
return this;
}
public ExpressionList<?> getOptions() {
return options;
}
public void setOptions(ExpressionList<?> options) {
this.options = options;
}
public LoadDataStatement withOptions(ExpressionList<?> options) {
setOptions(options);
return this;
}
public ExpressionList<?> getFileOptions() {
return fileOptions;
}
public void setFileOptions(ExpressionList<?> fileOptions) {
this.fileOptions = fileOptions;
}
public LoadDataStatement withFileOptions(ExpressionList<?> fileOptions) {
setFileOptions(fileOptions);
return this;
}
public boolean isWithPartitionColumns() {
return withPartitionColumns;
}
public void setWithPartitionColumns(boolean withPartitionColumns) {
this.withPartitionColumns = withPartitionColumns;
}
public LoadDataStatement withWithPartitionColumns(boolean withPartitionColumns) {
setWithPartitionColumns(withPartitionColumns);
return this;
}
public String getConnectionName() {
return connectionName;
}
public void setConnectionName(String connectionName) {
this.connectionName = connectionName;
}
public LoadDataStatement withConnectionName(String connectionName) {
setConnectionName(connectionName);
return this;
}
public StringBuilder appendTo(StringBuilder builder) {
return appendTo(builder, builder::append);
}
/** Renders the options and file options through the caller's expression visitor. */
public StringBuilder appendTo(StringBuilder builder, Consumer<Expression> expressionRenderer) {
builder.append("LOAD DATA ").append(overwrite ? "OVERWRITE " : "INTO ").append(table);
if (columnDefinitions != null && !columnDefinitions.isEmpty()) {
builder.append(" ").append(PlainSelect.getStringList(columnDefinitions, true, true));
}
if (options != null) {
appendOptions(builder.append(" OPTIONS ("), options, expressionRenderer).append(")");
}
appendOptions(builder.append(" FROM FILES ("), fileOptions, expressionRenderer).append(")");
if (withPartitionColumns) {
builder.append(" WITH PARTITION COLUMNS");
}
if (connectionName != null) {
builder.append(" WITH CONNECTION ").append(connectionName);
}
return builder;
}
private static StringBuilder appendOptions(StringBuilder builder, ExpressionList<?> options,
Consumer<Expression> expressionRenderer) {
if (options != null) {
for (int i = 0; i < options.size(); i++) {
if (i > 0) {
builder.append(", ");
}
expressionRenderer.accept(options.get(i));
}
}
return builder;
}
@Override
public String toString() {
return appendTo(new StringBuilder()).toString();
}
@Override
public <T, S> T accept(StatementVisitor<T> statementVisitor, S context) {
return statementVisitor.visit(this, context);
}
}