improved odps sql formatter

This commit is contained in:
shaojin.wensj
2015-07-20 06:02:49 +08:00
parent a5811a4f3e
commit eb24ee61fc
16 changed files with 181 additions and 44 deletions
@@ -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));
}