Skip to content

Commit

Permalink
Implement databricks create or replace temp table.
Browse files Browse the repository at this point in the history
  • Loading branch information
lingo-xp authored and wenshao committed Feb 4, 2025
1 parent 992bc0c commit bc5f33d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.alibaba.druid.sql.parser.SQLExprParser;
import com.alibaba.druid.sql.parser.SQLSelectParser;
import com.alibaba.druid.sql.parser.Token;
import com.alibaba.druid.util.FnvHash;

public class DatabricksCreateTableParser extends SparkCreateTableParser {
public DatabricksCreateTableParser(SQLExprParser exprParser) {
Expand All @@ -19,5 +20,10 @@ protected void createTableBefore(SQLCreateTableStatement createTable) {
accept(Token.REPLACE);
createTable.config(SQLCreateTableStatement.Feature.OrReplace);
}

if (lexer.identifierEquals(FnvHash.Constants.TEMPORARY) || lexer.identifierEquals("temp")) {
lexer.nextToken();
createTable.setTemporary(true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10664,6 +10664,9 @@ public boolean visit(MySqlCreateTableStatement x) {
}

protected void printCreateTableFeatures(SQLCreateTableStatement x) {
if (x.isEnabled(SQLCreateTableStatement.Feature.OrReplace)) {
print0(ucase ? "OR REPLACE " : "or replace ");
}
SQLCreateTableStatement.Feature[] features = {
SQLCreateTableStatement.Feature.Global,
SQLCreateTableStatement.Feature.Local,
Expand All @@ -10682,10 +10685,6 @@ protected void printCreateTableFeatures(SQLCreateTableStatement x) {
print(' ');
}
}

if (x.isEnabled(SQLCreateTableStatement.Feature.OrReplace)) {
print0(ucase ? "OR REPLACE " : "or replace ");
}
}

@Override
Expand Down
7 changes: 7 additions & 0 deletions core/src/test/resources/bvt/parser/databricks/0.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
create or replace temp table c as select a from b
--------------------
CREATE OR REPLACE TEMPORARY TABLE c
AS
SELECT a
FROM b
------------------------------------------------------------------------------------------------------------------------
refresh table mc_power_insight_dm_ngbi_uat.dm_td_institution;
--------------------
REFRESH TABLE mc_power_insight_dm_ngbi_uat.dm_td_institution;
Expand Down

0 comments on commit bc5f33d

Please sign in to comment.