Skip to content

Commit 90ca0d0

Browse files
authored
Merge pull request #30 from sharding-sphere/dev
update from origin
2 parents 3843a50 + dce9698 commit 90ca0d0

File tree

10 files changed

+80
-60
lines changed

10 files changed

+80
-60
lines changed

sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/TableReferencesClauseParser.java

+16-4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import io.shardingsphere.core.parsing.parser.clause.expression.BasicExpressionParser;
3030
import io.shardingsphere.core.parsing.parser.context.table.Table;
3131
import io.shardingsphere.core.parsing.parser.dialect.ExpressionParserFactory;
32+
import io.shardingsphere.core.parsing.parser.exception.SQLParsingUnsupportedException;
3233
import io.shardingsphere.core.parsing.parser.sql.SQLStatement;
3334
import io.shardingsphere.core.parsing.parser.token.IndexToken;
3435
import io.shardingsphere.core.parsing.parser.token.TableToken;
@@ -75,7 +76,13 @@ public final void parse(final SQLStatement sqlStatement, final boolean isSingleT
7576
parseTableReference(sqlStatement, isSingleTableOnly);
7677
} while (lexerEngine.skipIfEqual(Symbol.COMMA));
7778
}
78-
79+
80+
/**
81+
* Parse table references.
82+
*
83+
* @param sqlStatement SQL statement
84+
* @param isSingleTableOnly is parse single table only
85+
*/
7986
protected void parseTableReference(final SQLStatement sqlStatement, final boolean isSingleTableOnly) {
8087
parseTableFactor(sqlStatement, isSingleTableOnly);
8188
}
@@ -103,7 +110,7 @@ protected final void parseTableFactor(final SQLStatement sqlStatement, final boo
103110
parseForceIndex(tableName, sqlStatement);
104111
parseJoinTable(sqlStatement);
105112
if (isSingleTableOnly && !sqlStatement.getTables().isSingleTable()) {
106-
throw new UnsupportedOperationException("Cannot support Multiple-Table.");
113+
throw new SQLParsingUnsupportedException("Cannot support Multiple-Table.");
107114
}
108115
}
109116

