Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate GetAll、GetOne、GetRange operation in parser #317

Merged
merged 2 commits into from
Dec 10, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 32 additions & 25 deletions parser/src/main/java/com/distkv/dst/parser/DstNewSqlListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,35 +99,42 @@ public void enterListRput(DstNewSQLParser.ListRputContext ctx) {
}

@Override
public void enterListGet(DstNewSQLParser.ListGetContext ctx) {
public void enterListGetAll(DstNewSQLParser.ListGetAllContext ctx) {
Preconditions.checkState(parsedResult == null);
Preconditions.checkState(ctx.children.size() == 1);

ListProtocol.GetRequest.Builder getRequestBuilder = ListProtocol.GetRequest.newBuilder();
getRequestBuilder.setKey(ctx.getChild(0).getText());
getRequestBuilder.setType(ListProtocol.GetType.GET_ALL);

parsedResult = new DstParsedResult(RequestTypeEnum.LIST_GET, getRequestBuilder.build());
}

@Override
public void enterListGetOne(DstNewSQLParser.ListGetOneContext ctx) {
Preconditions.checkState(parsedResult == null);
Preconditions.checkState(ctx.children.size() == 2);
final ParseTree listGetArgumentsParseTree = ctx.children.get(1);
final int numArguments = listGetArgumentsParseTree.getChildCount();

ListProtocol.GetRequest.Builder builder = ListProtocol.GetRequest.newBuilder();
final String key = listGetArgumentsParseTree.getChild(0).getText();
builder.setKey(key);
if (1 == numArguments) {
// GET_ALL
Preconditions.checkState(listGetArgumentsParseTree.getChildCount() == 1);
builder.setType(ListProtocol.GetType.GET_ALL);
} else if (2 == numArguments) {
// GET_ONE
Preconditions.checkState(listGetArgumentsParseTree.getChildCount() == 2);
builder.setType(ListProtocol.GetType.GET_ONE);
builder.setIndex(Integer.valueOf(listGetArgumentsParseTree.getChild(1).getText()));
} else if (3 == numArguments) {
// GET_RANGE
Preconditions.checkState(listGetArgumentsParseTree.getChildCount() == 3);
builder.setType(ListProtocol.GetType.GET_RANGE);
builder.setFrom(Integer.valueOf(listGetArgumentsParseTree.getChild(1).getText()));
builder.setEnd(Integer.valueOf(listGetArgumentsParseTree.getChild(2).getText()));
} else {
throw new RuntimeException("Failed to parser the command.");
}
ListProtocol.GetRequest.Builder getRequestBuilder = ListProtocol.GetRequest.newBuilder();
getRequestBuilder.setKey(ctx.getChild(0).getText());
getRequestBuilder.setIndex(Integer.valueOf(ctx.getChild(1).getText()));
getRequestBuilder.setType(ListProtocol.GetType.GET_ONE);

parsedResult = new DstParsedResult(RequestTypeEnum.LIST_GET, getRequestBuilder.build());
}

@Override
public void enterListGetRange(DstNewSQLParser.ListGetRangeContext ctx) {
Preconditions.checkState(parsedResult == null);
Preconditions.checkState(ctx.children.size() == 3);

ListProtocol.GetRequest.Builder getRequestBuilder = ListProtocol.GetRequest.newBuilder();
getRequestBuilder.setKey(ctx.getChild(0).getText());
getRequestBuilder.setFrom(Integer.valueOf(ctx.getChild(1).getText()));
getRequestBuilder.setEnd(Integer.valueOf(ctx.getChild(2).getText()));
getRequestBuilder.setType(ListProtocol.GetType.GET_RANGE);

parsedResult = new DstParsedResult(RequestTypeEnum.LIST_GET, builder.build());
parsedResult = new DstParsedResult(RequestTypeEnum.LIST_GET, getRequestBuilder.build());
}

@Override
Expand Down