lowka commented on code in PR #1596:
URL: https://github.com/apache/ignite-3/pull/1596#discussion_r1096960795
##########
modules/runner/src/integrationTest/java/org/apache/ignite/internal/sqllogic/SqlScriptRunner.java:
##########
@@ -244,78 +289,58 @@ boolean ready() throws IOException {
return buffReader.ready();
}
- String positionDescription() {
- return '(' + fileName + ':' + lineNum + ')';
+ ScriptPosition scriptPosition() {
+ return new ScriptPosition(fileName, lineNum);
}
@Override
public void close() throws Exception {
buffReader.close();
}
+ @Nullable
private Command nextCommand() {
try {
- while (script.ready()) {
- String s = script.nextLine();
+ while (ready()) {
+ String line = nextLine();
- if (Strings.isNullOrEmpty(s) || s.startsWith("#")) {
+ if (Strings.isNullOrEmpty(line) || line.startsWith("#")) {
continue;
}
- String[] tokens = s.split("\\s+");
-
- assert !ArrayUtils.nullOrEmpty(tokens) : "Invalid command
line. "
- + script.positionDescription() + ". [cmd=" + s +
']';
-
- Command cmd = null;
-
- switch (tokens[0]) {
- case "statement":
- cmd = new Statement(tokens);
-
- break;
-
- case "query":
- cmd = new Query(tokens);
-
- break;
-
- case "loop":
- cmd = new Loop(tokens);
-
- break;
-
- case "endloop":
- cmd = new EndLoop();
-
- break;
-
- case "mode":
- // TODO: output_hash. output_result, debug, skip,
unskip
-
- break;
-
- default:
- throw new IgniteException("Unexpected command. "
- + script.positionDescription() + ". [cmd="
+ s + ']');
+ String[] tokens = line.split("\\s+");
+ if (tokens.length == 0) {
+ throw reportError("Invalid line", line);
}
- if (cmd != null) {
- return cmd;
- }
+ String token = tokens[0];
+ return parseCommand(token, tokens, line);
}
return null;
} catch (IOException e) {
- throw new RuntimeException("Cannot read next command", e);
+ throw reportError("Can not read next command", null, e);
+ }
+ }
+
+ private Command parseCommand(String token, String[] tokens, String
line) throws IOException {
+ ParseCommand parser = commands.get(token);
+ if (parser == null) {
+ throw reportError("Unexpected command " + token, line);
+ }
+ try {
+ return parser.parse(this, ctx, tokens);
+ } catch (Exception e) {
+ throw reportError("Failed to parse a command", line, e);
}
}
@NotNull
@Override
public Iterator<Command> iterator() {
- final Command cmd0 = nextCommand();
+ Command cmd0 = nextCommand();
return new Iterator<>() {
+ @Nullable
private Command cmd = cmd0;
Review Comment:
Fixed
##########
modules/runner/src/integrationTest/java/org/apache/ignite/internal/sqllogic/SqlScriptRunner.java:
##########
@@ -244,78 +289,58 @@ boolean ready() throws IOException {
return buffReader.ready();
}
- String positionDescription() {
- return '(' + fileName + ':' + lineNum + ')';
+ ScriptPosition scriptPosition() {
+ return new ScriptPosition(fileName, lineNum);
}
@Override
public void close() throws Exception {
buffReader.close();
}
+ @Nullable
private Command nextCommand() {
Review Comment:
Fixed
--
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]