-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix when insert replace issue. (#6289)
* improved sql parser bigquery support * Fix merge when replace issue. --------- Co-authored-by: wenshao <[email protected]>
- Loading branch information
Showing
2 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
core/src/test/java/com/alibaba/druid/bvt/sql/ReplaceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.alibaba.druid.bvt.sql; | ||
|
||
import com.alibaba.druid.sql.SQLUtils; | ||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr; | ||
import com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr; | ||
import com.alibaba.druid.sql.ast.statement.SQLMergeStatement; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
|
||
public class ReplaceTest { | ||
@Test | ||
public void test_when() { | ||
SQLMergeStatement.WhenInsert when = new SQLMergeStatement.WhenInsert(); | ||
when.addColumn(new SQLIdentifierExpr("id")); | ||
when.addColumn(new SQLIdentifierExpr("id2")); | ||
SQLIdentifierExpr current_timestamp_identifier1 = new SQLIdentifierExpr("current_timestamp"); | ||
SQLIdentifierExpr current_timestamp_identifier2 = new SQLIdentifierExpr("current_timestamp"); | ||
when.addValue(current_timestamp_identifier1); | ||
when.addValue(current_timestamp_identifier2); | ||
SQLMethodInvokeExpr current_timestamp_method1 = new SQLMethodInvokeExpr("current_timestamp"); | ||
SQLMethodInvokeExpr current_timestamp_method2 = new SQLMethodInvokeExpr("current_timestamp"); | ||
SQLUtils.replaceInParent(current_timestamp_identifier1, current_timestamp_method1); | ||
SQLUtils.replaceInParent(current_timestamp_identifier2, current_timestamp_method2); | ||
Assert.assertEquals(current_timestamp_method1, when.getValues().get(0)); | ||
Assert.assertEquals(current_timestamp_method2, when.getValues().get(1)); | ||
} | ||
} |