Merge pull request #947 from wenshao/master

bug fixed for mysql connection validation checker, and improved odps …
This commit is contained in:
高铁
2015-09-07 11:27:10 +08:00
20 changed files with 314 additions and 51 deletions
@@ -9,7 +9,7 @@ import com.alibaba.druid.wall.WallUtils;
public class PGWallTest extends TestCase {
public void test_false() throws Exception {
Assert.assertFalse(WallUtils.isValidatePostgres(//
Assert.assertTrue(WallUtils.isValidatePostgres(//
"select wm_concat(article_id) over() from t_nds_web_article")); //
}
}
@@ -50,8 +50,12 @@ public class OdpsResourceTest extends TestCase {
JdbcUtils.close(reader);
String[] items = input.split("---------------------------");
String sql = items[0].trim();
String expect = items[1].trim();
String expect = null;
if (items.length > 1) {
expect = items[1].trim();
}
OdpsStatementParser parser = new OdpsStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement stmt = statementList.get(0);
@@ -0,0 +1,42 @@
/*
* Copyright 1999-2101 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.bvt.sql.odps;
import org.junit.Assert;
import com.alibaba.druid.sql.SQLUtils;
import junit.framework.TestCase;
public class OdpsSelectTest2 extends TestCase {
public void test_distribute_by() throws Exception {
String sql = "SELECT user_id,user_flag,cat1_id,wireless_client_type,alipay_num,last_buy_time,md5,my_udf_001('t_datax_odps2ots_resource_tcif_dmp_user_topup_d',md5) AS datax_pt FROM mytable_001 WHERE ds='20150819' DISTRIBUTE BY cast (datax_pt as BIGINT) SORT BY md5,user_id,user_flag,cat1_id,wireless_client_type";//
Assert.assertEquals("SELECT user_id"
+ "\n\t, user_flag"
+ "\n\t, cat1_id"
+ "\n\t, wireless_client_type"
+ "\n\t, alipay_num"
+ "\n\t, last_buy_time"
+ "\n\t, md5"
+ "\n\t, my_udf_001('t_datax_odps2ots_resource_tcif_dmp_user_topup_d', md5) AS datax_pt"
+ "\nFROM mytable_001"
+ "\nWHERE ds = '20150819'"
+ "\nDISTRIBUTE BY CAST(datax_pt AS BIGINT) SORT BY md5, user_id, user_flag, cat1_id, wireless_client_type", SQLUtils.formatOdps(sql));
}
}
@@ -0,0 +1,33 @@
/*
* Copyright 1999-2101 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.bvt.sql.odps;
import org.junit.Assert;
import com.alibaba.druid.sql.SQLUtils;
import junit.framework.TestCase;
public class OdpsSelectTest3 extends TestCase {
public void test_distribute_by() throws Exception {
String sql = "select RANK() OVER (PARTITION BY ui ORDER BY duration DESC) rank from dual";//
Assert.assertEquals("SELECT RANK() OVER (PARTITION BY ui ORDER BY duration DESC) AS rank"
+ "\nFROM dual", SQLUtils.formatOdps(sql));
}
}
@@ -0,0 +1,33 @@
/*
* Copyright 1999-2101 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.bvt.sql.odps;
import org.junit.Assert;
import com.alibaba.druid.sql.SQLUtils;
import junit.framework.TestCase;
public class OdpsSelectTest4 extends TestCase {
public void test_distribute_by() throws Exception {
String sql = "select total_day_cnt * EXP(-datediff(to_date('20150819', 'yyyymmdd'), last_time, 'dd') / 60) from dual";//
Assert.assertEquals("SELECT total_day_cnt * EXP(-datediff(TO_DATE('20150819', 'yyyymmdd'), last_time, 'dd') / 60)"
+ "\nFROM dual", SQLUtils.formatOdps(sql));
}
}
@@ -0,0 +1,20 @@
package com.alibaba.druid.bvt.sql.odps.udf;
import com.alibaba.druid.support.opds.udf.ExportColumns;
import junit.framework.TestCase;
public class ExportColumnsTest0 extends TestCase {
private ExportColumns udf = new ExportColumns();
public void test_0() throws Exception {
String sql = "SELECT fund_base_cv_creative_ocr_judge_control_words_1422189630695(a.tfs, b.ocr_text, a.cates)"
+ "\n AS (tfs, control_word, ocr_word, control_type, cates)"
+ "\n FROM fund_base_cv_ad_auction_ocr_pv_tfs a"
+ "\n JOIN fund_base_cv_ad_auction_ocr_pv_tfs_ocr b ON a.tfs = b.tfs"
+ "\n WHERE a.ds=20150819 and b.ds=20150819;";
udf.evaluate(sql, "odps");
}
}
@@ -0,0 +1,52 @@
/*
* Copyright 1999-2101 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.bvt.sql.postgresql;
import java.util.List;
import org.junit.Assert;
import com.alibaba.druid.sql.PGTest;
import com.alibaba.druid.sql.ast.SQLStatement;
import com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser;
import com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor;
public class PGSelectTest24 extends PGTest {
public void test_0() throws Exception {
String sql = "select wm_concat(article_id) over() from t_nds_web_article";
PGSQLStatementParser parser = new PGSQLStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement statemen = statementList.get(0);
print(statementList);
Assert.assertEquals("SELECT wm_concat(article_id) OVER ()"
+ "\nFROM t_nds_web_article", output(statementList));
Assert.assertEquals(1, statementList.size());
PGSchemaStatVisitor visitor = new PGSchemaStatVisitor();
statemen.accept(visitor);
System.out.println("Tables : " + visitor.getTables());
System.out.println("fields : " + visitor.getColumns());
System.out.println("coditions : " + visitor.getConditions());
Assert.assertEquals(1, visitor.getColumns().size());
Assert.assertEquals(1, visitor.getTables().size());
}
}