mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved odps sql formatter
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
package com.alibaba.druid.bvt.sql.odps;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class OdpsFormatCommentTest11 extends TestCase {
|
||||
public void test_column_comment() throws Exception {
|
||||
String sql = "select * from t where -- comment_xx"
|
||||
+ "\n f1 > 0";
|
||||
Assert.assertEquals("SELECT *" //
|
||||
+ "\nFROM t" //
|
||||
+ "\nWHERE -- comment_xx"
|
||||
+ "\nf1 > 0", SQLUtils.formatOdps(sql));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.alibaba.druid.bvt.sql.odps;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class OdpsFormatCommentTest12 extends TestCase {
|
||||
public void test_column_comment() throws Exception {
|
||||
String sql = "select * from t --abc";
|
||||
Assert.assertEquals("SELECT *" //
|
||||
+ "\nFROM t --abc", SQLUtils.formatOdps(sql));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.alibaba.druid.bvt.sql.odps;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class OdpsFormatCommentTest13 extends TestCase {
|
||||
public void test_column_comment() throws Exception {
|
||||
String sql = "select * from t where f0 > 0 -- comment_0"
|
||||
+ "\n and -- comment_1"
|
||||
+ "\n f1 > 1 -- comment_2"
|
||||
+ "\n and -- comment_3"
|
||||
+ "\n f2 > 2 -- comment_4";
|
||||
Assert.assertEquals("SELECT *"
|
||||
+ "\nFROM t"
|
||||
+ "\nWHERE f0 > 0 -- comment_0"
|
||||
+ "\n\tAND -- comment_1"
|
||||
+ "\n\tf1 > 1 -- comment_2"
|
||||
+ "\n\tAND -- comment_3"
|
||||
+ "\n\tf2 > 2 -- comment_4", SQLUtils.formatOdps(sql));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.alibaba.druid.bvt.sql.odps;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class OdpsFormatCommentTest14 extends TestCase {
|
||||
public void test_column_comment() throws Exception {
|
||||
String sql = "select * from (" //
|
||||
+ "select 1 from t1"
|
||||
+ "\n --c_0"
|
||||
+ "\n union all "
|
||||
+ "\n --c_1" //
|
||||
+ "\nselect 2 from t2" //
|
||||
+ "\n --c_2"
|
||||
+ "\n union all "
|
||||
+ "\n --c_3" //
|
||||
+ "\nselect 3 from t3" //
|
||||
+ ") xx";
|
||||
Assert.assertEquals("SELECT *"
|
||||
+ "\nFROM ("
|
||||
+ "\n\tSELECT 1"
|
||||
+ "\n\tFROM t1 --c_0"
|
||||
+ "\n\tUNION ALL"
|
||||
+ "\n\t--c_1"
|
||||
+ "\n\tSELECT 2"
|
||||
+ "\n\tFROM t2 --c_2"
|
||||
+ "\n\tUNION ALL"
|
||||
+ "\n\t--c_3"
|
||||
+ "\n\tSELECT 3"
|
||||
+ "\n\tFROM t3"
|
||||
+ "\n) xx", SQLUtils.formatOdps(sql));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -20,7 +20,7 @@ public class OdpsFormatCommentTest8 extends TestCase {
|
||||
+ "\nFROM table2;"
|
||||
+ "\nSELECT *"
|
||||
+ "\nFROM table3"
|
||||
+ "\n;--comment2 goes her", SQLUtils.formatOdps(sql));
|
||||
+ "\n;--comment2 goes here", SQLUtils.formatOdps(sql));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user