improved odps sql formatter

This commit is contained in:
shaojin.wensj
2015-07-28 22:24:07 +08:00
parent 29d0889d86
commit 87f3f8144b
6 changed files with 61 additions and 21 deletions
@@ -18,8 +18,8 @@ public class OdpsFormatCommentTest extends TestCase {
String sql = "select f1 -- aaa"
+ "\n, f2 -- bbb"
+ "\n from t1";
Assert.assertEquals("SELECT f1, -- aaa" //
+ "\n\tf2 -- bbb" //
Assert.assertEquals("SELECT f1 -- aaa" //
+ "\n\t, f2 -- bbb" //
+ "\nFROM t1", SQLUtils.formatOdps(sql));
}
@@ -27,8 +27,8 @@ public class OdpsFormatCommentTest extends TestCase {
String sql = "select f1 /*aa*/"
+ "\n, f2 -- bbb"
+ "\n from t1";
Assert.assertEquals("SELECT f1, /*aa*/" //
+ "\n\tf2 -- bbb" //
Assert.assertEquals("SELECT f1 /*aa*/" //
+ "\n\t, f2 -- bbb" //
+ "\nFROM t1", SQLUtils.formatOdps(sql));
}
}
@@ -0,0 +1,19 @@
package com.alibaba.druid.bvt.sql.odps;
import org.junit.Assert;
import com.alibaba.druid.sql.SQLUtils;
import junit.framework.TestCase;
public class OdpsFormatCommentTest20 extends TestCase {
public void test_column_comment() throws Exception {
String sql = "select * from a full outer join b on a.id=b.id";
Assert.assertEquals("SELECT *"
+ "\nFROM a"
+ "\nFULL OUTER JOIN b"
+ "\n\tON a.id = b.id", SQLUtils.formatOdps(sql));
}
}
@@ -24,15 +24,15 @@ public class OdpsFormatCommentTest4 extends TestCase {
+ "\n) a" //
+ "\n-- comment_0"//
+ "\nINSERT OVERWRITE TABLE b PARTITION (ds='20150711')"//
+ "\nSELECT f0, "//
+ "\n\tf1, "//
+ "\n\tf2"//
+ "\nSELECT f0"//
+ "\n\t, f1"//
+ "\n\t, f2"//
+ "\nWHERE name RLIKE 'xxxx'" //
+ "\n-- comment_1"//
+ "\nINSERT OVERWRITE TABLE c PARTITION (ds='20150711')"//
+ "\nSELECT f0, "//
+ "\n\tf1, "//
+ "\n\tf2"//
+ "\nSELECT f0"//
+ "\n\t, f1"//
+ "\n\t, f2"//
+ "\nWHERE name RLIKE 'kk';", SQLUtils.formatOdps(sql));
}
@@ -30,11 +30,12 @@ public class OdpsSelectTest_mapjoin extends TestCase {
+ "\nb.total_price"
+ "\nfrom shop a join sale_detail b"
+ "\non a.shop_name = b.shop_name;";
Assert.assertEquals("SELECT /*+ mapjoin(a) */ a.shop_name, "
+ "\n\tb.customer_id, "
+ "\n\tb.total_price"
Assert.assertEquals("SELECT /*+ mapjoin(a) */ a.shop_name"
+ "\n\t, b.customer_id"
+ "\n\t, b.total_price"
+ "\nFROM shop a"
+ "\nJOIN sale_detail b ON a.shop_name = b.shop_name;", SQLUtils.formatOdps(sql));
+ "\nJOIN sale_detail b"
+ "\n\tON a.shop_name = b.shop_name;", SQLUtils.formatOdps(sql));
}