Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/v1.21-2022-2-9' into v1.21-2022-2-9
Browse files Browse the repository at this point in the history
  • Loading branch information
junwen12221 committed Mar 1, 2022
2 parents 47d2574 + 915a962 commit d1f285e
Show file tree
Hide file tree
Showing 25 changed files with 115 additions and 102 deletions.
10 changes: 5 additions & 5 deletions common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,29 +51,29 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>27.1-jre</version>
<version>31.0.1-jre</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.22</version>
<version>8.0.25</version>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
<version>4.2.3</version>
<version>4.2.5</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-sql-client</artifactId>
<version>4.2.3</version>
<version>4.2.5</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-mysql-client</artifactId>
<version>4.2.3</version>
<version>4.2.5</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down
19 changes: 7 additions & 12 deletions common/src/main/java/io/mycat/PreparedStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,19 @@
import com.alibaba.druid.sql.ast.SQLReplaceable;
import com.alibaba.druid.sql.ast.SQLStatement;
import com.alibaba.druid.sql.ast.expr.*;
import com.alibaba.druid.sql.ast.statement.SQLDeleteStatement;
import com.alibaba.druid.sql.ast.statement.SQLInsertStatement;
import com.alibaba.druid.sql.ast.statement.SQLSelectStatement;
import com.alibaba.druid.sql.ast.statement.SQLUpdateStatement;
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitorAdapter;
import com.alibaba.druid.sql.parser.ParserException;
import io.mycat.util.HexFormatUtil;
import lombok.SneakyThrows;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import scala.util.control.Exception;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Time;
import java.sql.Timestamp;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -116,7 +107,11 @@ public static SQLExpr fromJavaObject(Object o, TimeZone timeZone) {
String s = HexFormatUtil.bytesToHexString(new byte[]{(Byte)o});
return new SQLHexExpr(s);
}

if (o instanceof CharBuffer) {
CharBuffer charBuffer = (CharBuffer) o;
String s = charBuffer.toString();
return new SQLCharExpr(s);
}
LOGGER.warn("not support class : {}", o.getClass());


