Skip to content

Commit

Permalink
Merge pull request #51 from sharding-sphere/dev
Browse files Browse the repository at this point in the history
update from origin
  • Loading branch information
beckhampu authored Nov 21, 2018
2 parents c285767 + bd05896 commit f0a54ce
Show file tree
Hide file tree
Showing 44 changed files with 356 additions and 523 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* @author duhongjun
*/
public interface ASTExtractHandler<T> {

/**
* Extract AST.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,16 @@

package io.shardingsphere.core.parsing.antlr.extractor.statement.handler;

import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;

import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.tree.ParseTree;

import com.google.common.base.Optional;

import io.shardingsphere.core.parsing.antlr.extractor.statement.handler.result.ColumnDefinitionExtractResult;
import io.shardingsphere.core.parsing.antlr.extractor.statement.phrase.ColumnDefinitionPhraseExtractor;
import io.shardingsphere.core.parsing.antlr.extractor.statement.util.ASTUtils;
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.tree.ParseTree;

import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;

/**
* Add column extract handler.
Expand All @@ -39,12 +37,6 @@ public class AddColumnExtractHandler implements ASTExtractHandler<Collection<Col

private final ColumnDefinitionPhraseExtractor columnDefinitionPhraseExtractor = new ColumnDefinitionPhraseExtractor();

/**‘
* Extract add column result.
*
* @param ancestorNode ancestor node of ast
* @return column definition
*/
@Override
public Collection<ColumnDefinitionExtractResult> extract(final ParserRuleContext ancestorNode) {
Collection<ParserRuleContext> addColumnNodes = ASTUtils.getAllDescendantNodes(ancestorNode, RuleName.ADD_COLUMN);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,25 @@

package io.shardingsphere.core.parsing.antlr.extractor.statement.handler;

import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;

import org.antlr.v4.runtime.ParserRuleContext;

import com.google.common.base.Optional;

import io.shardingsphere.core.parsing.antlr.extractor.statement.handler.result.ColumnDefinitionExtractResult;
import io.shardingsphere.core.parsing.antlr.extractor.statement.phrase.ColumnDefinitionPhraseExtractor;
import io.shardingsphere.core.parsing.antlr.extractor.statement.util.ASTUtils;
import org.antlr.v4.runtime.ParserRuleContext;

import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;

/**
* Column definition extract handler.
*
* @author duhongjun
*/
public final class ColumnDefinitionExtractHandler implements ASTExtractHandler<Collection<ColumnDefinitionExtractResult>> {

private final ColumnDefinitionPhraseExtractor columnDefinitionPhraseExtractor = new ColumnDefinitionPhraseExtractor();

@Override
public Collection<ColumnDefinitionExtractResult> extract(final ParserRuleContext ancestorNode) {
Collection<ParserRuleContext> columnDefinitionNodes = ASTUtils.getAllDescendantNodes(ancestorNode, RuleName.COLUMN_DEFINITION);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,25 @@

package io.shardingsphere.core.parsing.antlr.extractor.statement.handler;

import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;

import org.antlr.v4.runtime.ParserRuleContext;

import com.google.common.base.Optional;

import io.shardingsphere.core.parsing.antlr.extractor.statement.handler.result.TableExtractResult;
import io.shardingsphere.core.parsing.antlr.extractor.statement.handler.result.TableJoinExtractResult;
import io.shardingsphere.core.parsing.antlr.extractor.statement.util.ASTUtils;
import org.antlr.v4.runtime.ParserRuleContext;

import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;

/**
* Extract table result.
*
* @author duhongjun
*/
public class FromClauseExtractHandler implements ASTExtractHandler<Collection<TableExtractResult>> {

public final class FromClauseExtractHandler implements ASTExtractHandler<Collection<TableExtractResult>> {
private final TableNameExtractHandler tableNameExtractHandler = new TableNameExtractHandler();

/**
* Extract AST.
*
* @param ancestorNode ancestor node of AST
* @return extract result
*/

@Override
public Collection<TableExtractResult> extract(final ParserRuleContext ancestorNode) {
Optional<ParserRuleContext> fromNode = ASTUtils.findFirstChildNode(ancestorNode, RuleName.FROM_CLAUSE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
*
* @author duhongjun
*/
public class GroupByExtractHandler extends OrderByExtractHandler {
public final class GroupByExtractHandler extends OrderByExtractHandler {

public GroupByExtractHandler() {
ruleName = RuleName.GROUPBYCLAUSE;
super(RuleName.GROUPBYCLAUSE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,26 @@

package io.shardingsphere.core.parsing.antlr.extractor.statement.handler;

import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;

import org.antlr.v4.runtime.ParserRuleContext;

import io.shardingsphere.core.parsing.antlr.extractor.statement.handler.result.IndexExtractResult;
import io.shardingsphere.core.parsing.antlr.extractor.statement.util.ASTUtils;
import io.shardingsphere.core.parsing.parser.token.IndexToken;
import io.shardingsphere.core.util.SQLUtil;
import org.antlr.v4.runtime.ParserRuleContext;

import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;

/**
* Multiple index names extract handler.
*
* @author duhongjun
*/
public final class IndexesNameExtractHandler implements ASTExtractHandler<Collection<IndexExtractResult>> {

@Override
public Collection<IndexExtractResult> extract(final ParserRuleContext ancestorNode) {
Collection<ParserRuleContext> indexNameNodes = ASTUtils.getAllDescendantNodes(ancestorNode,
RuleName.INDEX_NAME);
Collection<ParserRuleContext> indexNameNodes = ASTUtils.getAllDescendantNodes(ancestorNode, RuleName.INDEX_NAME);
if (indexNameNodes.isEmpty()) {
return Collections.emptyList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,15 @@

package io.shardingsphere.core.parsing.antlr.extractor.statement.handler;

import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;

import org.antlr.v4.runtime.ParserRuleContext;

import com.google.common.base.Optional;

import io.shardingsphere.core.parsing.antlr.extractor.statement.handler.result.ColumnDefinitionExtractResult;
import io.shardingsphere.core.parsing.antlr.extractor.statement.phrase.ColumnDefinitionPhraseExtractor;
import io.shardingsphere.core.parsing.antlr.extractor.statement.util.ASTUtils;
import org.antlr.v4.runtime.ParserRuleContext;

import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;

/**
* Modify column extract handler.
Expand All @@ -37,13 +35,7 @@
public class ModifyColumnExtractHandler implements ASTExtractHandler<Collection<ColumnDefinitionExtractResult>> {

private final ColumnDefinitionPhraseExtractor columnDefinitionPhraseExtractor = new ColumnDefinitionPhraseExtractor();

/**
* Extract AST.
*
* @param ancestorNode ancestor node of AST
* @return extract result
*/

@Override
public Collection<ColumnDefinitionExtractResult> extract(final ParserRuleContext ancestorNode) {
Collection<ParserRuleContext> modifyColumnNodes = ASTUtils.getAllDescendantNodes(ancestorNode, RuleName.MODIFY_COLUMN);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,33 @@

package io.shardingsphere.core.parsing.antlr.extractor.statement.handler;

import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;

import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.tree.TerminalNode;

import com.google.common.base.Optional;

import io.shardingsphere.core.constant.OrderDirection;
import io.shardingsphere.core.parsing.antlr.extractor.statement.handler.result.OrderByExtractResult;
import io.shardingsphere.core.parsing.antlr.extractor.statement.util.ASTUtils;
import io.shardingsphere.core.parsing.parser.token.OrderByToken;
import lombok.RequiredArgsConstructor;
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.tree.TerminalNode;

import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;

/**
* Order by extract handler.
*
* @author duhongjun
*/
@RequiredArgsConstructor
public class OrderByExtractHandler implements ASTExtractHandler<Collection<OrderByExtractResult>> {

protected RuleName ruleName;

private final RuleName ruleName;
public OrderByExtractHandler() {
ruleName = RuleName.ORDERBYCLAUSE;
}

/**
* Extract AST.
*
* @param ancestorNode ancestor node of AST
* @return extract result
*/

@Override
public Collection<OrderByExtractResult> extract(final ParserRuleContext ancestorNode) {
Optional<ParserRuleContext> orderByParentNode = ASTUtils.findFirstChildNode(ancestorNode, ruleName);
Expand All @@ -74,7 +68,6 @@ public Collection<OrderByExtractResult> extract(final ParserRuleContext ancestor
ownerName = name.substring(0, pos - 1);
name = name.substring(pos + 1);
}

if (1 < count) {
TerminalNode direction = (TerminalNode) each.getChild(1);
if (direction.getSymbol().getStopIndex() - direction.getSymbol().getStartIndex() == 3) {
Expand All @@ -83,7 +76,6 @@ public Collection<OrderByExtractResult> extract(final ParserRuleContext ancestor
orderDirection = OrderDirection.ASC;
}
}

result.add(new OrderByExtractResult(Optional.of(ownerName), Optional.of(name), orderDirection, null, new OrderByToken(orderByParentNode.get().getStop().getStopIndex())));
}
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,25 @@

package io.shardingsphere.core.parsing.antlr.extractor.statement.handler;

import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;

import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.tree.ParseTree;

import com.google.common.base.Optional;

import io.shardingsphere.core.parsing.antlr.extractor.statement.handler.result.IndexExtractResult;
import io.shardingsphere.core.parsing.antlr.extractor.statement.util.ASTUtils;
import io.shardingsphere.core.parsing.parser.token.IndexToken;
import io.shardingsphere.core.util.SQLUtil;
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.tree.ParseTree;

import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;

/**
* Rename index extract handler.
*
* @author duhongjun
*/
public final class RenameIndexExtractHandler implements ASTExtractHandler<Collection<IndexExtractResult>> {

@Override
public Collection<IndexExtractResult> extract(final ParserRuleContext ancestorNode) {
Optional<ParserRuleContext> renameIndexNode = ASTUtils.findFirstChildNode(ancestorNode, RuleName.RENAME_INDEX);
Expand All @@ -57,7 +55,7 @@ public Collection<IndexExtractResult> extract(final ParserRuleContext ancestorNo
result.add(getIndexToken((ParserRuleContext) oldIndexNode));
return result;
}

private IndexExtractResult getIndexToken(final ParserRuleContext indexNode) {
String name = SQLUtil.getNameWithoutSchema(indexNode.getText());
return new IndexExtractResult(name, new IndexToken(indexNode.getStop().getStartIndex(), name, null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,27 @@

package io.shardingsphere.core.parsing.antlr.extractor.statement.handler;

import org.antlr.v4.runtime.ParserRuleContext;

import com.google.common.base.Optional;

import io.shardingsphere.core.parsing.antlr.extractor.statement.handler.result.TableExtractResult;
import io.shardingsphere.core.parsing.antlr.extractor.statement.util.ASTUtils;
import io.shardingsphere.core.parsing.lexer.token.Symbol;
import io.shardingsphere.core.parsing.parser.token.TableToken;
import io.shardingsphere.core.util.SQLUtil;
import org.antlr.v4.runtime.ParserRuleContext;

/**
* Single table name extract handler.
*
* @author duhongjun
*/
public class TableNameExtractHandler implements ASTExtractHandler<Optional<TableExtractResult>> {

/**
* Extract AST.
*
* @param ancestorNode ancestor node of AST
* @return Extract Result
*/
public final class TableNameExtractHandler implements ASTExtractHandler<Optional<TableExtractResult>> {

@Override
public Optional<TableExtractResult> extract(final ParserRuleContext ancestorNode) {
Optional<ParserRuleContext> tableNameNode = ASTUtils.findFirstChildNode(ancestorNode, RuleName.TABLE_NAME);
if (!tableNameNode.isPresent()) {
return Optional.absent();
}

String tableText = tableNameNode.get().getText();
int dotPosition = tableText.contains(Symbol.DOT.getLiterals()) ? tableText.lastIndexOf(Symbol.DOT.getLiterals()) : 0;
String tableName = tableText;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,24 @@

package io.shardingsphere.core.parsing.antlr.extractor.statement.handler;

import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;

import org.antlr.v4.runtime.ParserRuleContext;

import com.google.common.base.Optional;

import io.shardingsphere.core.parsing.antlr.extractor.statement.handler.result.TableExtractResult;
import io.shardingsphere.core.parsing.antlr.extractor.statement.util.ASTUtils;
import org.antlr.v4.runtime.ParserRuleContext;

import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;

/**
* Multiple table names extract handler.
*
* @author duhongjun
*/
public final class TableNamesExtractHandler implements ASTExtractHandler<Collection<TableExtractResult>> {

private final TableNameExtractHandler tableNameExtractHandler = new TableNameExtractHandler();

@Override
public Collection<TableExtractResult> extract(final ParserRuleContext ancestorNode) {
Collection<ParserRuleContext> tableNameNodes = ASTUtils.getAllDescendantNodes(ancestorNode, RuleName.TABLE_NAME);
Expand Down
Loading

0 comments on commit f0a54ce

Please sign in to comment.