Skip to content

Commit

Permalink
Support impala ddl parser
Browse files Browse the repository at this point in the history
  • Loading branch information
woyumen4597 authored and wenshao committed Aug 9, 2024
1 parent 786cefd commit cfc1ac5
Show file tree
Hide file tree
Showing 15 changed files with 900 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public class SQLPartitionValue extends OracleSegmentAttributesImpl {
protected Operator operator;
protected final List<SQLExpr> items = new ArrayList<SQLExpr>();

public SQLPartitionValue() {
}

public SQLPartitionValue(Operator operator) {
super();
this.operator = operator;
Expand All @@ -45,8 +48,10 @@ public Operator getOperator() {
return operator;
}

public static enum Operator {
public enum Operator {
LessThan,
LessThanEqual,
Equal,
In,
List
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ protected void parseLike(HiveCreateTableStatement stmt) {
}
}

private void parseSortedBy(HiveCreateTableStatement stmt) {
protected void parseSortedBy(HiveCreateTableStatement stmt) {
lexer.nextToken();
accept(Token.BY);
accept(Token.LPAREN);
Expand All @@ -415,7 +415,7 @@ private void parseSortedBy(HiveCreateTableStatement stmt) {
accept(Token.RPAREN);
}

private void parseRowFormat(HiveCreateTableStatement stmt) {
protected void parseRowFormat(HiveCreateTableStatement stmt) {
SQLExternalRecordFormat format = this.getExprParser().parseRowFormat();
stmt.setRowFormat(format);
parseCreateTableWithSerderPropertie(stmt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,10 +519,12 @@ protected void printTableOptionsPrefix(SQLCreateTableStatement x) {

@Override
public boolean visit(SQLCreateTableStatement x) {
printCreateTable((HiveCreateTableStatement) x, true);
printCreateTable((HiveCreateTableStatement) x, true, true);
return false;
}
protected void printCreateTable(HiveCreateTableStatement x, boolean printSelect) {

protected void printCreateTable(HiveCreateTableStatement x, boolean printSelect,
boolean printCommentAdvance) {
final SQLObject parent = x.getParent();

if (x.hasBeforeComment()) {
Expand Down Expand Up @@ -561,7 +563,9 @@ protected void printCreateTable(HiveCreateTableStatement x, boolean printSelect)
using.accept(this);
}

printComment(x.getComment());
if (printCommentAdvance) {
printComment(x.getComment());
}

List<SQLAssignItem> mappedBy = x.getMappedBy();
if (mappedBy != null && mappedBy.size() > 0) {
Expand All @@ -581,12 +585,7 @@ protected void printCreateTable(HiveCreateTableStatement x, boolean printSelect)
print(')');
}
List<SQLSelectOrderByItem> sortedBy = x.getSortedBy();
if (sortedBy.size() > 0) {
println();
print0(ucase ? "SORTED BY (" : "sorted by (");
printAndAccept(sortedBy, ", ");
print(')');
}
printSortedBy(sortedBy);
int buckets = x.getBuckets();
if (buckets > 0) {
println();
Expand All @@ -611,7 +610,10 @@ protected void printCreateTable(HiveCreateTableStatement x, boolean printSelect)
print(ucase ? " STORED AS DIRECTORIES" : " stored as directories");
}
}

if (!printCommentAdvance) {
printComment(x.getComment());
}
printPartitionBy(x);
SQLExternalRecordFormat format = x.getRowFormat();
SQLExpr storedBy = x.getStoredBy();
if (format != null) {
Expand Down Expand Up @@ -665,6 +667,7 @@ protected void printCreateTable(HiveCreateTableStatement x, boolean printSelect)
printExpr(location, parameterized);
}

printCached(x);
printTableOptions(x);
printLifeCycle(x.getLifeCycle());

Expand All @@ -681,4 +684,8 @@ protected void printCreateTable(HiveCreateTableStatement x, boolean printSelect)
visit(select);
}
}

protected void printCached(SQLCreateTableStatement x) {
// do nothing
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.alibaba.druid.sql.dialect.impala.ast;

import com.alibaba.druid.sql.ast.SQLPartitionValue;

public class ImpalaSQLPartitionValue extends SQLPartitionValue {
private Integer leftBound;
private Integer rightBound;
private Operator leftOperator;
private Operator rightOperator;

public void setOperator(Operator operator) {
this.operator = operator;
}

public Integer getLeftBound() {
return leftBound;
}

public void setLeftBound(Integer leftBound) {
this.leftBound = leftBound;
}

public Integer getRightBound() {
return rightBound;
}

public void setRightBound(Integer rightBound) {
this.rightBound = rightBound;
}

public String constructPartitionName() {
StringBuilder sb = new StringBuilder();
sb.append("partition_").append(leftBound != null ? leftBound.toString() : "")
.append("_").append(rightBound != null ? rightBound.toString() : "");
return sb.toString();
}

public Operator getLeftOperator() {
return leftOperator;
}

public void setLeftOperator(Operator leftOperator) {
this.leftOperator = leftOperator;
}

public Operator getRightOperator() {
return rightOperator;
}

public void setRightOperator(Operator rightOperator) {
this.rightOperator = rightOperator;
}
}
Loading

0 comments on commit cfc1ac5

Please sign in to comment.