mirror of
https://github.com/actiontech/dble.git
synced 2026-01-25 06:18:29 -06:00
druid update to 1.0.28
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -76,7 +76,7 @@
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid</artifactId>
|
||||
<version>1.0.26</version>
|
||||
<version>1.0.28</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLLimit;
|
||||
import com.alibaba.druid.sql.ast.SQLOrderBy;
|
||||
import com.alibaba.druid.sql.ast.SQLOrderingSpecification;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
@@ -23,7 +24,6 @@ import com.alibaba.druid.sql.ast.statement.SQLTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLUnionOperator;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlOrderingExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock.Limit;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUnionQuery;
|
||||
|
||||
import io.mycat.config.ErrorCode;
|
||||
@@ -77,7 +77,7 @@ public class MySQLPlanNodeVisitor {
|
||||
mtvright.visit(right);
|
||||
|
||||
SQLOrderBy orderBy = sqlSelectQuery.getOrderBy();
|
||||
Limit limit = sqlSelectQuery.getLimit();
|
||||
SQLLimit limit = sqlSelectQuery.getLimit();
|
||||
MergeNode mergeNode = new MergeNode();
|
||||
if (sqlSelectQuery.getOperator() != SQLUnionOperator.UNION) {
|
||||
mergeNode.setUnion(true);
|
||||
@@ -128,7 +128,7 @@ public class MySQLPlanNodeVisitor {
|
||||
handleGroupBy(groupBy);
|
||||
}
|
||||
|
||||
Limit limit = sqlSelectQuery.getLimit();
|
||||
SQLLimit limit = sqlSelectQuery.getLimit();
|
||||
if (limit != null) {
|
||||
handleLimit(limit);
|
||||
}
|
||||
@@ -310,7 +310,7 @@ public class MySQLPlanNodeVisitor {
|
||||
|
||||
}
|
||||
|
||||
private void handleLimit(Limit limit) {
|
||||
private void handleLimit(SQLLimit limit) {
|
||||
long from = 0;
|
||||
SQLExpr offest = limit.getOffset();
|
||||
if (offest != null) {
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLLimit;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIntegerExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
|
||||
@@ -16,7 +17,6 @@ import com.alibaba.druid.sql.ast.statement.SQLSubqueryTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLUnionQueryTableSource;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock.Limit;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUnionQuery;
|
||||
|
||||
import io.mycat.MycatServer;
|
||||
@@ -180,7 +180,7 @@ public class DruidSelectParser extends DruidBaseSelectParser {
|
||||
Map<String, Map<String, Set<ColumnRoutePair>>> allConditions = getAllConditions();
|
||||
boolean isNeedAddLimit = isNeedAddLimit(schema, rrs, mysqlSelectQuery, allConditions);
|
||||
if (isNeedAddLimit) {
|
||||
Limit limit = new Limit();
|
||||
SQLLimit limit = new SQLLimit();
|
||||
limit.setRowCount(new SQLIntegerExpr(limitSize));
|
||||
mysqlSelectQuery.setLimit(limit);
|
||||
rrs.setLimitSize(limitSize);
|
||||
@@ -188,7 +188,7 @@ public class DruidSelectParser extends DruidBaseSelectParser {
|
||||
rrs.changeNodeSqlAfterAddLimit(schema, sql, 0, limitSize);
|
||||
|
||||
}
|
||||
Limit limit = mysqlSelectQuery.getLimit();
|
||||
SQLLimit limit = mysqlSelectQuery.getLimit();
|
||||
if (limit != null && !isNeedAddLimit) {
|
||||
SQLIntegerExpr offset = (SQLIntegerExpr) limit.getOffset();
|
||||
SQLIntegerExpr count = (SQLIntegerExpr) limit.getRowCount();
|
||||
@@ -202,7 +202,7 @@ public class DruidSelectParser extends DruidBaseSelectParser {
|
||||
}
|
||||
|
||||
if (isNeedChangeLimit(rrs)) {
|
||||
Limit changedLimit = new Limit();
|
||||
SQLLimit changedLimit = new SQLLimit();
|
||||
changedLimit.setRowCount(new SQLIntegerExpr(limitStart + limitSize));
|
||||
|
||||
if (offset != null) {
|
||||
|
||||
@@ -135,8 +135,15 @@ public class Testparser {
|
||||
// strCreateIndex = "CREATE UNIQUE INDEX part_of_name ON customer (name(10));";
|
||||
// obj.test(strCreateIndex);
|
||||
|
||||
String selectSQl = "select udf(char_columns.id), BIT_AND(char_columns.ID),BIT_OR(char_columns.ID),bit_xor(char_columns.ID),STD(char_columns.ID),STDDEV_SAMP(char_columns.ID), VAR_SAMP(char_columns.ID),VARIANCE(char_columns.ID),sum(id),avg(id),MIN(distinct char_columns.ID),MAX(distinct char_columns.ID),COUNT(char_columns.ID) from char_columns where id =1 and name = 'x';";
|
||||
// obj.test(selectSQl);
|
||||
String selectSQl = "select avg(char_columns.id), BIT_AND(char_columns.ID),BIT_OR(char_columns.ID),bit_xor(char_columns.ID),"
|
||||
+ "COUNT(char_columns.ID),MAX(distinct char_columns.ID),MIN(distinct char_columns.ID),"
|
||||
+ "STD(char_columns.ID),STDDEV(char_columns.ID),STDDEV_POP(char_columns.ID),STDDEV_SAMP(char_columns.ID), "
|
||||
+ "sum(id),VAR_POP(char_columns.ID),VAR_SAMP(char_columns.ID),VARIANCE(char_columns.ID)"
|
||||
+ " from char_columns where id =1 and name = 'x';";
|
||||
obj.test(selectSQl);
|
||||
selectSQl = "SELECT student_name, GROUP_CONCAT(test_score) "
|
||||
+ "FROM student GROUP BY student_name;";
|
||||
obj.test(selectSQl);
|
||||
// selectSQl = "select @@tx_read_only;";
|
||||
// obj.test(selectSQl);
|
||||
// selectSQl = "SELECT ABS(-1);";
|
||||
@@ -149,14 +156,14 @@ public class Testparser {
|
||||
// obj.test(selectSQl);
|
||||
// selectSQl = "select CAST(expr AS datetime(6) ), CAST(expr AS date ), CAST(expr AS time(6) ) from char_columns where id =1 and name = 'x';";
|
||||
// TODO:NOT SUPPORTED
|
||||
selectSQl = "select CAST(expr AS nchar(2) CHARACTER SET utf8),CAST(expr AS char(2)), CAST(expr AS char(2) CHARACTER SET utf8 ),CAST(expr AS char(2) CHARACTER SET latin1 ) from char_columns where id =1 and name = 'x';";
|
||||
// selectSQl = "select CAST(expr AS nchar(2) CHARACTER SET utf8),CAST(expr AS char(2)), CAST(expr AS char(2) CHARACTER SET utf8 ),CAST(expr AS char(2) CHARACTER SET latin1 ) from char_columns where id =1 and name = 'x';";
|
||||
// selectSQl = "select CAST(expr AS char(2) CHARACTER SET utf8 ),CAST(expr AS SIGNED INT ),CAST(expr AS unSIGNED INT ) from char_columns where id =1 and name = 'x';";
|
||||
// obj.test(selectSQl);
|
||||
// selectSQl = "select CONVERT(expr , char(2)) from char_columns where id =1 and name = 'x';";
|
||||
// obj.test(selectSQl);
|
||||
// selectSQl = "SELECT CASE 1 WHEN 1 THEN 'one' WHEN 2 THEN 'two' ELSE 'more' END, CASE WHEN 1>0 THEN 'true' ELSE 'false' END;";
|
||||
// obj.test(selectSQl);
|
||||
// selectSQl = "SELECT - (2), 3/5;";
|
||||
// selectSQl = "SELECT 3 DIV 5, - (2), 3/5;";
|
||||
// obj.test(selectSQl);
|
||||
// selectSQl = "SELECT ~5 , SELECT 29 & 15;";
|
||||
// obj.test(selectSQl);
|
||||
@@ -186,8 +193,8 @@ public class Testparser {
|
||||
//
|
||||
// selectSQl = "SELECT TIMESTAMPADD(WEEK,1,'2003-01-02'), TIMESTAMPDIFF(MONTH,'2003-02-01','2003-05-01'),DATE_ADD(OrderDate,INTERVAL 2 DAY) AS OrderPayDate,ADDDATE('2008-01-02', INTERVAL 31 DAY),ADDDATE('2008-01-02', 31),EXTRACT(YEAR FROM '2009-07-02') FROM Orders;";
|
||||
// obj.test(selectSQl);
|
||||
selectSQl = "SELECT * FROM Orders as t;";
|
||||
obj.test(selectSQl);
|
||||
// selectSQl = "SELECT * FROM Orders as t;";
|
||||
// obj.test(selectSQl);
|
||||
// selectSQl = "select 1,null,'x','xxx';";
|
||||
// obj.test(selectSQl);
|
||||
}
|
||||
@@ -314,8 +321,8 @@ public class Testparser {
|
||||
if (sqlSelectQuery instanceof MySqlSelectQueryBlock) {
|
||||
MySqlSelectQueryBlock selectQueryBlock = (MySqlSelectQueryBlock)sqlSelectQuery;
|
||||
SQLExprTableSource fromSource = (SQLExprTableSource) selectQueryBlock.getFrom();
|
||||
fromSource.setExpr(new SQLIdentifierExpr("`table`"));
|
||||
System.out.println(stament.toString());
|
||||
// fromSource.setExpr(new SQLIdentifierExpr("`table`"));
|
||||
// System.out.println(stament.toString());
|
||||
// System.out.println(sql + ": selectQueryBlock.getFrom() :"+selectQueryBlock.getFrom().getClass().toString() + "\n");
|
||||
for(SQLSelectItem item :selectQueryBlock.getSelectList()){
|
||||
if(item.getExpr()!=null){
|
||||
|
||||
175
src/test/java/io/mycat/memory/unsafe/sort/TestSorter.java
Normal file
175
src/test/java/io/mycat/memory/unsafe/sort/TestSorter.java
Normal file
@@ -0,0 +1,175 @@
|
||||
package io.mycat.memory.unsafe.sort;
|
||||
|
||||
import io.mycat.memory.MyCatMemory;
|
||||
import io.mycat.memory.unsafe.memory.mm.DataNodeMemoryManager;
|
||||
import io.mycat.memory.unsafe.memory.mm.MemoryManager;
|
||||
import io.mycat.memory.unsafe.row.BufferHolder;
|
||||
import io.mycat.memory.unsafe.row.StructType;
|
||||
import io.mycat.memory.unsafe.row.UnsafeRow;
|
||||
import io.mycat.memory.unsafe.row.UnsafeRowWriter;
|
||||
import io.mycat.memory.unsafe.utils.MycatPropertyConf;
|
||||
import io.mycat.memory.unsafe.utils.sort.PrefixComparator;
|
||||
import io.mycat.memory.unsafe.utils.sort.PrefixComparators;
|
||||
import io.mycat.memory.unsafe.utils.sort.RowPrefixComputer;
|
||||
import io.mycat.memory.unsafe.utils.sort.UnsafeExternalRowSorter;
|
||||
import io.mycat.memory.unsafe.utils.sort.UnsafeExternalRowSorter.PrefixComputer;
|
||||
import io.mycat.sqlengine.mpp.ColMeta;
|
||||
import io.mycat.sqlengine.mpp.OrderCol;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
/**
|
||||
* Created by zagnix on 16-7-9.
|
||||
*/
|
||||
public class TestSorter implements Runnable {
|
||||
private static final Logger logger = LoggerFactory.getLogger(TestSorter.class);
|
||||
|
||||
private static final int TEST_SIZE = 1000000;
|
||||
private static int TASK_SIZE = 100;
|
||||
private static CountDownLatch countDownLatch = new CountDownLatch(100);
|
||||
public void runSorter( MyCatMemory myCatMemory,
|
||||
MemoryManager memoryManager,
|
||||
MycatPropertyConf conf) throws NoSuchFieldException, IllegalAccessException, IOException {
|
||||
DataNodeMemoryManager dataNodeMemoryManager = new DataNodeMemoryManager(memoryManager,
|
||||
Thread.currentThread().getId());
|
||||
/**
|
||||
* 1.schema ,模拟一个field字段值
|
||||
*
|
||||
*/
|
||||
int fieldCount = 3;
|
||||
ColMeta colMeta = null;
|
||||
Map<String, ColMeta> colMetaMap = new HashMap<String, ColMeta>(fieldCount);
|
||||
colMeta = new ColMeta(0, ColMeta.COL_TYPE_STRING);
|
||||
colMetaMap.put("id", colMeta);
|
||||
colMeta = new ColMeta(1, ColMeta.COL_TYPE_STRING);
|
||||
colMetaMap.put("name", colMeta);
|
||||
colMeta = new ColMeta(2, ColMeta.COL_TYPE_STRING);
|
||||
colMetaMap.put("age", colMeta);
|
||||
|
||||
|
||||
OrderCol[] orderCols = new OrderCol[1];
|
||||
OrderCol orderCol = new OrderCol(colMetaMap.get("id"),
|
||||
OrderCol.COL_ORDER_TYPE_ASC);
|
||||
orderCols[0] = orderCol;
|
||||
/**
|
||||
* 2 .PrefixComputer
|
||||
*/
|
||||
StructType schema = new StructType(colMetaMap, fieldCount);
|
||||
schema.setOrderCols(orderCols);
|
||||
|
||||
UnsafeExternalRowSorter.PrefixComputer prefixComputer =
|
||||
new RowPrefixComputer(schema);
|
||||
|
||||
/**
|
||||
* 3 .PrefixComparator 默认是ASC,可以选择DESC
|
||||
*/
|
||||
final PrefixComparator prefixComparator = PrefixComparators.LONG;
|
||||
|
||||
UnsafeExternalRowSorter sorter =
|
||||
new UnsafeExternalRowSorter(dataNodeMemoryManager,
|
||||
myCatMemory,
|
||||
schema,
|
||||
prefixComparator,
|
||||
prefixComputer,
|
||||
conf.getSizeAsBytes("mycat.buffer.pageSize","1m"),
|
||||
true, /**使用基数排序?true or false*/
|
||||
true);
|
||||
UnsafeRow unsafeRow;
|
||||
BufferHolder bufferHolder;
|
||||
UnsafeRowWriter unsafeRowWriter;
|
||||
String line = "testUnsafeRow";
|
||||
final Random rand = new Random(42);
|
||||
for (int i = 0; i < TEST_SIZE; i++) {
|
||||
unsafeRow = new UnsafeRow(3);
|
||||
bufferHolder = new BufferHolder(unsafeRow);
|
||||
unsafeRowWriter = new UnsafeRowWriter(bufferHolder,3);
|
||||
bufferHolder.reset();
|
||||
|
||||
String key = getRandomString(rand.nextInt(300)+100);
|
||||
|
||||
unsafeRowWriter.write(0,key.getBytes());
|
||||
unsafeRowWriter.write(1, line.getBytes());
|
||||
unsafeRowWriter.write(2, ("35" + 1).getBytes());
|
||||
|
||||
unsafeRow.setTotalSize(bufferHolder.totalSize());
|
||||
sorter.insertRow(unsafeRow);
|
||||
}
|
||||
Iterator<UnsafeRow> iter = sorter.sort();
|
||||
UnsafeRow row = null;
|
||||
int indexprint = 0;
|
||||
while (iter.hasNext()) {
|
||||
row = iter.next();
|
||||
indexprint++;
|
||||
}
|
||||
|
||||
sorter.cleanupResources();
|
||||
countDownLatch.countDown();
|
||||
|
||||
System.out.println("Thread ID :" + Thread.currentThread().getId() + "Index : " + indexprint);
|
||||
}
|
||||
|
||||
|
||||
public static String getRandomString(int length) { //length表示生成字符串的长度
|
||||
String base = "abcdefghijklmnopqrstuvwxyz0123456789";
|
||||
Random random = new Random();
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (int i = 0; i < length; i++) {
|
||||
int number = random.nextInt(base.length());
|
||||
sb.append(base.charAt(number));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
final MyCatMemory myCatMemory ;
|
||||
final MemoryManager memoryManager;
|
||||
final MycatPropertyConf conf;
|
||||
|
||||
|
||||
public TestSorter( MyCatMemory myCatMemory, MemoryManager memoryManager,MycatPropertyConf conf) throws NoSuchFieldException, IllegalAccessException {
|
||||
this.myCatMemory = myCatMemory;
|
||||
this.memoryManager = memoryManager;
|
||||
this.conf = conf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
runSorter(myCatMemory,memoryManager,conf);
|
||||
} catch (NoSuchFieldException e) {
|
||||
logger.error(e.getMessage());
|
||||
} catch (IllegalAccessException e) {
|
||||
logger.error(e.getMessage());
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
MyCatMemory myCatMemory ;
|
||||
MemoryManager memoryManager;
|
||||
MycatPropertyConf conf;
|
||||
|
||||
myCatMemory = new MyCatMemory();
|
||||
memoryManager = myCatMemory.getResultMergeMemoryManager();
|
||||
conf = myCatMemory.getConf();
|
||||
|
||||
for (int i = 0; i < TASK_SIZE; i++) {
|
||||
Thread thread = new Thread(new TestSorter(myCatMemory,memoryManager,conf));
|
||||
thread.start();
|
||||
}
|
||||
|
||||
while (countDownLatch.getCount() != 0){
|
||||
System.err.println("count ========================>" + countDownLatch.getCount());
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
|
||||
System.err.println(TASK_SIZE + " tasks sorter finished ok !!!!!!!!!");
|
||||
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user