Skip to content

Commit

Permalink
Merge 1690f20 into 2e4defe
Browse files Browse the repository at this point in the history
  • Loading branch information
jingshanglu committed Feb 10, 2020
2 parents 2e4defe + 1690f20 commit dbeb596
Show file tree
Hide file tree
Showing 17 changed files with 286 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
-->

<sql-cases>
<sql-case id="set_parameter_equal" value="SET configuration_parameter = 'value'" db-types="PostgreSQL" />
<sql-case id="set_parameter_equal" value="SET configuration_parameter = 'value'" db-types="PostgreSQL, MySQL" />
<sql-case id="set_parameter_to" value="SET configuration_parameter TO 'value'" db-types="PostgreSQL" />
<sql-case id="set_parameter_for_session_scope" value="SET SESSION configuration_parameter TO 'value'" db-types="PostgreSQL" />
<sql-case id="set_parameter_for_local_scope" value="SET LOCAL configuration_parameter TO 'value'" db-types="PostgreSQL" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
<sql-case id="show_index_with_table_back_quotes" value="SHOW INDEXES FROM `t_order` FROM sharding_db" db-types="MySQL" />
<sql-case id="show_index_with_database_back_quotes" value="SHOW INDEXES FROM t_order FROM `sharding_db`" db-types="MySQL" />
<sql-case id="show_index_with_back_quotes" value="SHOW KEYS FROM `sharding_db`.`t_order`" db-types="MySQL" />
<sql-case id="show_columns_from_table" value="SHOW COLUMNS FROM `t_order`" db-types="MySQL" />
<sql-case id="show_create_table" value="SHOW CREATE TABLE `t_order`" db-types="MySQL" />
<sql-case id="show_all" value="SHOW ALL" db-types="PostgreSQL" />
<sql-case id="show_server_version" value="SHOW SERVER_VERSION" db-types="PostgreSQL" />
<sql-case id="show_transaction_isolation_level" value="SHOW TRANSACTION ISOLATION LEVEL" db-types="PostgreSQL" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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.statement.dal.dialect.mysql;

import org.apache.shardingsphere.sql.parser.sql.statement.dal.DALStatement;