Expand Down
2 changes: 1 addition & 1 deletion config/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.62</version>
<version>1.2.79</version>
</dependency>
<!-- https://mvnrepository.com/artifact/uk.com.robust-it/cloning -->
<dependency>
Expand Down
1 change: 1 addition & 0 deletions config/src/main/java/io/mycat/config/ServerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public class ServerConfig {
private long bkaJoinLeftRowCountLimit = 1000;
private boolean pstmtStringVal = false;
private String pushDownSelectDual = "hackRouter";
private boolean useProxyProtocol = false;
public static void main(String[] args) {
System.out.println(JsonUtil.toJson(new ServerConfig()));
}
Expand Down
1 change: 1 addition & 0 deletions config/src/main/java/io/mycat/config/UserConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class UserConfig implements KVObject {
private String ip = null;
private String transactionType = "proxy";
private String dialect = "mysql";
private String schema;

public static void main(String[] args) {
String s = JsonUtil.toJson(new UserConfig());
Expand Down
4 changes: 2 additions & 2 deletions example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-mysql-client</artifactId>
<version>4.2.3</version>
<version>4.2.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.alibaba/druid -->
<dependency>
Expand Down Expand Up @@ -125,7 +125,7 @@
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-junit5</artifactId>
<version>4.2.3</version>
<version>4.2.5</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion example/src/test/java/io/mycat/assemble/SpmHintTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void testParameterize() throws Exception {
) {
List<Map<String, Object>> maps = executeQuery(mycatConnection, BaselineParameterizeHint.create("select 1"));
Assert.assertEquals(1, maps.size());
Assert.assertEquals("{PARAMETERIZED_SQL=select ?, INFO=DrdsSqlWithParams{params=[1], aliasList=[1], timeout=null, partitions=[]}}",maps.get(0).toString());
Assert.assertEquals("{PARAMETERIZED_SQL=select ?, INFO=DrdsSqlWithParams{parameterizedSQL=select ?, params=[1], aliasList=[1], timeout=null, partitions=[]}}",maps.get(0).toString());
}
}
@Test
Expand Down
4 changes: 2 additions & 2 deletions example/src/test/java/io/mycat/sql/UserCaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1273,8 +1273,8 @@ public void case21() throws Exception {
Assert.assertEquals("[{1=1}]", res3.toString());
Assert.assertEquals("[{1=1}]", res4.toString());
Assert.assertEquals("[{1=1}]", res5.toString());
Assert.assertEquals("[{'{{'={{}]", res6.toString());
Assert.assertEquals("[{'1'=1}]", res7.toString());
Assert.assertEquals("[{{{={{}]", res6.toString());
Assert.assertEquals("[{1=1}]", res7.toString());
Assert.assertEquals("[{1=1}]", res8.toString());
System.out.println();
}
Expand Down
2 changes: 1 addition & 1 deletion hbt/src/main/java/io/mycat/calcite/DrdsRunnerHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static DrdsSqlWithParams preParse(SQLStatement sqlStatement, String defau
} else {
StringBuilder sbText = new StringBuilder();
selectItem.output(sbText);
columnNodes.add(sbText.toString().replaceAll(" ", ""));
columnNodes.add(SQLUtils.normalize(sbText.toString().replaceAll(" ", "")));
}
} else {
columnNodes.add(SQLUtils.normalize(selectItem.getAlias()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public boolean visit(SQLSelectQueryBlock x) {
} else {
StringBuilder sb = new StringBuilder();
selectItem.output(sb);
selectItem.setAlias(sb.toString().replaceAll(" ", ""));
selectItem.setAlias(SQLUtils.normalize(sb.toString().replaceAll(" ", "")));
}
}
SqlNode column = convertToSqlNode(selectItem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class MycatValueFactory {
public static final LongValueFactory LONG_VALUE_FACTORY = new LongValueFactory(DEFAULT_PROPERTY_SET);
public static final ShortValueFactory SHORT_VALUE_FACTORY = new ShortValueFactory(DEFAULT_PROPERTY_SET);
public static final SqlDateValueFactory SQL_DATE_VALUE_FACTORY = new SqlDateValueFactory(DEFAULT_PROPERTY_SET,null, TimeZone.getDefault());
public static final SqlTimestampValueFactory SQL_TIMESTAMP_VALUE_FACTORY = new SqlTimestampValueFactory(DEFAULT_PROPERTY_SET,null,TimeZone.getDefault());
//public static final SqlTimestampValueFactory SQL_TIMESTAMP_VALUE_FACTORY = new SqlTimestampValueFactory(DEFAULT_PROPERTY_SET,null,TimeZone.getDefault());
public static final SqlTimeValueFactory SQL_TIME_VALUE_FACTORY = new SqlTimeValueFactory(DEFAULT_PROPERTY_SET,null,TimeZone.getDefault());
public static final StringValueFactory STRING_VALUE_FACTORY = new StringValueFactory(DEFAULT_PROPERTY_SET);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public void split() {
case BIT_XOR:
case BIT_AND:
case SUM0:
case ANY_VALUE:
splitCommon(aggregateCall);
break;
default:
Expand Down
51 changes: 30 additions & 21 deletions hbt/src/main/java/io/mycat/calcite/rewriter/SQLRBORewriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@ public static boolean userDefinedFunctionInFilter(Filter filter) {
Information_Functions.put("LAG", null);
Information_Functions.put("LEAD", null);
Information_Functions.put("NTH_VALUE", null);

//LOCK
Information_Functions.put("GET_LOCK", null);
Information_Functions.put("RELEASE_LOCK", null);
Information_Functions.put("IS_FREE_LOCK", null);
}

@Override
Expand Down Expand Up @@ -610,27 +615,31 @@ public static Optional<RelNode> aggregate(RelNode original, Aggregate aggregate)
}

private static Optional<RelNode> splitAggregate(MycatView viewNode, Aggregate aggregate) {

AggregatePushContext aggregateContext = AggregatePushContext.split(aggregate);

MycatView newView = viewNode.changeTo(
LogicalAggregate.create(viewNode.getRelNode(),
aggregate.getHints(),
aggregate.getGroupSet(),
aggregate.getGroupSets(),
aggregateContext.getPartialAggregateCallList()));

LogicalAggregate globalAggregateRelNode = LogicalAggregate.create(newView, aggregate.getHints(),
aggregate.getGroupSet(),
aggregate.getGroupSets(),
aggregateContext.getGlobalAggregateCallList());

MycatProject projectRelNode = MycatProject.create(globalAggregateRelNode,
aggregateContext.getProjectExprList(),
aggregate.getRowType());

return RexUtil.isIdentity(projectRelNode.getProjects(), projectRelNode.getInput().getRowType()) ?
Optional.of(globalAggregateRelNode) : Optional.of(projectRelNode);
try {
AggregatePushContext aggregateContext = AggregatePushContext.split(aggregate);

MycatView newView = viewNode.changeTo(
LogicalAggregate.create(viewNode.getRelNode(),
aggregate.getHints(),
aggregate.getGroupSet(),
aggregate.getGroupSets(),
aggregateContext.getPartialAggregateCallList()));

LogicalAggregate globalAggregateRelNode = LogicalAggregate.create(newView, aggregate.getHints(),
aggregate.getGroupSet(),
aggregate.getGroupSets(),
aggregateContext.getGlobalAggregateCallList());

MycatProject projectRelNode = MycatProject.create(globalAggregateRelNode,
aggregateContext.getProjectExprList(),
aggregate.getRowType());

return RexUtil.isIdentity(projectRelNode.getProjects(), projectRelNode.getInput().getRowType()) ?
Optional.of(globalAggregateRelNode) : Optional.of(projectRelNode);
}catch (Throwable throwable){
LOGGER.debug("",throwable);
}
return Optional.empty();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ public boolean visit(SQLMethodInvokeExpr x) {

@Override
public boolean visit(SQLVariantRefExpr x) {
if(!"?".equals(x.getName())){
if (!"?".equals(x.getName())) {
hasVar.set(true);
}
return super.visit(x);
}
});
this.metadataManager = MetaClusterCurrent.wrapper(MetadataManager.class);
if (PUSH_DOWN_SELECT_DUAL&&tableNames.isEmpty() && !hasVar.get()) {
if (methods.stream().noneMatch(name -> SQLRBORewriter.Information_Functions.containsKey(SQLUtils.normalize(name), false))) {
if (PUSH_DOWN_SELECT_DUAL && tableNames.isEmpty() && !hasVar.get()) {
if (!methods.isEmpty() && methods.stream().noneMatch(name -> SQLRBORewriter.Information_Functions.containsKey(SQLUtils.normalize(name), false))) {
targetMap = NameMap.immutableCopyOf(Collections.emptyMap());
targetName = MetadataManager.getPrototype();
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2140,10 +2140,11 @@ public Optional<String> getCreateTableSQLByJDBC(String schemaName, String tableN
return Optional.of(createTableSql);
}
}
return Optional.empty();
continue;
} catch (Exception e) {
LOGGER.error("", e);
}
continue;
} catch (Throwable e) {
LOGGER.error("can not get create table sql from:" + backend.getTargetName() + backend.getTargetSchemaTable(), e);
continue;
Expand Down
11 changes: 2 additions & 9 deletions mycat2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,6 @@
<artifactId>guava</artifactId>
<version>28.1-jre</version>
</dependency>
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
<!-- <dependency>-->
<!-- <groupId>log4j</groupId>-->
<!-- <artifactId>log4j</artifactId>-->
<!-- <version>1.2.17</version>-->
<!-- </dependency>-->
<!-- https://mvnrepository.com/artifact/log4j/apache-log4j-extras -->
<dependency>
<groupId>io.mycat</groupId>
<artifactId>hbt</artifactId>
Expand Down Expand Up @@ -212,7 +205,7 @@
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
<version>4.2.3</version>
<version>4.2.5</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
Expand All @@ -237,7 +230,7 @@
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<version>2.0.1</version>
<version>2.7.2</version>
</dependency>

</dependencies>
Expand Down
8 changes: 8 additions & 0 deletions mycat2/src/main/java/io/mycat/commands/MycatdbCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,14 @@ public Future<Void> executeQuery(String text,
Response response = responseFactory.apply(1);
return handleBaseline(text, dataContext, response);
}
if (text.startsWith("IN ")) {
//IN
Response response = responseFactory.apply(1);
String schema = text.split(" ")[1];
String normalize = SQLUtils.normalize(schema);
dataContext.useShcema(normalize);
return response.sendOk();
}
LinkedList<SQLStatement> statements = parse(text);
if (statements.isEmpty()) {
throw new MycatException("Illegal syntax:" + text);
Expand Down
29 changes: 13 additions & 16 deletions mycat2/src/main/java/io/mycat/exporter/MySQLLogConsumer.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
public class MySQLLogConsumer implements Consumer<SqlEntry> {
private static final Logger LOGGER = LoggerFactory.getLogger(MySQLLogConsumer.class);
boolean init = false;
boolean initFail = false;

@SneakyThrows
public MySQLLogConsumer() {

Expand All @@ -33,7 +33,7 @@ private void init() throws SQLException {
MetadataManager metadataManager = MetaClusterCurrent.wrapper(MetadataManager.class);
try (DefaultConnection connection = jdbcConnectionManager.getConnection(metadataManager.getPrototype())) {
JdbcUtils.execute(connection.getRawConnection(),
" create table if not exists mycat.`sql_log` (\n" +
"CREATE TABLE IF NOT EXISTS mycat.`sql_log` (\n" +
" `instanceId` bigint(20) DEFAULT NULL,\n" +
" `user` varchar(64) DEFAULT NULL,\n" +
" `connectionId` bigint(20) DEFAULT NULL,\n" +
Expand All @@ -44,35 +44,31 @@ private void init() throws SQLException {
" `sqlType` varchar(22) DEFAULT NULL,\n" +
" `sql` longtext,\n" +
" `transactionId` varchar(22) DEFAULT NULL,\n" +
" `sqlTime` time DEFAULT NULL,\n" +
" `sqlTime` bigint(20) DEFAULT NULL,\n" +
" `responseTime` datetime DEFAULT NULL,\n" +
" `affectRow` int(11) DEFAULT NULL,\n" +
" `result` tinyint(1) DEFAULT NULL,\n" +
" `externalMessage` tinytext,\n" +
" PRIMARY KEY (`traceId`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", Collections.emptyList());
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci", Collections.emptyList());
}
}

@Override
@SneakyThrows
public void accept(SqlEntry sqlEntry) {
if (!init){
if (!init) {
init = true;
try {
init();
}catch (Exception e){
LOGGER.error("",e);
initFail = true;
} catch (Exception e) {
LOGGER.error("", e);
}
}
if (initFail){
return;
}
boolean isInRuntime = MetaClusterCurrent.exist(IOExecutor.class)
&&MetaClusterCurrent.exist(JdbcConnectionManager.class)
&&MetaClusterCurrent.exist(IOExecutor.class);
if (isInRuntime){
&& MetaClusterCurrent.exist(JdbcConnectionManager.class)
&& MetaClusterCurrent.exist(IOExecutor.class);
if (isInRuntime) {
IOExecutor ioExecutor = MetaClusterCurrent.wrapper(IOExecutor.class);
JdbcConnectionManager jdbcConnectionManager = MetaClusterCurrent.wrapper(JdbcConnectionManager.class);
MetadataManager metadataManager = MetaClusterCurrent.wrapper(MetadataManager.class);
Expand Down Expand Up @@ -116,8 +112,9 @@ public void accept(SqlEntry sqlEntry) {
));
}
} catch (Exception e) {
LOGGER.warn("", e);
}finally {
LOGGER.info(" warning sql:{} , info:{}", sqlEntry.getSql(), sqlEntry);
LOGGER.error("", e);
} finally {
event.tryComplete();
}
});
Expand Down
Loading

0 comments on commit d1f285e

Please sign in to comment.