Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

impala support kudu column attributes #6182

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
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.SQLIntegerExpr;
import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;

Expand Down Expand Up @@ -70,8 +71,8 @@ public class SQLColumnDefinition extends SQLObjectImpl implements SQLTableElemen
private SQLExpr unitCount;
private SQLExpr unitIndex;
private SQLExpr step;
private SQLCharExpr encode;
private SQLCharExpr compression;
private SQLExpr encode;
private SQLExpr compression;
protected SQLCharExpr aggType; // for starrocks
protected SQLCharExpr bitmap; // for starrocks
protected SQLCharExpr indexComment; // for starrocks
Expand All @@ -80,6 +81,8 @@ public class SQLColumnDefinition extends SQLObjectImpl implements SQLTableElemen
private List<SQLAssignItem> mappedBy;
private List<SQLAssignItem> colProperties;

protected SQLIntegerExpr blockSize; // for impala for kudu

private boolean generateByDefault;

public SQLCharExpr getIndexComment() {
Expand Down Expand Up @@ -852,22 +855,30 @@ public List<SQLAssignItem> getColProperties() {
return colProperties;
}

public SQLCharExpr getEncode() {
public SQLExpr getEncode() {
return encode;
}

public void setEncode(SQLCharExpr encode) {
public void setEncode(SQLExpr encode) {
this.encode = encode;
}

public SQLCharExpr getCompression() {
public SQLExpr getCompression() {
return compression;
}

public void setCompression(SQLCharExpr compression) {
public void setCompression(SQLExpr compression) {
this.compression = compression;
}

public void setBlockSize(SQLIntegerExpr blockSize) {
this.blockSize = blockSize;
}

public SQLIntegerExpr getBlockSize() {
return blockSize;
}

public List<SQLAssignItem> getColPropertiesDirect() {
return colProperties;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.alibaba.druid.sql.ast.expr.SQLCharExpr;
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
import com.alibaba.druid.sql.ast.expr.SQLIntegerExpr;
import com.alibaba.druid.sql.ast.statement.SQLColumnDefinition;
import com.alibaba.druid.sql.ast.statement.SQLExprHint;
import com.alibaba.druid.sql.dialect.hive.parser.HiveExprParser;
import com.alibaba.druid.sql.dialect.impala.ast.ImpalaSQLPartitionValue;
Expand All @@ -25,6 +26,22 @@ public ImpalaExprParser(String sql, SQLParserFeature... features) {
dbType = DbType.impala;
}

public SQLColumnDefinition parseColumnRest(SQLColumnDefinition column) {
if (lexer.nextIfIdentifier("ENCODING")) {
column.setEncode(this.expr());
}

if (lexer.nextIfIdentifier(FnvHash.Constants.COMPRESSION)) {
column.setCompression(this.expr());
}

if (lexer.nextIfIdentifier("BLOCK_SIZE")) {
column.setBlockSize(this.integerExpr());
}

return super.parseColumnRest(column);
}

public SQLPartition parsePartition() {
accept(Token.PARTITION);
SQLPartition partitionDef = new SQLPartition();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,20 @@ public boolean visit(SQLPartition x) {
return false;
}

protected void printEncoding(SQLColumnDefinition x) {
if (x.getEncode() != null) {
print0(ucase ? " ENCODING " : " encoding ");
x.getEncode().accept(this);
}
}

protected void printCompression(SQLColumnDefinition x) {
if (x.getCompression() != null) {
print0(ucase ? " COMPRESSION " : " compression ");
x.getCompression().accept(this);
}
}

@Override
public boolean visit(SQLPartitionValue x) {
if (x instanceof ImpalaSQLPartitionValue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3522,19 +3522,36 @@ public boolean visit(SQLColumnDefinition x) {

printColumnProperties(x);

printEncoding(x);

printCompression(x);

printBlockSize(x);

this.parameterized = parameterized;

return false;
}

protected void printEncoding(SQLColumnDefinition x) {
if (x.getEncode() != null) {
print0(ucase ? " ENCODE=" : " encode=");
x.getEncode().accept(this);
}
}

protected void printCompression(SQLColumnDefinition x) {
if (x.getCompression() != null) {
print0(ucase ? " COMPRESSION=" : " compression=");
x.getCompression().accept(this);
}
}

this.parameterized = parameterized;

return false;
protected void printBlockSize(SQLColumnDefinition x) {
if (x.getBlockSize() != null) {
print0(ucase ? " BLOCK_SIZE " : " block_size ");
x.getBlockSize().accept(this);
}
}

protected void printColumnProperties(SQLColumnDefinition x) {
Expand Down
30 changes: 30 additions & 0 deletions core/src/test/resources/bvt/parser/impala/6.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
CREATE TABLE dwd_kudu.t09_miu_shop_commodity_status_log (
id STRING DEFAULT 0 NOT NULL ENCODING AUTO_ENCODING COMPRESSION DEFAULT_COMPRESSION DEFAULT 0,
shop_commodity_id STRING NULL ENCODING AUTO_ENCODING COMPRESSION DEFAULT_COMPRESSION,
shop_commodity STRING NULL ENCODING AUTO_ENCODING COMPRESSION DEFAULT_COMPRESSION BLOCK_SIZE 1024,
PRIMARY KEY (id)
) PARTITION BY HASH (id) PARTITIONS 8
COMMENT '商品上下架日志表'
STORED AS KUDU
TBLPROPERTIES (
'STATS_GENERATED' = '',
'impala.lastComputeStatsTime' = '',
'kudu.master_addresses' = '',
'numRows' = ''
)
--------------------
CREATE TABLE dwd_kudu.t09_miu_shop_commodity_status_log (
id STRING DEFAULT 0 NOT NULL ENCODING AUTO_ENCODING COMPRESSION DEFAULT_COMPRESSION,
shop_commodity_id STRING NULL ENCODING AUTO_ENCODING COMPRESSION DEFAULT_COMPRESSION,
shop_commodity STRING NULL ENCODING AUTO_ENCODING COMPRESSION DEFAULT_COMPRESSION BLOCK_SIZE 1024,
PRIMARY KEY (id)
)
COMMENT '商品上下架日志表'
PARTITION BY HASH (id) PARTITIONS 8
STORED AS KUDU
TBLPROPERTIES (
'STATS_GENERATED' = '',
'impala.lastComputeStatsTime' = '',
'kudu.master_addresses' = '',
'numRows' = ''
)
Loading