refactor SQLUtils

This commit is contained in:
高铁
2016-03-12 13:05:12 +08:00
parent 70f8c43a26
commit d9a6fde5d6
19 changed files with 382 additions and 197 deletions
@@ -12,11 +12,15 @@ public class OdpsAlterTableDropPartitionTest extends TestCase {
String sql = "alter table sale_detail drop if not exists partition (sale_date='201312', region='hangzhou');";
Assert.assertEquals("ALTER TABLE sale_detail" //
+ "\n\tDROP IF NOT EXISTS PARTITION (sale_date = '201312', region = 'hangzhou');", SQLUtils.formatOdps(sql));
Assert.assertEquals("alter table sale_detail" //
+ "\n\tdrop if not exists partition (sale_date = '201312', region = 'hangzhou');", SQLUtils.formatOdps(sql, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
}
public void test_purge() throws Exception {
String sql = "alter table my_log drop partition (ds='20150618') purge;";
Assert.assertEquals("ALTER TABLE my_log"
+ "\n\tDROP PARTITION (ds = '20150618') PURGE;", SQLUtils.formatOdps(sql));
Assert.assertEquals("alter table my_log"
+ "\n\tdrop partition (ds = '20150618') purge;", SQLUtils.formatOdps(sql, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
}
}
@@ -22,6 +22,16 @@ public class OdpsFormatCommentTest8 extends TestCase {
+ "\n"
+ "\nSELECT *"
+ "\nFROM table3;--comment2 goes here", SQLUtils.formatOdps(sql));
Assert.assertEquals("select *"
+ "\nfrom table1;"
+ "\n"
+ "\n--comment1 goes here"
+ "\nselect *"
+ "\nfrom table2;"
+ "\n"
+ "\nselect *"
+ "\nfrom table3;--comment2 goes here", SQLUtils.formatOdps(sql, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
}
@@ -42,6 +42,9 @@ public class OdpsSelectTest extends TestCase {
Assert.assertEquals("SELECT region" //
+ "\nFROM sale_detail" //
+ "\nDISTRIBUTE BY region SORT BY f1 ASC;", SQLUtils.formatOdps(sql));
Assert.assertEquals("select region" //
+ "\nfrom sale_detail" //
+ "\ndistribute by region sort by f1 asc;", SQLUtils.formatOdps(sql, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
}
}