mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved hive sql parser
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package com.alibaba.druid.sql.ast;
|
||||
|
||||
public enum AutoIncrementType
|
||||
{
|
||||
GROUP("GROUP"), SIMPLE("SIMPLE"),
|
||||
SIMPLE_CACHE("SIMPLE WITH CACHE"), TIME("TIME");
|
||||
|
||||
private final String keyword;
|
||||
|
||||
public String getKeyword() {
|
||||
return this.keyword;
|
||||
}
|
||||
|
||||
private AutoIncrementType(String keyword){
|
||||
this.keyword = keyword;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.alibaba.druid.sql.ast;
|
||||
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLTableSourceImpl;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLAdhocTableSource
|
||||
extends SQLTableSourceImpl {
|
||||
private SQLCreateTableStatement definition;
|
||||
|
||||
public SQLAdhocTableSource(SQLCreateTableStatement definition) {
|
||||
setDefinition(definition);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor v) {
|
||||
if (v.visit(this)) {
|
||||
if (definition != null) {
|
||||
definition.accept(v);
|
||||
}
|
||||
}
|
||||
v.endVisit(this);
|
||||
}
|
||||
|
||||
public SQLCreateTableStatement getDefinition() {
|
||||
return definition;
|
||||
}
|
||||
|
||||
public void setDefinition(SQLCreateTableStatement x) {
|
||||
if (x != null) {
|
||||
x.setParent(this);
|
||||
}
|
||||
this.definition = x;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.alibaba.druid.sql.ast;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLCurrentTimeExpr
|
||||
extends SQLExprImpl {
|
||||
private final Type type;
|
||||
|
||||
public SQLCurrentTimeExpr(Type type) {
|
||||
if (type == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor v) {
|
||||
v.visit(this);
|
||||
v.endVisit(this);
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (getClass() != o.getClass()) return false;
|
||||
|
||||
SQLCurrentTimeExpr that = (SQLCurrentTimeExpr) o;
|
||||
|
||||
return type == that.type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return type.hashCode();
|
||||
}
|
||||
|
||||
public SQLCurrentTimeExpr clone() {
|
||||
return new SQLCurrentTimeExpr(type);
|
||||
}
|
||||
|
||||
public static enum Type {
|
||||
CURRENT_TIME("CURRENT_TIME"),
|
||||
CURRENT_DATE("CURRENT_DATE"),
|
||||
CURDATE("CURDATE"),
|
||||
CURTIME("CURTIME"),
|
||||
CURRENT_TIMESTAMP("CURRENT_TIMESTAMP"),
|
||||
LOCALTIME("LOCALTIME"),
|
||||
LOCALTIMESTAMP("LOCALTIMESTAMP"),
|
||||
SYSDATE("SYSDATE"),
|
||||
;
|
||||
|
||||
public final String name;
|
||||
public final String name_lower;
|
||||
|
||||
Type(String name)
|
||||
{
|
||||
this.name = name;
|
||||
this.name_lower = name.toLowerCase();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.alibaba.druid.sql.ast;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLCurrentUserExpr
|
||||
extends SQLExprImpl {
|
||||
|
||||
public SQLCurrentUserExpr() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor v) {
|
||||
v.visit(this);
|
||||
v.endVisit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return getClass() == o.getClass();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public SQLCurrentUserExpr clone() {
|
||||
return new SQLCurrentUserExpr();
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package com.alibaba.druid.sql.ast;
|
||||
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -102,5 +104,20 @@ public abstract class SQLPartitionBy extends SQLObjectImpl {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isPartitionByColumn(long columnNameHashCode64) {
|
||||
for (SQLExpr column : columns) {
|
||||
if (column instanceof SQLIdentifierExpr
|
||||
&& ((SQLIdentifierExpr) column)
|
||||
.nameHashCode64() == columnNameHashCode64) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (subPartitionBy != null) {
|
||||
return subPartitionBy.isPartitionByColumn(columnNameHashCode64);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public abstract SQLPartitionBy clone();
|
||||
}
|
||||
|
||||
@@ -73,5 +73,9 @@ public abstract class SQLSubPartitionBy extends SQLObjectImpl {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isPartitionByColumn(long columnNameHashCode64) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public abstract SQLSubPartitionBy clone();
|
||||
}
|
||||
|
||||
@@ -61,4 +61,8 @@ public class SQLSubPartitionByHash extends SQLSubPartitionBy {
|
||||
return x;
|
||||
}
|
||||
|
||||
public boolean isPartitionByColumn(long columnNameHashCode64) {
|
||||
return expr instanceof SQLName
|
||||
&& ((SQLName) expr).nameHashCode64() == columnNameHashCode64;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,4 +48,9 @@ public class SQLSubPartitionByList extends SQLSubPartitionBy {
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
public boolean isPartitionByColumn(long columnNameHashCode64) {
|
||||
return column != null
|
||||
&& column.nameHashCode64() == columnNameHashCode64;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.alibaba.druid.sql.ast;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLSubPartitionByRange extends SQLSubPartitionBy {
|
||||
@@ -43,4 +44,14 @@ public class SQLSubPartitionByRange extends SQLSubPartitionBy {
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
public boolean isPartitionByColumn(long columnNameHashCode64) {
|
||||
for (SQLExpr column : columns) {
|
||||
if (column instanceof SQLIdentifierExpr
|
||||
&& ((SQLIdentifierExpr) column).nameHashCode64() == columnNameHashCode64) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.sql.ast.expr;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLDataType;
|
||||
import com.alibaba.druid.sql.ast.SQLDataTypeImpl;
|
||||
import com.alibaba.druid.sql.ast.SQLObject;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class SQLDecimalExpr
|
||||
extends SQLNumericLiteralExpr implements SQLValuableExpr, Comparable<SQLDecimalExpr>
|
||||
{
|
||||
public final static SQLDataType DATA_TYPE = new SQLDataTypeImpl("DECIMAL");
|
||||
|
||||
private BigDecimal value;
|
||||
private transient String literal;
|
||||
|
||||
public SQLDecimalExpr(){
|
||||
|
||||
}
|
||||
|
||||
public SQLDecimalExpr(BigDecimal value){
|
||||
super();
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public SQLDecimalExpr(String value){
|
||||
super();
|
||||
this.value = new BigDecimal(value);
|
||||
this.literal = value;
|
||||
}
|
||||
|
||||
public String getLiteral() {
|
||||
return literal;
|
||||
}
|
||||
|
||||
public SQLDecimalExpr clone() {
|
||||
return new SQLDecimalExpr(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SQLObject> getChildren() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getNumber() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public BigDecimal getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(BigDecimal value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((value == null) ? 0 : value.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
SQLDecimalExpr other = (SQLDecimalExpr) obj;
|
||||
if (value == null) {
|
||||
if (other.value != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!value.equals(other.value)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNumber(Number number) {
|
||||
if (number == null) {
|
||||
this.setValue(null);
|
||||
return;
|
||||
}
|
||||
|
||||
this.setValue(((BigDecimal) number));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(SQLDecimalExpr o) {
|
||||
return value.compareTo(o.value);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,24 +15,95 @@
|
||||
*/
|
||||
package com.alibaba.druid.sql.ast.expr;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
public enum SQLIntervalUnit {
|
||||
YEAR, YEAR_MONTH,
|
||||
|
||||
YEAR,
|
||||
YEAR_MONTH,
|
||||
QUARTER,
|
||||
MONTH,
|
||||
WEEK,
|
||||
DAY,
|
||||
DAY_HOUR,
|
||||
DAY_MINUTE,
|
||||
DAY_SECOND,
|
||||
DAY_MICROSECOND,
|
||||
HOUR,
|
||||
HOUR_MINUTE,
|
||||
HOUR_SECOND,
|
||||
HOUR_MICROSECOND,
|
||||
MINUTE,
|
||||
MINUTE_SECOND,
|
||||
MINUTE_MICROSECOND,
|
||||
SECOND,
|
||||
SECOND_MICROSECOND,
|
||||
MICROSECOND,
|
||||
DAY_OF_WEEK,
|
||||
DOW,
|
||||
DAY_OF_MONTH,
|
||||
DAY_OF_YEAR,
|
||||
YEAR_OF_WEEK,
|
||||
YOW,
|
||||
TIMEZONE_HOUR,
|
||||
TIMEZONE_MINUTE,
|
||||
DOY,
|
||||
YEAR_TO_MONTH("YEAR TO MONTH")
|
||||
;
|
||||
|
||||
MONTH, WEEK, DAY, DAY_HOUR, DAY_MINUTE, DAY_SECOND, DAY_MICROSECOND,
|
||||
|
||||
HOUR, HOUR_MINUTE, HOUR_SECOND, HOUR_MICROSECOND,
|
||||
|
||||
MINUTE, MINUTE_SECOND, MINUTE_MICROSECOND,
|
||||
|
||||
SECOND, SECOND_MICROSECOND,
|
||||
|
||||
MICROSECOND;
|
||||
|
||||
public final String name;
|
||||
public final String name_lcase;
|
||||
|
||||
private SQLIntervalUnit() {
|
||||
this.name_lcase = name().toLowerCase();
|
||||
|
||||
SQLIntervalUnit(String name) {
|
||||
this.name = name;
|
||||
this.name_lcase = name.toLowerCase();
|
||||
}
|
||||
|
||||
SQLIntervalUnit() {
|
||||
this.name = name();
|
||||
this.name_lcase = name.toLowerCase();
|
||||
}
|
||||
|
||||
public static boolean add(Calendar calendar, int intervalInt, SQLIntervalUnit unit) {
|
||||
switch (unit) {
|
||||
case YEAR:
|
||||
calendar.add(Calendar.YEAR, intervalInt);
|
||||
return true;
|
||||
case MONTH:
|
||||
calendar.add(Calendar.MONTH, intervalInt);
|
||||
return true;
|
||||
case WEEK:
|
||||
calendar.add(Calendar.WEEK_OF_MONTH, intervalInt);
|
||||
return true;
|
||||
case DAY:
|
||||
calendar.add(Calendar.DAY_OF_MONTH, intervalInt);
|
||||
return true;
|
||||
case HOUR:
|
||||
calendar.add(Calendar.HOUR_OF_DAY, intervalInt);
|
||||
return true;
|
||||
case MINUTE:
|
||||
calendar.add(Calendar.MINUTE, intervalInt);
|
||||
return true;
|
||||
case SECOND:
|
||||
calendar.add(Calendar.SECOND, intervalInt);
|
||||
return true;
|
||||
case MICROSECOND:
|
||||
calendar.add(Calendar.MILLISECOND, intervalInt);
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isDateTime() {
|
||||
switch (this) {
|
||||
case HOUR:
|
||||
case MINUTE:
|
||||
case SECOND:
|
||||
case MICROSECOND:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.sql.ast.expr;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLExprImpl;
|
||||
import com.alibaba.druid.sql.ast.SQLObject;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class SQLSizeExpr
|
||||
extends SQLExprImpl {
|
||||
|
||||
private SQLExpr value;
|
||||
private Unit unit;
|
||||
|
||||
public SQLSizeExpr(){
|
||||
|
||||
}
|
||||
|
||||
public SQLSizeExpr(String value, char unit){
|
||||
this.unit = Unit.valueOf(Character.toString(unit).toUpperCase());
|
||||
if (value.indexOf('.') == -1) {
|
||||
this.value = new SQLIntegerExpr(Integer.parseInt(value));
|
||||
} else {
|
||||
this.value = new SQLNumberExpr(new BigDecimal(value));
|
||||
}
|
||||
}
|
||||
|
||||
public SQLSizeExpr(SQLExpr value, Unit unit){
|
||||
super();
|
||||
this.value = value;
|
||||
this.unit = unit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
if (this.value != null) {
|
||||
this.value.accept(visitor);
|
||||
}
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public List<SQLObject> getChildren() {
|
||||
return Collections.<SQLObject>singletonList(value);
|
||||
}
|
||||
|
||||
public SQLExpr getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(SQLExpr value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Unit getUnit() {
|
||||
return unit;
|
||||
}
|
||||
|
||||
public void setUnit(Unit unit) {
|
||||
this.unit = unit;
|
||||
}
|
||||
|
||||
public static enum Unit {
|
||||
B, K, M, G, T, P, E
|
||||
}
|
||||
|
||||
public SQLSizeExpr clone() {
|
||||
SQLSizeExpr x = new SQLSizeExpr();
|
||||
|
||||
if (value != null) {
|
||||
x.setValue(value.clone());
|
||||
}
|
||||
x.unit = unit;
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
SQLSizeExpr that = (SQLSizeExpr) o;
|
||||
|
||||
if (value != null ? !value.equals(that.value) : that.value != null) return false;
|
||||
return unit == that.unit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = value != null ? value.hashCode() : 0;
|
||||
result = 31 * result + (unit != null ? unit.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,22 +15,18 @@
|
||||
*/
|
||||
package com.alibaba.druid.sql.ast.statement;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLDataType;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLObjectImpl;
|
||||
import com.alibaba.druid.sql.ast.SQLObjectWithDataType;
|
||||
import com.alibaba.druid.sql.ast.SQLReplaceable;
|
||||
import com.alibaba.druid.sql.ast.*;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLCharExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLColumnDefinition extends SQLObjectImpl implements SQLTableElement, SQLObjectWithDataType, SQLReplaceable {
|
||||
import java.sql.Types;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SQLColumnDefinition extends SQLObjectImpl implements SQLTableElement, SQLObjectWithDataType, SQLReplaceable, SQLDbTypedObject {
|
||||
protected String dbType;
|
||||
|
||||
protected SQLName name;
|
||||
@@ -46,14 +42,37 @@ public class SQLColumnDefinition extends SQLObjectImpl implements SQLTableElemen
|
||||
// for mysql
|
||||
protected boolean autoIncrement = false;
|
||||
protected SQLExpr onUpdate;
|
||||
protected SQLExpr format;
|
||||
protected SQLExpr storage;
|
||||
protected SQLExpr charsetExpr;
|
||||
protected SQLExpr collateExpr;
|
||||
protected SQLExpr asExpr;
|
||||
protected boolean stored = false;
|
||||
protected boolean virtual = false;
|
||||
protected boolean visible = false;
|
||||
protected AutoIncrementType sequenceType;
|
||||
protected boolean preSort = false; // for ads
|
||||
protected int preSortOrder = 0; // for ads
|
||||
|
||||
protected Identity identity;
|
||||
|
||||
// for ads
|
||||
protected SQLExpr generatedAlawsAs;
|
||||
protected SQLExpr delimiter; // for ads
|
||||
protected SQLExpr delimiterTokenizer; // for ads3.0 multivalue
|
||||
protected SQLExpr nlpTokenizer; // for ads3.0 multivalue
|
||||
protected SQLExpr valueType; // for ads3.0 multivalue
|
||||
protected boolean disableIndex = false; //for ads
|
||||
protected SQLExpr jsonIndexAttrsExpr; // for ads
|
||||
private SQLExpr unitCount;
|
||||
private SQLExpr unitIndex;
|
||||
private SQLExpr step;
|
||||
private SQLCharExpr encode;
|
||||
private SQLCharExpr compression;
|
||||
|
||||
// for aliyun data lake anlytics
|
||||
private List<SQLAssignItem> mappedBy;
|
||||
private List<SQLAssignItem> colProperties;
|
||||
|
||||
public SQLColumnDefinition(){
|
||||
|
||||
@@ -64,22 +83,11 @@ public class SQLColumnDefinition extends SQLObjectImpl implements SQLTableElemen
|
||||
}
|
||||
|
||||
// for sqlserver
|
||||
public void setIdentity(Identity x) {
|
||||
if (x != null) {
|
||||
x.setParent(this);
|
||||
public void setIdentity(Identity identity) {
|
||||
if (identity != null) {
|
||||
identity.setParent(this);
|
||||
}
|
||||
this.identity = x;
|
||||
}
|
||||
|
||||
public SQLExpr getGeneratedAlawsAs() {
|
||||
return generatedAlawsAs;
|
||||
}
|
||||
|
||||
public void setGeneratedAlawsAs(SQLExpr x) {
|
||||
if (x != null) {
|
||||
x.setParent(this);
|
||||
}
|
||||
this.generatedAlawsAs = x;
|
||||
this.identity = identity;
|
||||
}
|
||||
|
||||
public Boolean getEnable() {
|
||||
@@ -110,6 +118,14 @@ public class SQLColumnDefinition extends SQLObjectImpl implements SQLTableElemen
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getColumnName() {
|
||||
if (name == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return name.getSimpleName();
|
||||
}
|
||||
|
||||
public long nameHashCode64() {
|
||||
if (name == null) {
|
||||
return 0;
|
||||
@@ -137,6 +153,14 @@ public class SQLColumnDefinition extends SQLObjectImpl implements SQLTableElemen
|
||||
public SQLDataType getDataType() {
|
||||
return dataType;
|
||||
}
|
||||
//
|
||||
// public int jdbcType() {
|
||||
// if (dataType == null) {
|
||||
// return Types.OTHER;
|
||||
// }
|
||||
//
|
||||
// return dataType.jdbcType();
|
||||
// }
|
||||
|
||||
public void setDataType(SQLDataType dataType) {
|
||||
if (dataType != null) {
|
||||
@@ -159,7 +183,58 @@ public class SQLColumnDefinition extends SQLObjectImpl implements SQLTableElemen
|
||||
public List<SQLColumnConstraint> getConstraints() {
|
||||
return constraints;
|
||||
}
|
||||
|
||||
|
||||
public boolean isPrimaryKey() {
|
||||
for (SQLColumnConstraint constraint : constraints) {
|
||||
if (constraint instanceof SQLColumnPrimaryKey) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (parent instanceof SQLCreateTableStatement) {
|
||||
return ((SQLCreateTableStatement) parent)
|
||||
.isPrimaryColumn(
|
||||
nameHashCode64());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isOnlyPrimaryKey() {
|
||||
for (SQLColumnConstraint constraint : constraints) {
|
||||
if (constraint instanceof SQLColumnPrimaryKey) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (parent instanceof SQLCreateTableStatement) {
|
||||
return ((SQLCreateTableStatement) parent)
|
||||
.isPrimaryColumn(
|
||||
nameHashCode64());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isPartitionBy() {
|
||||
if (!(parent instanceof SQLCreateTableStatement)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SQLCreateTableStatement stmt = (SQLCreateTableStatement) parent;
|
||||
final SQLPartitionBy partitioning = stmt.getPartitioning();
|
||||
if (partitioning == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (name == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return partitioning.isPartitionByColumn(
|
||||
nameHashCode64());
|
||||
}
|
||||
|
||||
public void addConstraint(SQLColumnConstraint constraint) {
|
||||
if (constraint != null) {
|
||||
constraint.setParent(this);
|
||||
@@ -167,17 +242,6 @@ public class SQLColumnDefinition extends SQLObjectImpl implements SQLTableElemen
|
||||
this.constraints.add(constraint);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void output(StringBuffer buf) {
|
||||
name.output(buf);
|
||||
buf.append(' ');
|
||||
this.dataType.output(buf);
|
||||
if (defaultExpr != null) {
|
||||
buf.append(" DEFAULT ");
|
||||
this.defaultExpr.output(buf);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
@@ -194,7 +258,13 @@ public class SQLColumnDefinition extends SQLObjectImpl implements SQLTableElemen
|
||||
}
|
||||
|
||||
public void setComment(String comment) {
|
||||
this.setComment(new SQLCharExpr(comment));
|
||||
SQLCharExpr expr;
|
||||
if (comment == null) {
|
||||
expr = null;
|
||||
} else {
|
||||
expr = new SQLCharExpr(comment);
|
||||
}
|
||||
this.setComment(expr);
|
||||
}
|
||||
|
||||
public void setComment(SQLExpr comment) {
|
||||
@@ -231,6 +301,17 @@ public class SQLColumnDefinition extends SQLObjectImpl implements SQLTableElemen
|
||||
this.charsetExpr = charsetExpr;
|
||||
}
|
||||
|
||||
public SQLExpr getCollateExpr() {
|
||||
return collateExpr;
|
||||
}
|
||||
|
||||
public void setCollateExpr(SQLExpr x) {
|
||||
if (charsetExpr != null) {
|
||||
charsetExpr.setParent(this);
|
||||
}
|
||||
this.collateExpr = x;
|
||||
}
|
||||
|
||||
public SQLExpr getAsExpr() {
|
||||
return asExpr;
|
||||
}
|
||||
@@ -258,6 +339,14 @@ public class SQLColumnDefinition extends SQLObjectImpl implements SQLTableElemen
|
||||
this.onUpdate = onUpdate;
|
||||
}
|
||||
|
||||
public SQLExpr getFormat() {
|
||||
return format;
|
||||
}
|
||||
|
||||
public void setFormat(SQLExpr format) {
|
||||
this.format = format;
|
||||
}
|
||||
|
||||
public SQLExpr getStorage() {
|
||||
return storage;
|
||||
}
|
||||
@@ -278,15 +367,31 @@ public class SQLColumnDefinition extends SQLObjectImpl implements SQLTableElemen
|
||||
return true;
|
||||
}
|
||||
|
||||
if (comment == expr) {
|
||||
setComment(target);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setUnitCount(SQLExpr unitCount) {
|
||||
if (unitCount != null) {
|
||||
unitCount.setParent(this);
|
||||
}
|
||||
this.unitCount = unitCount;
|
||||
}
|
||||
|
||||
public static class Identity extends SQLObjectImpl {
|
||||
|
||||
private Integer seed;
|
||||
private Integer increment;
|
||||
|
||||
private boolean notForReplication;
|
||||
private boolean cycle;
|
||||
|
||||
private Integer minValue;
|
||||
private Integer maxValue;
|
||||
|
||||
public Identity(){
|
||||
|
||||
@@ -308,6 +413,30 @@ public class SQLColumnDefinition extends SQLObjectImpl implements SQLTableElemen
|
||||
this.increment = increment;
|
||||
}
|
||||
|
||||
public boolean isCycle() {
|
||||
return cycle;
|
||||
}
|
||||
|
||||
public void setCycle(boolean cycle) {
|
||||
this.cycle = cycle;
|
||||
}
|
||||
|
||||
public Integer getMinValue() {
|
||||
return minValue;
|
||||
}
|
||||
|
||||
public void setMinValue(Integer minValue) {
|
||||
this.minValue = minValue;
|
||||
}
|
||||
|
||||
public Integer getMaxValue() {
|
||||
return maxValue;
|
||||
}
|
||||
|
||||
public void setMaxValue(Integer maxValue) {
|
||||
this.maxValue = maxValue;
|
||||
}
|
||||
|
||||
public boolean isNotForReplication() {
|
||||
return notForReplication;
|
||||
}
|
||||
@@ -326,6 +455,9 @@ public class SQLColumnDefinition extends SQLObjectImpl implements SQLTableElemen
|
||||
Identity x = new Identity();
|
||||
x.seed = seed;
|
||||
x.increment = increment;
|
||||
x.cycle = cycle;
|
||||
x.minValue = minValue;
|
||||
x.maxValue = maxValue;
|
||||
x.notForReplication = notForReplication;
|
||||
return x;
|
||||
}
|
||||
@@ -379,6 +511,10 @@ public class SQLColumnDefinition extends SQLObjectImpl implements SQLTableElemen
|
||||
x.setOnUpdate(onUpdate.clone());
|
||||
}
|
||||
|
||||
if (format != null) {
|
||||
x.setFormat(format.clone());
|
||||
}
|
||||
|
||||
if (storage != null) {
|
||||
x.setStorage(storage.clone());
|
||||
}
|
||||
@@ -387,6 +523,10 @@ public class SQLColumnDefinition extends SQLObjectImpl implements SQLTableElemen
|
||||
x.setCharsetExpr(charsetExpr.clone());
|
||||
}
|
||||
|
||||
if (collateExpr != null) {
|
||||
x.setCollateExpr(collateExpr.clone());
|
||||
}
|
||||
|
||||
if (asExpr != null) {
|
||||
x.setAsExpr(asExpr.clone());
|
||||
}
|
||||
@@ -398,6 +538,47 @@ public class SQLColumnDefinition extends SQLObjectImpl implements SQLTableElemen
|
||||
x.setIdentity(identity.clone());
|
||||
}
|
||||
|
||||
if (delimiter != null) {
|
||||
x.setDelimiter(delimiter.clone());
|
||||
}
|
||||
|
||||
if (valueType != null) {
|
||||
x.setValueType(valueType.clone());
|
||||
}
|
||||
|
||||
if (nlpTokenizer != null) {
|
||||
x.setNplTokenizer(nlpTokenizer.clone());
|
||||
}
|
||||
|
||||
x.preSort = preSort;
|
||||
x.preSortOrder = preSortOrder;
|
||||
|
||||
if (jsonIndexAttrsExpr != null) {
|
||||
x.setJsonIndexAttrsExpr(jsonIndexAttrsExpr.clone());
|
||||
}
|
||||
|
||||
if (mappedBy != null) {
|
||||
for (SQLAssignItem item : mappedBy) {
|
||||
SQLAssignItem item2 = item.clone();
|
||||
item2.setParent(this);
|
||||
if (x.mappedBy == null) {
|
||||
x.mappedBy = new ArrayList<SQLAssignItem>();
|
||||
}
|
||||
x.mappedBy.add(item2);
|
||||
}
|
||||
}
|
||||
|
||||
if (colProperties != null) {
|
||||
for (SQLAssignItem item : colProperties) {
|
||||
SQLAssignItem item2 = item.clone();
|
||||
item2.setParent(this);
|
||||
if (x.colProperties == null) {
|
||||
x.colProperties = new ArrayList<SQLAssignItem>();
|
||||
}
|
||||
x.colProperties.add(item2);
|
||||
}
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
@@ -435,22 +616,180 @@ public class SQLColumnDefinition extends SQLObjectImpl implements SQLTableElemen
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isPrimaryKey() {
|
||||
for (SQLColumnConstraint constraint : constraints) {
|
||||
if (constraint instanceof SQLColumnPrimaryKey) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
public SQLExpr getGeneratedAlawsAs() {
|
||||
return generatedAlawsAs;
|
||||
}
|
||||
|
||||
if (parent instanceof SQLCreateTableStatement) {
|
||||
return ((SQLCreateTableStatement) parent)
|
||||
.isPrimaryColumn(nameHashCode64());
|
||||
public void setGeneratedAlawsAs(SQLExpr x) {
|
||||
if (x != null) {
|
||||
x.setParent(this);
|
||||
}
|
||||
this.generatedAlawsAs = x;
|
||||
}
|
||||
|
||||
return false;
|
||||
public boolean isVisible() {
|
||||
return visible;
|
||||
}
|
||||
|
||||
public void setVisible(boolean visible) {
|
||||
this.visible = visible;
|
||||
}
|
||||
|
||||
public SQLExpr getDelimiter() {
|
||||
return delimiter;
|
||||
}
|
||||
|
||||
public boolean isDisableIndex() {
|
||||
return disableIndex;
|
||||
}
|
||||
|
||||
public void setDisableIndex(boolean disableIndex) {
|
||||
this.disableIndex = disableIndex;
|
||||
}
|
||||
|
||||
public void setDelimiter(SQLExpr x) {
|
||||
if (x != null) {
|
||||
x.setParent(this);
|
||||
}
|
||||
this.delimiter = x;
|
||||
}
|
||||
|
||||
public SQLExpr getDelimiterTokenizer() {
|
||||
return delimiterTokenizer;
|
||||
}
|
||||
|
||||
public void setDelimiterTokenizer(SQLExpr delimiterTokenizer) {
|
||||
this.delimiterTokenizer = delimiterTokenizer;
|
||||
}
|
||||
|
||||
public SQLExpr getNlpTokenizer() {
|
||||
return nlpTokenizer;
|
||||
}
|
||||
|
||||
public void setNlpTokenizer(SQLExpr nlpTokenizer) {
|
||||
this.nlpTokenizer = nlpTokenizer;
|
||||
}
|
||||
|
||||
public SQLExpr getValueType() {
|
||||
return valueType;
|
||||
}
|
||||
|
||||
public void setValueType(SQLExpr x) {
|
||||
if (x != null) {
|
||||
x.setParent(this);
|
||||
}
|
||||
this.valueType = x;
|
||||
}
|
||||
|
||||
public boolean isPreSort() {
|
||||
return preSort;
|
||||
}
|
||||
|
||||
public void setPreSort(boolean preSort) {
|
||||
this.preSort = preSort;
|
||||
}
|
||||
|
||||
public int getPreSortOrder() {
|
||||
return preSortOrder;
|
||||
}
|
||||
|
||||
public void setPreSortOrder(int preSortOrder) {
|
||||
this.preSortOrder = preSortOrder;
|
||||
}
|
||||
|
||||
public SQLExpr getJsonIndexAttrsExpr() {
|
||||
return jsonIndexAttrsExpr;
|
||||
}
|
||||
|
||||
public void setJsonIndexAttrsExpr(SQLExpr jsonIndexAttrsExpr) {
|
||||
this.jsonIndexAttrsExpr = jsonIndexAttrsExpr;
|
||||
}
|
||||
|
||||
public AutoIncrementType getSequenceType() {
|
||||
return sequenceType;
|
||||
}
|
||||
|
||||
public void setSequenceType(AutoIncrementType sequenceType) {
|
||||
this.sequenceType = sequenceType;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return SQLUtils.toSQLString(this, dbType);
|
||||
}
|
||||
|
||||
public SQLExpr getUnitCount() {
|
||||
return unitCount;
|
||||
}
|
||||
|
||||
public SQLExpr getUnitIndex() {
|
||||
return unitIndex;
|
||||
}
|
||||
|
||||
public void setUnitIndex(SQLExpr unitIndex) {
|
||||
if (unitIndex != null) {
|
||||
unitIndex.setParent(this);
|
||||
}
|
||||
this.unitIndex = unitIndex;
|
||||
}
|
||||
|
||||
public SQLExpr getNplTokenizer() {
|
||||
return nlpTokenizer;
|
||||
}
|
||||
|
||||
public void setNplTokenizer(SQLExpr x) {
|
||||
if (x != null) {
|
||||
x.setParent(this);
|
||||
}
|
||||
this.nlpTokenizer = x;
|
||||
}
|
||||
|
||||
public SQLExpr getStep() {
|
||||
return step;
|
||||
}
|
||||
|
||||
public void setStep(SQLExpr step) {
|
||||
if (step != null) {
|
||||
step.setParent(this);
|
||||
}
|
||||
this.step = step;
|
||||
}
|
||||
|
||||
public List<SQLAssignItem> getMappedBy() {
|
||||
if (mappedBy == null) {
|
||||
mappedBy = new ArrayList<SQLAssignItem>();
|
||||
}
|
||||
return mappedBy;
|
||||
}
|
||||
|
||||
public List<SQLAssignItem> getMappedByDirect() {
|
||||
return mappedBy;
|
||||
}
|
||||
|
||||
public List<SQLAssignItem> getColProperties() {
|
||||
if (colProperties == null) {
|
||||
colProperties = new ArrayList<SQLAssignItem>();
|
||||
}
|
||||
return colProperties;
|
||||
}
|
||||
|
||||
public SQLCharExpr getEncode() {
|
||||
return encode;
|
||||
}
|
||||
|
||||
public void setEncode(SQLCharExpr encode) {
|
||||
this.encode = encode;
|
||||
}
|
||||
|
||||
public SQLCharExpr getCompression() {
|
||||
return compression;
|
||||
}
|
||||
|
||||
public void setCompression(SQLCharExpr compression) {
|
||||
this.compression = compression;
|
||||
}
|
||||
|
||||
public List<SQLAssignItem> getColPropertiesDirect() {
|
||||
return colProperties;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ public class SQLExprTableSource extends SQLTableSourceImpl implements SQLReplace
|
||||
|
||||
protected SQLExpr expr;
|
||||
private List<SQLName> partitions;
|
||||
protected SQLTableSampling sampling;
|
||||
private SchemaObject schemaObject;
|
||||
|
||||
protected List<SQLName> columns;
|
||||
@@ -66,6 +67,17 @@ public class SQLExprTableSource extends SQLTableSourceImpl implements SQLReplace
|
||||
this.setExpr(new SQLIdentifierExpr(name));
|
||||
}
|
||||
|
||||
public SQLTableSampling getSampling() {
|
||||
return sampling;
|
||||
}
|
||||
|
||||
public void setSampling(SQLTableSampling x) {
|
||||
if (x != null) {
|
||||
x.setParent(this);
|
||||
}
|
||||
this.sampling = x;
|
||||
}
|
||||
|
||||
public SQLName getName() {
|
||||
if (expr instanceof SQLName) {
|
||||
return (SQLName) expr;
|
||||
@@ -145,17 +157,25 @@ public class SQLExprTableSource extends SQLTableSourceImpl implements SQLReplace
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
if (!super.equals(o)) return false;
|
||||
|
||||
SQLExprTableSource that = (SQLExprTableSource) o;
|
||||
|
||||
if (expr != null ? !expr.equals(that.expr) : that.expr != null) return false;
|
||||
return partitions != null ? partitions.equals(that.partitions) : that.partitions == null;
|
||||
if (partitions != null ? !partitions.equals(that.partitions) : that.partitions != null) return false;
|
||||
if (sampling != null ? !sampling.equals(that.sampling) : that.sampling != null) return false;
|
||||
if (schemaObject != null ? !schemaObject.equals(that.schemaObject) : that.schemaObject != null) return false;
|
||||
return columns != null ? columns.equals(that.columns) : that.columns == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = expr != null ? expr.hashCode() : 0;
|
||||
int result = super.hashCode();
|
||||
result = 31 * result + (expr != null ? expr.hashCode() : 0);
|
||||
result = 31 * result + (partitions != null ? partitions.hashCode() : 0);
|
||||
result = 31 * result + (sampling != null ? sampling.hashCode() : 0);
|
||||
result = 31 * result + (schemaObject != null ? schemaObject.hashCode() : 0);
|
||||
result = 31 * result + (columns != null ? columns.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,33 +1,38 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.sql.ast.statement;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLObjectImpl;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.OracleSQLObjectImpl;
|
||||
import com.alibaba.druid.sql.dialect.oracle.visitor.OracleASTVisitor;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLExternalRecordFormat extends SQLObjectImpl {
|
||||
private SQLExpr delimitedBy;
|
||||
private SQLExpr terminatedBy;
|
||||
private SQLExpr escapedBy;
|
||||
private SQLExpr collectionItemsTerminatedBy;
|
||||
private SQLExpr mapKeysTerminatedBy;
|
||||
private SQLExpr linesTerminatedBy;
|
||||
private SQLExpr nullDefinedAs;
|
||||
private SQLExpr serde;
|
||||
|
||||
private Boolean logfile;
|
||||
private Boolean badfile;
|
||||
private boolean ltrim;
|
||||
private boolean missingFieldValuesAreNull;
|
||||
private boolean rejectRowsWithAllNullFields;
|
||||
|
||||
@Override
|
||||
public void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, delimitedBy);
|
||||
acceptChild(visitor, terminatedBy);
|
||||
acceptChild(visitor, escapedBy);
|
||||
acceptChild(visitor, collectionItemsTerminatedBy);
|
||||
acceptChild(visitor, mapKeysTerminatedBy);
|
||||
acceptChild(visitor, linesTerminatedBy);
|
||||
acceptChild(visitor, nullDefinedAs);
|
||||
acceptChild(visitor, serde);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
@@ -47,10 +52,156 @@ public class SQLExternalRecordFormat extends SQLObjectImpl {
|
||||
return terminatedBy;
|
||||
}
|
||||
|
||||
public void setTerminatedBy(SQLExpr terminatedBy) {
|
||||
if (terminatedBy != null) {
|
||||
terminatedBy.setParent(this);
|
||||
public void setTerminatedBy(SQLExpr x) {
|
||||
if (x != null) {
|
||||
x.setParent(this);
|
||||
}
|
||||
this.terminatedBy = terminatedBy;
|
||||
this.terminatedBy = x;
|
||||
}
|
||||
|
||||
public SQLExpr getSerde() {
|
||||
return serde;
|
||||
}
|
||||
|
||||
public void setSerde(SQLExpr x) {
|
||||
if (x != null) {
|
||||
x.setParent(this);
|
||||
}
|
||||
this.serde = x;
|
||||
}
|
||||
|
||||
public SQLExpr getMapKeysTerminatedBy() {
|
||||
return mapKeysTerminatedBy;
|
||||
}
|
||||
|
||||
public void setMapKeysTerminatedBy(SQLExpr x) {
|
||||
if (x != null) {
|
||||
x.setParent(this);
|
||||
}
|
||||
mapKeysTerminatedBy = x;
|
||||
}
|
||||
|
||||
public SQLExpr getCollectionItemsTerminatedBy() {
|
||||
return collectionItemsTerminatedBy;
|
||||
}
|
||||
|
||||
public void setCollectionItemsTerminatedBy(SQLExpr x) {
|
||||
if (x != null) {
|
||||
x.setParent(this);
|
||||
}
|
||||
this.collectionItemsTerminatedBy = x;
|
||||
}
|
||||
|
||||
public SQLExpr getEscapedBy() {
|
||||
return escapedBy;
|
||||
}
|
||||
|
||||
public void setEscapedBy(SQLExpr x) {
|
||||
if (x != null) {
|
||||
x.setParent(this);
|
||||
}
|
||||
this.escapedBy = x;
|
||||
}
|
||||
|
||||
public SQLExpr getLinesTerminatedBy() {
|
||||
return linesTerminatedBy;
|
||||
}
|
||||
|
||||
public void setLinesTerminatedBy(SQLExpr x) {
|
||||
if (x != null) {
|
||||
x.setParent(this);
|
||||
}
|
||||
this.linesTerminatedBy = x;
|
||||
}
|
||||
|
||||
public SQLExpr getNullDefinedAs() {
|
||||
return nullDefinedAs;
|
||||
}
|
||||
|
||||
public void setNullDefinedAs(SQLExpr x) {
|
||||
if (x != null) {
|
||||
x.setParent(this);
|
||||
}
|
||||
this.nullDefinedAs = x;
|
||||
}
|
||||
|
||||
public Boolean getLogfile() {
|
||||
return logfile;
|
||||
}
|
||||
|
||||
public void setLogfile(Boolean logfile) {
|
||||
this.logfile = logfile;
|
||||
}
|
||||
|
||||
public Boolean getBadfile() {
|
||||
return badfile;
|
||||
}
|
||||
|
||||
public void setBadfile(Boolean badfile) {
|
||||
this.badfile = badfile;
|
||||
}
|
||||
|
||||
public boolean isLtrim() {
|
||||
return ltrim;
|
||||
}
|
||||
|
||||
public void setLtrim(boolean ltrim) {
|
||||
this.ltrim = ltrim;
|
||||
}
|
||||
|
||||
public boolean isRejectRowsWithAllNullFields() {
|
||||
return rejectRowsWithAllNullFields;
|
||||
}
|
||||
|
||||
public void setRejectRowsWithAllNullFields(boolean rejectRowsWithAllNullFields) {
|
||||
this.rejectRowsWithAllNullFields = rejectRowsWithAllNullFields;
|
||||
}
|
||||
|
||||
public boolean isMissingFieldValuesAreNull() {
|
||||
return missingFieldValuesAreNull;
|
||||
}
|
||||
|
||||
public void setMissingFieldValuesAreNull(boolean missingFieldValuesAreNull) {
|
||||
this.missingFieldValuesAreNull = missingFieldValuesAreNull;
|
||||
}
|
||||
|
||||
public SQLExternalRecordFormat clone() {
|
||||
SQLExternalRecordFormat x = new SQLExternalRecordFormat();
|
||||
|
||||
if (delimitedBy != null) {
|
||||
x.setDelimitedBy(delimitedBy.clone());
|
||||
}
|
||||
|
||||
if (escapedBy != null) {
|
||||
x.setEscapedBy(escapedBy.clone());
|
||||
}
|
||||
|
||||
if (collectionItemsTerminatedBy != null) {
|
||||
x.setCollectionItemsTerminatedBy(collectionItemsTerminatedBy.clone());
|
||||
}
|
||||
|
||||
if (mapKeysTerminatedBy != null) {
|
||||
x.setMapKeysTerminatedBy(mapKeysTerminatedBy.clone());
|
||||
}
|
||||
|
||||
if (linesTerminatedBy != null) {
|
||||
x.setLinesTerminatedBy(linesTerminatedBy.clone());
|
||||
}
|
||||
|
||||
if (nullDefinedAs != null) {
|
||||
x.setNullDefinedAs(nullDefinedAs.clone());
|
||||
}
|
||||
|
||||
if (serde != null) {
|
||||
x.setSerde(serde.clone());
|
||||
}
|
||||
|
||||
x.logfile = logfile;
|
||||
x.badfile = badfile;
|
||||
x.ltrim = ltrim;
|
||||
x.missingFieldValuesAreNull = missingFieldValuesAreNull;
|
||||
x.rejectRowsWithAllNullFields = rejectRowsWithAllNullFields;
|
||||
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
package com.alibaba.druid.sql.ast.statement;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLObjectImpl;
|
||||
import com.alibaba.druid.sql.ast.SQLReplaceable;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLTableSampling
|
||||
extends SQLObjectImpl implements SQLReplaceable {
|
||||
private SQLExpr bucket;
|
||||
private SQLExpr outOf;
|
||||
private SQLExpr on;
|
||||
private SQLExpr percent;
|
||||
private SQLExpr rows;
|
||||
private SQLExpr byteLength;
|
||||
|
||||
private boolean bernoulli;
|
||||
private boolean system;
|
||||
|
||||
public SQLTableSampling clone() {
|
||||
SQLTableSampling x = new SQLTableSampling();
|
||||
|
||||
if (bucket != null) {
|
||||
x.setBucket(bucket.clone());
|
||||
}
|
||||
|
||||
if (outOf != null) {
|
||||
x.setOutOf(outOf.clone());
|
||||
}
|
||||
|
||||
if (on != null) {
|
||||
x.setOn(on.clone());
|
||||
}
|
||||
|
||||
if (percent != null) {
|
||||
x.setPercent(percent.clone());
|
||||
}
|
||||
|
||||
if (rows != null) {
|
||||
x.setRows(rows.clone());
|
||||
}
|
||||
|
||||
if (byteLength != null) {
|
||||
x.setByteLength(byteLength.clone());
|
||||
}
|
||||
|
||||
x.bernoulli = bernoulli;
|
||||
x.system = system;
|
||||
return x;
|
||||
}
|
||||
|
||||
public SQLExpr getBucket() {
|
||||
return bucket;
|
||||
}
|
||||
|
||||
public void setBucket(SQLExpr x) {
|
||||
if (x != null) {
|
||||
x.setParent(this);
|
||||
}
|
||||
this.bucket = x;
|
||||
}
|
||||
|
||||
public SQLExpr getOutOf() {
|
||||
return outOf;
|
||||
}
|
||||
|
||||
public void setOutOf(SQLExpr x) {
|
||||
if (x != null) {
|
||||
x.setParent(this);
|
||||
}
|
||||
this.outOf = x;
|
||||
}
|
||||
|
||||
public SQLExpr getOn() {
|
||||
return on;
|
||||
}
|
||||
|
||||
public void setOn(SQLExpr x) {
|
||||
if (x != null) {
|
||||
x.setParent(this);
|
||||
}
|
||||
this.on = x;
|
||||
}
|
||||
|
||||
public SQLExpr getPercent() {
|
||||
return percent;
|
||||
}
|
||||
|
||||
public void setPercent(SQLExpr x) {
|
||||
if (x != null) {
|
||||
x.setParent(this);
|
||||
}
|
||||
this.percent = x;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor v) {
|
||||
if (v.visit(this)) {
|
||||
acceptChild(v, bucket);
|
||||
acceptChild(v, outOf);
|
||||
acceptChild(v, on);
|
||||
acceptChild(v, percent);
|
||||
acceptChild(v, byteLength);
|
||||
}
|
||||
v.endVisit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean replace(SQLExpr expr, SQLExpr target) {
|
||||
if (bucket == expr) {
|
||||
setBucket(target);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (outOf == expr) {
|
||||
setOutOf(target);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (on == expr) {
|
||||
setOn(target);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (percent == expr) {
|
||||
setPercent(target);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (byteLength == expr) {
|
||||
setByteLength(target);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public SQLExpr getByteLength() {
|
||||
return byteLength;
|
||||
}
|
||||
|
||||
public void setByteLength(SQLExpr x) {
|
||||
if (x != null) {
|
||||
x.setParent(this);
|
||||
}
|
||||
this.byteLength = x;
|
||||
}
|
||||
|
||||
public SQLExpr getRows() {
|
||||
return rows;
|
||||
}
|
||||
|
||||
public void setRows(SQLExpr x) {
|
||||
if (x != null) {
|
||||
x.setParent(this);
|
||||
}
|
||||
this.rows = x;
|
||||
}
|
||||
|
||||
public boolean isBernoulli() {
|
||||
return bernoulli;
|
||||
}
|
||||
|
||||
public void setBernoulli(boolean bernoulli) {
|
||||
this.bernoulli = bernoulli;
|
||||
}
|
||||
|
||||
public boolean isSystem() {
|
||||
return system;
|
||||
}
|
||||
|
||||
public void setSystem(boolean system) {
|
||||
this.system = system;
|
||||
}
|
||||
}
|
||||
@@ -144,4 +144,24 @@ public abstract class SQLTableSourceImpl extends SQLObjectImpl implements SQLTab
|
||||
public SQLObject resolveColum(long columnNameHash) {
|
||||
return findColumn(columnNameHash);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
SQLTableSourceImpl that = (SQLTableSourceImpl) o;
|
||||
|
||||
if (aliasHashCode64() != that.aliasHashCode64()) return false;
|
||||
if (hints != null ? !hints.equals(that.hints) : that.hints != null) return false;
|
||||
return flashback != null ? flashback.equals(that.flashback) : that.flashback == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = (hints != null ? hints.hashCode() : 0);
|
||||
result = 31 * result + (flashback != null ? flashback.hashCode() : 0);
|
||||
result = 31 * result + (int) (aliasHashCode64() ^ (aliasHashCode64() >>> 32));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.alibaba.druid.sql.ast.statement;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SQLUnnestTableSource
|
||||
extends SQLTableSourceImpl {
|
||||
private final List<SQLExpr> items = new ArrayList<SQLExpr>();
|
||||
protected List<SQLName> columns = new ArrayList<SQLName>();
|
||||
private boolean ordinality = false;
|
||||
|
||||
public SQLUnnestTableSource() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor v) {
|
||||
if (v.visit(this)) {
|
||||
acceptChild(v, items);
|
||||
acceptChild(v, columns);
|
||||
}
|
||||
v.endVisit(this);
|
||||
}
|
||||
|
||||
public List<SQLName> getColumns() {
|
||||
return columns;
|
||||
}
|
||||
|
||||
public void addColumn(SQLName column) {
|
||||
column.setParent(this);
|
||||
this.columns.add(column);
|
||||
}
|
||||
|
||||
public boolean isOrdinality() {
|
||||
return ordinality;
|
||||
}
|
||||
|
||||
public void setOrdinality(boolean ordinality) {
|
||||
this.ordinality = ordinality;
|
||||
}
|
||||
|
||||
public List<SQLExpr> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void addItem(SQLExpr item) {
|
||||
item.setParent(this);
|
||||
this.items.add(item);
|
||||
}
|
||||
|
||||
public SQLUnnestTableSource clone() {
|
||||
SQLUnnestTableSource x = new SQLUnnestTableSource();
|
||||
|
||||
for (SQLExpr item : items) {
|
||||
SQLExpr item2 = item.clone();
|
||||
item2.setParent(x);
|
||||
x.items.add(item2);
|
||||
}
|
||||
|
||||
for (SQLName column : columns) {
|
||||
SQLName c2 = column.clone();
|
||||
c2.setParent(x);
|
||||
x.columns.add(c2);
|
||||
}
|
||||
|
||||
x.alias = alias;
|
||||
|
||||
return x;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user