-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathCopyStatement.java
More file actions
139 lines (115 loc) · 3.39 KB
/
Copy pathCopyStatement.java
File metadata and controls
139 lines (115 loc) · 3.39 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
/*-
* #%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;
import net.sf.jsqlparser.expression.operators.relational.ExpressionList;
import net.sf.jsqlparser.schema.Column;
import net.sf.jsqlparser.schema.Table;
import net.sf.jsqlparser.statement.select.PlainSelect;
import net.sf.jsqlparser.statement.select.Select;
import java.util.List;
/**
* {@code COPY table [(columns)] FROM path [(options)]} and
* {@code COPY {table | (query)} TO path [(options)]}, DuckDB's bulk import and export statement.
*
* @see <a href="https://duckdb.org/docs/stable/sql/statements/copy">COPY</a>
*/
public class CopyStatement implements Statement {
private Table table;
private ExpressionList<Column> columns;
private Select select;
private boolean from;
private String path;
private List<String> options;
public Table getTable() {
return table;
}
public void setTable(Table table) {
this.table = table;
}
public CopyStatement withTable(Table table) {
setTable(table);
return this;
}
public ExpressionList<Column> getColumns() {
return columns;
}
public void setColumns(ExpressionList<Column> columns) {
this.columns = columns;
}
public CopyStatement withColumns(ExpressionList<Column> columns) {
setColumns(columns);
return this;
}
public Select getSelect() {
return select;
}
public void setSelect(Select select) {
this.select = select;
}
public CopyStatement withSelect(Select select) {
setSelect(select);
return this;
}
/** {@code true} for COPY ... FROM (import), {@code false} for COPY ... TO (export). */
public boolean isFrom() {
return from;
}
public void setFrom(boolean from) {
this.from = from;
}
public CopyStatement withFrom(boolean from) {
setFrom(from);
return this;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public CopyStatement withPath(String path) {
setPath(path);
return this;
}
public List<String> getOptions() {
return options;
}
public void setOptions(List<String> options) {
this.options = options;
}
public CopyStatement withOptions(List<String> options) {
setOptions(options);
return this;
}
public StringBuilder appendTo(StringBuilder builder) {
builder.append("COPY ");
if (select != null) {
builder.append("(").append(select).append(")");
} else {
builder.append(table);
if (columns != null && !columns.isEmpty()) {
builder.append(" (").append(columns).append(")");
}
}
builder.append(from ? " FROM " : " TO ").append(path);
if (options != null && !options.isEmpty()) {
builder.append(" ").append(PlainSelect.getStringList(options, true, true));
}
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);
}
}