improved odps sql formmatter

This commit is contained in:
shaojin.wensj
2015-07-28 23:33:01 +08:00
parent 3de275fa8c
commit 9d45ec9d12
4 changed files with 64 additions and 4 deletions
@@ -0,0 +1,28 @@
package com.alibaba.druid.bvt.sql.odps;
import org.junit.Assert;
import com.alibaba.druid.sql.SQLUtils;
import junit.framework.TestCase;
public class OdpsFormatCommentTest22 extends TestCase {
public void test_if() throws Exception {
String sql = "select if(a>0,1, 0) from dual";
Assert.assertEquals("SELECT IF(a > 0, 1, 0)"
+ "\nFROM dual", SQLUtils.formatOdps(sql));
}
public void test_coalesce() throws Exception {
String sql = "select coalesce(f1,f2) from dual";
Assert.assertEquals("SELECT COALESCE(f1, f2)"
+ "\nFROM dual", SQLUtils.formatOdps(sql));
}
public void test_count() throws Exception {
String sql = "select count(*) from dual";
Assert.assertEquals("SELECT COUNT(*)"
+ "\nFROM dual", SQLUtils.formatOdps(sql));
}
}
@@ -10,7 +10,7 @@ public class OdpsIfTest extends TestCase {
public void test_if() throws Exception {
String sql = "select sum(if(a > 0, 1, 0)) from t1";
Assert.assertEquals("SELECT SUM(if(a > 0, 1, 0))" //
Assert.assertEquals("SELECT SUM(IF(a > 0, 1, 0))" //
+ "\nFROM t1", SQLUtils.formatOdps(sql));
}
}