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));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -38,7 +38,8 @@ from (
|
||||
|
||||
---------------------------
|
||||
SELECT COUNT(*)
|
||||
FROM (SELECT a.activity_offer_id AS adResourceId, a.title AS adResourceName, a.b2boffer_url AS adResourceURL, a.custid, b.memberid
|
||||
FROM (
|
||||
SELECT a.activity_offer_id AS adResourceId, a.title AS adResourceName, a.b2boffer_url AS adResourceURL, a.custid, b.memberid
|
||||
, c.position_name AS positionName, c.charge_setting AS feeRegulation, a.priority_weight AS priorityWeight, a.audit_state AS adResourceState, 0 AS adResourceType
|
||||
, a.gmt_create, a.refuse_remark
|
||||
FROM q_activity_offer_enroll a, q_custinfo b, q_activity_position c
|
||||
@@ -53,4 +54,4 @@ FROM (SELECT a.activity_offer_id AS adResourceId, a.title AS adResourceName, a.b
|
||||
WHERE a.custid = b.custid
|
||||
AND a.activity_position_id = c.activity_position_id
|
||||
AND c.activity_id = ?
|
||||
) a
|
||||
) a
|
||||
|
||||
@@ -7,13 +7,14 @@ WHERE a.examine_id = b.examine_id
|
||||
|
||||
---------------------------
|
||||
SELECT a.examine_id AS examineId, a.examine_name AS examineName, a.level_limit AS levelLimit
|
||||
FROM c_examinepaper a, (SELECT examine_id
|
||||
FROM c_examinepaper a, (
|
||||
SELECT examine_id
|
||||
FROM c_examinepaper
|
||||
WHERE level_limit = ?
|
||||
AND status = 1
|
||||
MINUS
|
||||
SELECT DISTINCT examine_id
|
||||
FROM course
|
||||
) b
|
||||
) b
|
||||
WHERE a.examine_id = b.examine_id
|
||||
|
||||
|
||||
Reference in New Issue
Block a user