@@ -128,7 +135,7 @@ private void parseForceIndex(final String tableName, final SQLStatement sqlState
128135
private void parseJoinTable(final SQLStatement sqlStatement) {
129136
while (parseJoinType()) {
130137
if (lexerEngine.equalAny(Symbol.LEFT_PAREN)) {
131-
throw new UnsupportedOperationException("Cannot support sub query for join table.");
138+
throw new SQLParsingUnsupportedException("Cannot support sub query for join table.");
132139
}
133140
parseTableFactor(sqlStatement, false);
134141
parseJoinCondition(sqlStatement);
@@ -147,7 +154,12 @@ private boolean parseJoinType() {
147154
lexerEngine.skipAll(joinTypeKeywordArrays);
148155
return true;
149156
}
150-
157+
158+
/**
159+
* Get keywords for join type.
160+
*
161+
* @return new Keyword object array
162+
*/
151163
protected Keyword[] getKeywordsForJoinType() {
152164
return new Keyword[0];
153165
}

sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/exception/SQLParsingUnsupportedException.java

+4
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,8 @@ public final class SQLParsingUnsupportedException extends ShardingException {
3434
public SQLParsingUnsupportedException(final TokenType tokenType) {
3535
super(String.format(MESSAGE, tokenType.toString()));
3636
}
37+
38+
public SQLParsingUnsupportedException(final String message) {
39+
super(message);
40+
}
3741
}

sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/mysql/MySQLFrontendHandler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public void run() {
135135
}
136136
}
137137

138-
private CommandPacket getCommandPacket(final MySQLPacketPayload payload, final BackendConnection backendConnection, final FrontendHandler frontendHandler) {
138+
private CommandPacket getCommandPacket(final MySQLPacketPayload payload, final BackendConnection backendConnection, final FrontendHandler frontendHandler) throws SQLException {
139139
int sequenceId = payload.readInt1();
140140
int connectionId = ChannelRegistry.getInstance().getConnectionId(context.channel().id().asShortText());
141141
return CommandPacketFactory.newInstance(sequenceId, connectionId, payload, backendConnection, frontendHandler);

sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/packet/command/CommandPacketFactory.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import lombok.AccessLevel;
3333
import lombok.NoArgsConstructor;
3434

35+
import java.sql.SQLException;
36+
3537
/**
3638
* Command packet factory.
3739
*
@@ -50,9 +52,10 @@ public final class CommandPacketFactory {
5052
* @param backendConnection backend connection
5153
* @param frontendHandler frontend handler
5254
* @return command packet
55+
* @throws SQLException SQL exception
5356
*/
5457
public static CommandPacket newInstance(final int sequenceId, final int connectionId, final MySQLPacketPayload payload,
55-
final BackendConnection backendConnection, final FrontendHandler frontendHandler) {
58+
final BackendConnection backendConnection, final FrontendHandler frontendHandler) throws SQLException {
5659
int commandPacketTypeValue = payload.readInt1();
5760
CommandPacketType type = CommandPacketType.valueOf(commandPacketTypeValue);
5861
switch (type) {

sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/packet/command/query/binary/execute/ComStmtExecutePacket.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public final class ComStmtExecutePacket implements QueryCommandPacket {
7777

7878
private final BackendHandler backendHandler;
7979

80-
public ComStmtExecutePacket(final int sequenceId, final int connectionId, final MySQLPacketPayload payload, final BackendConnection backendConnection, final FrontendHandler frontendHandler) {
80+
public ComStmtExecutePacket(final int sequenceId, final int connectionId, final MySQLPacketPayload payload, final BackendConnection backendConnection, final FrontendHandler frontendHandler) throws SQLException {
8181
this.sequenceId = sequenceId;
8282
statementId = payload.readInt4();
8383
binaryStatement = BinaryStatementRegistry.getInstance().getBinaryStatement(statementId);
@@ -107,7 +107,7 @@ private List<BinaryStatementParameterType> getParameterTypes(final MySQLPacketPa
107107
return result;
108108
}
109109

110-
private List<Object> getParameters(final MySQLPacketPayload payload, final int parametersCount) {
110+
private List<Object> getParameters(final MySQLPacketPayload payload, final int parametersCount) throws SQLException {
111111
List<Object> result = new ArrayList<>(parametersCount);
112112
for (int parameterIndex = 0; parameterIndex < parametersCount; parameterIndex++) {
113113
BinaryProtocolValue binaryProtocolValue = BinaryProtocolValueFactory.getBinaryProtocolValue(binaryStatement.getParameterTypes().get(parameterIndex).getColumnType());

sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/packet/command/query/binary/execute/protocol/BinaryProtocolValue.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
import io.shardingsphere.proxy.transport.mysql.packet.MySQLPacketPayload;
2121

22+
import java.sql.SQLException;
23+
2224
/**
2325
* Binary protocol value.
2426
*
@@ -34,8 +36,9 @@ public interface BinaryProtocolValue {
3436
*
3537
* @param payload payload operation for MySQL packet
3638
* @return binary value result
39+
* @throws SQLException SQL exception
3740
*/
38-
Object read(MySQLPacketPayload payload);
41+
Object read(MySQLPacketPayload payload) throws SQLException;
3942

4043
/**
4144
* Write binary protocol value.

sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/packet/command/query/binary/execute/protocol/DateBinaryProtocolValue.java

+5-10
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
import io.shardingsphere.proxy.transport.mysql.packet.MySQLPacketPayload;
2121

22+
import java.sql.SQLException;
23+
import java.sql.SQLFeatureNotSupportedException;
2224
import java.sql.Timestamp;
2325
import java.util.Calendar;
2426

@@ -31,11 +33,11 @@
3133
public final class DateBinaryProtocolValue implements BinaryProtocolValue {
3234

3335
@Override
34-
public Object read(final MySQLPacketPayload payload) {
36+
public Object read(final MySQLPacketPayload payload) throws SQLException {
3537
int length = payload.readInt1();
3638
switch (length) {
3739
case 0:
38-
return new Timestamp(0L);
40+
throw new SQLFeatureNotSupportedException("Can not support date format if year, month, day is absent.");
3941
case 4:
4042
return getTimestampForDate(payload);
4143
case 7:
@@ -63,25 +65,18 @@ private Timestamp getTimestampForDatetime(final MySQLPacketPayload payload) {
6365

6466
@Override
6567
public void write(final MySQLPacketPayload payload, final Object value) {
66-
// TODO :yonglun confirm here is cannot set YEAR == 0, it at least 1970 here
6768
Timestamp timestamp = (Timestamp) value;
6869
Calendar calendar = Calendar.getInstance();
69-
calendar.setTimeInMillis(timestamp.getTime());
70+
calendar.setTime(timestamp);
7071
int year = calendar.get(Calendar.YEAR);
71-
// TODO :yonglun confirm here is month + 1, and isDateAbsent adjust is 0 == month, is it never == 0?
7272
int month = calendar.get(Calendar.MONTH) + 1;
7373
int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
7474
int hourOfDay = calendar.get(Calendar.HOUR_OF_DAY);
7575
int minutes = calendar.get(Calendar.MINUTE);
7676
int seconds = calendar.get(Calendar.SECOND);
7777
int nanos = timestamp.getNanos();
78-
boolean isDateAbsent = 0 == year && 0 == month && 0 == dayOfMonth;
7978
boolean isTimeAbsent = 0 == hourOfDay && 0 == minutes && 0 == seconds;
8079
boolean isNanosAbsent = 0 == nanos;
81-
if (isDateAbsent && isTimeAbsent && isNanosAbsent) {
82-
payload.writeInt1(0);
83-
return;
84-
}
8580
if (isTimeAbsent && isNanosAbsent) {
8681
payload.writeInt1(4);
8782
writeDate(payload, year, month, dayOfMonth);

0 commit comments

Comments
 (0)