Repository navigation
Expand file tree
/
Copy pathDescribeStatement.java
More file actions
117 lines (98 loc) · 3.08 KB
/
Copy pathDescribeStatement.java
File metadata and controls
117 lines (98 loc) · 3.08 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
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.statement;
import java.util.function.Consumer;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
import net.sf.jsqlparser.schema.Table;
import net.sf.jsqlparser.statement.select.Select;
/**
* {@code DESCRIBE} or {@code DESC} of a table, or, in DuckDB, of a query's result.
*
* @see <a href="https://dev.mysql.com/doc/refman/8.4/en/explain.html">MySQL DESCRIBE</a>
*/
public class DescribeStatement extends ASTNodeAccessImpl implements Statement {
private Table table;
private Select select;
private String describeType;
private Expression columnPattern;
public DescribeStatement() {
// empty constructor
}
public DescribeStatement(Table table) {
this.table = table;
}
public Table getTable() {
return table;
}
public void setTable(Table table) {
this.table = table;
}
/** DuckDB also describes a query: {@code DESCRIBE SELECT ...}. */
public Select getSelect() {
return select;
}
public void setSelect(Select select) {
this.select = select;
}
public DescribeStatement withSelect(Select select) {
setSelect(select);
return this;
}
/**
* The MySQL column name ({@link net.sf.jsqlparser.schema.Column}) or wildcard string that
* limits the described columns to those it matches, or null.
*/
public Expression getColumnPattern() {
return columnPattern;
}
public void setColumnPattern(Expression columnPattern) {
this.columnPattern = columnPattern;
}
public DescribeStatement withColumnPattern(Expression columnPattern) {
setColumnPattern(columnPattern);
return this;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
return appendTo(builder, builder::append, builder::append).toString();
}
/** Shared by SQL rendering and statement deparsers. */
public StringBuilder appendTo(StringBuilder builder, Consumer<Select> selectPrinter,
Consumer<Expression> expressionPrinter) {
builder.append(describeType).append(" ");
if (select != null) {
selectPrinter.accept(select);
} else {
builder.append(table);
if (columnPattern != null) {
builder.append(" ");
expressionPrinter.accept(columnPattern);
}
}
return builder;
}
@Override
public <T, S> T accept(StatementVisitor<T> statementVisitor, S context) {
return statementVisitor.visit(this, context);
}
public DescribeStatement withTable(Table table) {
this.setTable(table);
return this;
}
public String getDescribeType() {
return describeType;
}
public DescribeStatement setDescribeType(String describeType) {
this.describeType = describeType;
return this;
}
}