forked from alibaba/druid
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
优化hive sql set hivevar的sql生成 alibaba#5901
优化hive sql set hivevar的sql生成 alibaba#5901
- Loading branch information
Showing
2 changed files
with
44 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
39 changes: 39 additions & 0 deletions
39
core/src/test/java/com/alibaba/druid/bvt/sql/hive/issues/Issue5901.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,39 @@ | ||
package com.alibaba.druid.bvt.sql.hive.issues; | ||
|
||
import java.util.List; | ||
|
||
import com.alibaba.druid.DbType; | ||
import com.alibaba.druid.sql.SQLParseAssertUtil; | ||
import com.alibaba.druid.sql.ast.SQLStatement; | ||
import com.alibaba.druid.sql.parser.SQLParserUtils; | ||
import com.alibaba.druid.sql.parser.SQLStatementParser; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
/** | ||
* @author lizongbo | ||
* @see <a href="https://github.com/alibaba/druid/issues/5901>Issue来源</a> | ||
*/ | ||
public class Issue5901 { | ||
|
||
@Test | ||
public void test_parse_set() { | ||
for (DbType dbType : new DbType[]{DbType.hive}) { | ||
for (String sql : new String[]{ | ||
"SET hivevar:account_period = IF(${hivevar:now_month} >= 3 and ${hivevar:now_month} < 6, CONCAT(${hivevar:now_year}, '-03XYZ'), ${hivevar:now_year});\n" | ||
, | ||
}) { | ||
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, dbType); | ||
List<SQLStatement> statementList = parser.parseStatementList(); | ||
assertEquals(1, statementList.size()); | ||
assertEquals( | ||
"SET hivevar:account_period = IF(${hivevar:now_month} >= 3 AND ${hivevar:now_month} < 6, CONCAT(${hivevar:now_year}, '-03XYZ'), ${hivevar:now_year});" | ||
, statementList.get(0).toString()); | ||
SQLParseAssertUtil.assertParseSql(sql, dbType); | ||
} | ||
} | ||
} | ||
|
||
} |