public final class SetStatement extends DALStatement {
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ showProfileType
;

setVariable
: SET variable_?
: SET variableExpr+
;

variableExpr
: variable_ EQ_ expr
;

showBinaryLogs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,15 @@ public class FromTableSegment implements SQLSegment, TableAvailable {

private int stopIndex;

private TableSegment pattern;
private TableSegment table;

@Override
public String getTableName() {
return pattern.getTableName();
return table.getTableName();
}

@Override
public QuoteCharacter getTableQuoteCharacter() {
return QuoteCharacter.NONE;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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.segment.dal;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.sql.parser.sql.segment.SQLSegment;

@RequiredArgsConstructor
@Getter
public class VariableExprSegment implements SQLSegment {

private final int startIndex;

private final int stopIndex;

private final String variable;

private final String expr;


}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
package org.apache.shardingsphere.sql.parser.visitor;

import org.apache.shardingsphere.sql.parser.MySQLVisitor;
import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.VariableExprContext;
import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.SetVariableContext;
import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowOtherContext;
import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.DescContext;
import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.FromSchemaContext;
import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.FromTableContext;
Expand All @@ -34,8 +37,10 @@
import org.apache.shardingsphere.sql.parser.sql.segment.dal.FromSchemaSegment;
import org.apache.shardingsphere.sql.parser.sql.segment.dal.FromTableSegment;
import org.apache.shardingsphere.sql.parser.sql.segment.dal.ShowLikeSegment;
import org.apache.shardingsphere.sql.parser.sql.segment.dal.VariableExprSegment;
import org.apache.shardingsphere.sql.parser.sql.segment.generic.SchemaSegment;
import org.apache.shardingsphere.sql.parser.sql.segment.generic.TableSegment;
import org.apache.shardingsphere.sql.parser.sql.statement.dal.dialect.mysql.SetStatement;
import org.apache.shardingsphere.sql.parser.sql.statement.dal.dialect.mysql.DescribeStatement;
import org.apache.shardingsphere.sql.parser.sql.statement.dal.dialect.mysql.ShowColumnsStatement;
import org.apache.shardingsphere.sql.parser.sql.statement.dal.dialect.mysql.ShowCreateTableStatement;
Expand All @@ -44,9 +49,12 @@
import org.apache.shardingsphere.sql.parser.sql.statement.dal.dialect.mysql.ShowTableStatusStatement;
import org.apache.shardingsphere.sql.parser.sql.statement.dal.dialect.mysql.ShowTablesStatement;
import org.apache.shardingsphere.sql.parser.sql.statement.dal.dialect.mysql.UseStatement;
import org.apache.shardingsphere.sql.parser.sql.statement.dal.dialect.mysql.ShowOtherStatement;
import org.apache.shardingsphere.sql.parser.sql.value.identifier.IdentifierValue;
import org.apache.shardingsphere.sql.parser.sql.value.literal.impl.StringLiteralValue;

import java.util.List;

/**
* MySQL DAL visitor.
*
Expand Down Expand Up @@ -119,7 +127,7 @@ public ASTNode visitShowColumns(final ShowColumnsContext ctx) {
FromSchemaContext fromSchemaContext = ctx.fromSchema();
if (null != fromTableContext) {
FromTableSegment fromTableSegment = (FromTableSegment) visit(fromTableContext);
result.setTable(fromTableSegment.getPattern());
result.setTable(fromTableSegment.getTable());
result.getAllSQLSegments().add(fromTableSegment);
}
if (null != fromSchemaContext) {
Expand All @@ -141,7 +149,7 @@ public ASTNode visitShowIndex(final ShowIndexContext ctx) {
}
if (null != fromTableContext) {
FromTableSegment fromTableSegment = (FromTableSegment) visitFromTable(fromTableContext);
TableSegment tableSegment = fromTableSegment.getPattern();
TableSegment tableSegment = fromTableSegment.getTable();
result.setTable(tableSegment);
result.getAllSQLSegments().add(tableSegment);
}
Expand All @@ -160,9 +168,27 @@ public ASTNode visitShowCreateTable(final ShowCreateTableContext ctx) {
public ASTNode visitFromTable(final FromTableContext ctx) {
FromTableSegment fromTableSegment = new FromTableSegment();
TableSegment tableSegment = (TableSegment) visit(ctx.tableName());
fromTableSegment.setPattern(tableSegment);
fromTableSegment.setTable(tableSegment);
return fromTableSegment;
}

@Override
public ASTNode visitShowOther(final ShowOtherContext ctx) {
return new ShowOtherStatement();
}

@Override
public ASTNode visitSetVariable(final SetVariableContext ctx) {
List<VariableExprContext> variableExprs = ctx.variableExpr();
SetStatement result = new SetStatement();
for (VariableExprContext vectx: variableExprs) {
String variable = vectx.variable_().getText();
String expr = vectx.expr().getText();
VariableExprSegment variableExprSegment = new VariableExprSegment(vectx.start.getStartIndex(), vectx.stop.getStopIndex(), variable, expr);
result.getAllSQLSegments().add(variableExprSegment);
}
return result;
}

@Override
public ASTNode visitFromSchema(final FromSchemaContext ctx) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.shardingsphere.sql.parser.integrate.asserts.statement.dal.impl.ShowTableStatusStatementAssert;
import org.apache.shardingsphere.sql.parser.integrate.asserts.statement.dal.impl.ShowTablesStatementAssert;
import org.apache.shardingsphere.sql.parser.integrate.asserts.statement.dal.impl.UseStatementAssert;
import org.apache.shardingsphere.sql.parser.integrate.asserts.statement.dal.impl.SetVariableStatementAssert;
import org.apache.shardingsphere.sql.parser.integrate.jaxb.domain.statement.SQLParserTestCase;
import org.apache.shardingsphere.sql.parser.integrate.jaxb.domain.statement.dal.DescribeStatementTestCase;
import org.apache.shardingsphere.sql.parser.integrate.jaxb.domain.statement.dal.ShowColumnsStatementTestCase;
Expand All @@ -39,6 +40,7 @@
import org.apache.shardingsphere.sql.parser.integrate.jaxb.domain.statement.dal.ShowTableStatusStatementTestCase;
import org.apache.shardingsphere.sql.parser.integrate.jaxb.domain.statement.dal.ShowTablesStatementTestCase;
import org.apache.shardingsphere.sql.parser.integrate.jaxb.domain.statement.dal.UseStatementTestCase;
import org.apache.shardingsphere.sql.parser.integrate.jaxb.domain.statement.dal.SetVariableStatementTestCase;
import org.apache.shardingsphere.sql.parser.sql.statement.dal.DALStatement;
import org.apache.shardingsphere.sql.parser.sql.statement.dal.dialect.mysql.DescribeStatement;
import org.apache.shardingsphere.sql.parser.sql.statement.dal.dialect.mysql.ShowColumnsStatement;
Expand All @@ -48,6 +50,7 @@
import org.apache.shardingsphere.sql.parser.sql.statement.dal.dialect.mysql.ShowTableStatusStatement;
import org.apache.shardingsphere.sql.parser.sql.statement.dal.dialect.mysql.ShowTablesStatement;
import org.apache.shardingsphere.sql.parser.sql.statement.dal.dialect.mysql.UseStatement;
import org.apache.shardingsphere.sql.parser.sql.statement.dal.dialect.mysql.SetStatement;
import org.apache.shardingsphere.sql.parser.sql.statement.dal.dialect.postgresql.ShowStatement;

/**
Expand Down Expand Up @@ -83,6 +86,8 @@ public static void assertIs(final SQLCaseAssertContext assertContext, final DALS
ShowTableStatusStatementAssert.assertIs(assertContext, (ShowTableStatusStatement) actual, (ShowTableStatusStatementTestCase) expected);
} else if (actual instanceof ShowIndexStatement) {
ShowIndexStatementAssert.assertIs(assertContext, (ShowIndexStatement) actual, (ShowIndexStatementTestCase) expected);
} else if (actual instanceof SetStatement) {
SetVariableStatementAssert.assertIs(assertContext, (SetStatement) actual, (SetVariableStatementTestCase) expected);
} else if (actual instanceof ShowStatement) {
ShowStatementAssert.assertIs(assertContext, (ShowStatement) actual, (ShowStatementTestCase) expected);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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.integrate.asserts.statement.dal.impl;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.sql.parser.integrate.asserts.SQLCaseAssertContext;
import org.apache.shardingsphere.sql.parser.integrate.jaxb.domain.statement.dal.SetVariableStatementTestCase;
import org.apache.shardingsphere.sql.parser.sql.statement.dal.dialect.mysql.SetStatement;

/**
* set variable statement assert.
*
* @author lujingshang
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class SetVariableStatementAssert {

/**
* Assert describe statement is correct with expected parser result.
*
* @param assertContext assert context
* @param actual actual describe statement
* @param expected expected describe statement test case
*/
public static void assertIs(final SQLCaseAssertContext assertContext, final SetStatement actual, final SetVariableStatementTestCase expected) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import org.apache.shardingsphere.sql.parser.integrate.jaxb.domain.statement.dal.ShowTableStatusStatementTestCase;
import org.apache.shardingsphere.sql.parser.integrate.jaxb.domain.statement.dal.ShowTablesStatementTestCase;
import org.apache.shardingsphere.sql.parser.integrate.jaxb.domain.statement.dal.UseStatementTestCase;
import org.apache.shardingsphere.sql.parser.integrate.jaxb.domain.statement.dal.ShowColumnsStatementTestCase;
import org.apache.shardingsphere.sql.parser.integrate.jaxb.domain.statement.dal.SetVariableStatementTestCase;
import org.apache.shardingsphere.sql.parser.integrate.jaxb.domain.statement.dcl.AlterLoginStatementTestCase;
import org.apache.shardingsphere.sql.parser.integrate.jaxb.domain.statement.dcl.AlterRoleStatementTestCase;
import org.apache.shardingsphere.sql.parser.integrate.jaxb.domain.statement.dcl.AlterUserStatementTestCase;
Expand Down Expand Up @@ -193,7 +195,7 @@ public final class SQLParserTestCases {
private final List<ShowTablesStatementTestCase> showTablesTestCases = new LinkedList<>();

@XmlElement(name = "show-columns")
private final List<ShowTablesStatementTestCase> showColumnsTestCases = new LinkedList<>();
private final List<ShowColumnsStatementTestCase> showColumnsTestCases = new LinkedList<>();

@XmlElement(name = "show-create-table")
private final List<ShowCreateTableStatementTestCase> showCreateTableTestCases = new LinkedList<>();
Expand All @@ -203,6 +205,9 @@ public final class SQLParserTestCases {

@XmlElement(name = "show-index")
private final List<ShowIndexStatementTestCase> showIndexTestCases = new LinkedList<>();

@XmlElement(name = "set-variable")
private final List<SetVariableStatementTestCase> setVariableStatementTestCases = new LinkedList<>();

@XmlElement(name = "show")
private final List<ShowStatementTestCase> showTestCases = new LinkedList<>();
Expand Down Expand Up @@ -258,6 +263,7 @@ public Map<String, SQLParserTestCase> getAllSQLParserTestCases() {
putAll(showCreateTableTestCases, result);
putAll(showTableStatusTestCases, result);
putAll(showIndexTestCases, result);
putAll(setVariableStatementTestCases, result);
putAll(showTestCases, result);
putAll(commonTestCases, result);
return result;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.integrate.jaxb.domain.segment.impl.set;

import lombok.Getter;
import org.apache.shardingsphere.sql.parser.integrate.jaxb.domain.segment.AbstractExpectedSQLSegment;

import javax.xml.bind.annotation.XmlElement;

/**
* Expected variable expr.
*
* @author lujingshang
*/
@Getter
public final class ExpectedVariableExpr extends AbstractExpectedSQLSegment {

@XmlElement(name = "variable")
private String variable;

@XmlElement(name = "expr")
private String expr;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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.integrate.jaxb.domain.statement.dal;

import lombok.Getter;
import lombok.Setter;
import org.apache.shardingsphere.sql.parser.integrate.jaxb.domain.segment.impl.set.ExpectedVariableExpr;
import org.apache.shardingsphere.sql.parser.integrate.jaxb.domain.statement.SQLParserTestCase;

import javax.xml.bind.annotation.XmlElement;
import java.util.LinkedList;
import java.util.List;

/**
* set variable statement test case.
*
* @author lujingshang
*/
@Getter
@Setter
public final class SetVariableStatementTestCase extends SQLParserTestCase {

@XmlElement(name = "variable-expr")
private final List<ExpectedVariableExpr> variableExprs = new LinkedList<>();


}
Loading

0 comments on commit dbeb596

Please sign in to comment.