strongduanmu commented on a change in pull request #13444: URL: https://github.com/apache/shardingsphere/pull/13444#discussion_r742451951
########## File path: shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/dal/MySQLShowRelaylogEventsStatement.java ########## @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import org.apache.shardingsphere.sql.parser.sql.common.statement.AbstractSQLStatement; +import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.DALStatement; +import org.apache.shardingsphere.sql.parser.sql.common.value.literal.impl.NumberLiteralValue; +import org.apache.shardingsphere.sql.parser.sql.common.value.literal.impl.StringLiteralValue; +import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.MySQLStatement; +import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.segment.ChannelNameSegment; + +import java.util.List; + +/** + * MySQL show relay log events statement. + */ +@ToString +@Getter +@Setter +public final class MySQLShowRelaylogEventsStatement extends AbstractSQLStatement implements DALStatement, MySQLStatement { + + private StringLiteralValue logName; + + private NumberLiteralValue from; + + private List<NumberLiteralValue> limit; + + private ChannelNameSegment channel; Review comment: @flycash Can we use String type to replace StringLiteralValue and ChannelNameSegment? They seem to be a string. ########## File path: shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/dal/ShowRelaylogEventsStatementTestCase.java ########## @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.dal; + +import lombok.Getter; +import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.impl.channel.ExpectedChannelNameSegment; +import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.SQLParserTestCase; + +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import java.util.List; + +/** + * show relay log events statement test case. Review comment: @flycash The first letter of javadoc needs to be capitalized. ########## File path: shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLDALStatementSQLVisitor.java ########## @@ -452,6 +459,44 @@ public ASTNode visitShowCreateTrigger(final ShowCreateTriggerContext ctx) { result.setName(((IdentifierValue) visit(ctx.triggerName())).getValue()); return result; } + + @Override + public ASTNode visitShowRelaylogEvent(final MySQLStatementParser.ShowRelaylogEventContext ctx) { + MySQLShowRelaylogEventsStatement result = new MySQLShowRelaylogEventsStatement(); + ChannelNameSegment channel = (ChannelNameSegment) visit(ctx.channelName()); + result.setChannel(channel); + Optional.ofNullable(ctx.logName()) + .map(this::visit) + .map(node -> (StringLiteralValue) node) + .ifPresent(result::setLogName); + List<TerminalNode> numbers = ctx.NUMBER_(); + Optional.ofNullable(ctx.FROM()) + .ifPresent(node -> result.setFrom(new NumberLiteralValue(numbers.remove(0).getText()))); + Optional.ofNullable(ctx.LIMIT()) + .ifPresent(node -> result.setLimit(numbers.stream() + .map(ParseTree::getText) + .map(NumberLiteralValue::new) + .collect(Collectors.toList()))); + return result; + } + + @Override + public ASTNode visitLogName(final MySQLStatementParser.LogNameContext ctx) { + return visit(ctx.stringLiterals()); + } + + @Override + public ASTNode visitChannelName(final MySQLStatementParser.ChannelNameContext ctx) { + ChannelNameSegment result = new ChannelNameSegment(); + result.setStartIndex(ctx.start.getStartIndex()); + result.setStopIndex(ctx.stop.getStopIndex()); + result.setIdentifiers(ctx.identifier().stream() Review comment: @flycash Please use the new visit method to encapsulate these logic. ########## File path: shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/segment/ChannelNameSegment.java ########## @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.segment; + +import lombok.Getter; +import lombok.Setter; +import org.apache.shardingsphere.sql.parser.sql.common.segment.SQLSegment; +import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue; + +import java.util.List; + +@Getter +@Setter +public class ChannelNameSegment implements SQLSegment { Review comment: @flycash Please add javadoc for ChannelNameSegment if we need this segment. ########## File path: shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/dal/MySQLShowRelaylogEventsStatement.java ########## @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import org.apache.shardingsphere.sql.parser.sql.common.statement.AbstractSQLStatement; +import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.DALStatement; +import org.apache.shardingsphere.sql.parser.sql.common.value.literal.impl.NumberLiteralValue; +import org.apache.shardingsphere.sql.parser.sql.common.value.literal.impl.StringLiteralValue; +import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.MySQLStatement; +import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.segment.ChannelNameSegment; + +import java.util.List; + +/** + * MySQL show relay log events statement. + */ +@ToString +@Getter +@Setter +public final class MySQLShowRelaylogEventsStatement extends AbstractSQLStatement implements DALStatement, MySQLStatement { + + private StringLiteralValue logName; + + private NumberLiteralValue from; + + private List<NumberLiteralValue> limit; Review comment: @flycash Does the limit here have the same meaning as the limit of the paging query? If yes, please use LimitSegement. ########## File path: shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLDALStatementSQLVisitor.java ########## @@ -452,6 +459,44 @@ public ASTNode visitShowCreateTrigger(final ShowCreateTriggerContext ctx) { result.setName(((IdentifierValue) visit(ctx.triggerName())).getValue()); return result; } + + @Override + public ASTNode visitShowRelaylogEvent(final MySQLStatementParser.ShowRelaylogEventContext ctx) { + MySQLShowRelaylogEventsStatement result = new MySQLShowRelaylogEventsStatement(); + ChannelNameSegment channel = (ChannelNameSegment) visit(ctx.channelName()); + result.setChannel(channel); + Optional.ofNullable(ctx.logName()) + .map(this::visit) + .map(node -> (StringLiteralValue) node) + .ifPresent(result::setLogName); + List<TerminalNode> numbers = ctx.NUMBER_(); + Optional.ofNullable(ctx.FROM()) + .ifPresent(node -> result.setFrom(new NumberLiteralValue(numbers.remove(0).getText()))); + Optional.ofNullable(ctx.LIMIT()) + .ifPresent(node -> result.setLimit(numbers.stream() + .map(ParseTree::getText) + .map(NumberLiteralValue::new) + .collect(Collectors.toList()))); + return result; + } + + @Override + public ASTNode visitLogName(final MySQLStatementParser.LogNameContext ctx) { Review comment: @flycash Please use static import instead. ########## File path: shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLDALStatementSQLVisitor.java ########## @@ -452,6 +459,44 @@ public ASTNode visitShowCreateTrigger(final ShowCreateTriggerContext ctx) { result.setName(((IdentifierValue) visit(ctx.triggerName())).getValue()); return result; } + + @Override + public ASTNode visitShowRelaylogEvent(final MySQLStatementParser.ShowRelaylogEventContext ctx) { + MySQLShowRelaylogEventsStatement result = new MySQLShowRelaylogEventsStatement(); + ChannelNameSegment channel = (ChannelNameSegment) visit(ctx.channelName()); + result.setChannel(channel); + Optional.ofNullable(ctx.logName()) Review comment: @flycash Can you use the new visit method to encapsulate this logic? The use of lambda expressions here does not seem very clear. ########## File path: shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/dal/impl/ShowRelaylogEventsStatementAssert.java ########## @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.dal.impl; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; +import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue; +import org.apache.shardingsphere.sql.parser.sql.common.value.literal.impl.NumberLiteralValue; +import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowRelaylogEventsStatement; +import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.segment.ChannelNameSegment; +import org.apache.shardingsphere.test.sql.parser.parameterized.asserts.SQLCaseAssertContext; +import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.impl.channel.ExpectedChannelNameSegment; +import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.dal.ShowRelaylogEventsStatementTestCase; + +import java.util.List; +import java.util.Optional; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +/** + * show relay log events statement assert. Review comment: @flycash Please use static import instead. ########## File path: shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/segment/impl/channel/ExpectedChannelNameSegment.java ########## @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.impl.channel; + +import lombok.Getter; +import lombok.Setter; +import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.AbstractExpectedSQLSegment; + +import javax.xml.bind.annotation.XmlElement; +import java.util.List; + +@Setter +@Getter +public class ExpectedChannelNameSegment extends AbstractExpectedSQLSegment { Review comment: @flycash Please add final for ExpectedChannelNameSegment and add a blank line after this line. ########## File path: shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/dal/MySQLShowRelaylogEventsStatement.java ########## @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import org.apache.shardingsphere.sql.parser.sql.common.statement.AbstractSQLStatement; +import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.DALStatement; +import org.apache.shardingsphere.sql.parser.sql.common.value.literal.impl.NumberLiteralValue; +import org.apache.shardingsphere.sql.parser.sql.common.value.literal.impl.StringLiteralValue; +import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.MySQLStatement; +import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.segment.ChannelNameSegment; + +import java.util.List; + +/** + * MySQL show relay log events statement. + */ +@ToString +@Getter +@Setter +public final class MySQLShowRelaylogEventsStatement extends AbstractSQLStatement implements DALStatement, MySQLStatement { + + private StringLiteralValue logName; + + private NumberLiteralValue from; Review comment: What is the meaning of from? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
