Skip to content

Commit

Permalink
fix: contain semicolons in lines (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
veezhang authored Oct 27, 2022
1 parent 1b9171c commit 8d1d289
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ __debug_bin
# Dependency directories (remove the comment below to include it)
vendor/


.idea/
.vscode/

nebula-console
Expand Down
89 changes: 50 additions & 39 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"encoding/json"
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"os"
Expand Down Expand Up @@ -339,43 +340,49 @@ func loop(c cli.Cli) error {
if len(line) == 0 { // 1). The line input is empty, or 2). user presses ctrlC so the input is truncated
continue
}
// Console side command
if isLocal, cmd, args := isConsoleCmd(line); isLocal {
if cmd == Quit {
return nil
statements := strings.Split(line, ";")
for _, statement := range statements {
if statement == "" {
continue
}
executeConsoleCmd(c, cmd, args)
continue
}
// Server side command
var t1 int64 = 0
var t2 int64 = 0
for i := 0; i < g_repeats; i++ {
start := time.Now()
res, err := session.ExecuteWithParameter(line, parameterMap)
if err != nil {
return err
}
if !res.IsSucceed() && !res.IsPartialSucceed() {
c.SetRespError(fmt.Sprintf("an error occurred when executing: %s, [ERROR (%d)]: %s", line, res.GetErrorCode(), res.GetErrorMsg()))
if c.IsPlayingData() {
// Console side command
if isLocal, cmd, args := isConsoleCmd(statement); isLocal {
if cmd == Quit {
return nil
}
executeConsoleCmd(c, cmd, args)
continue
}
// Server side command
var t1 int64 = 0
var t2 int64 = 0
for i := 0; i < g_repeats; i++ {
start := time.Now()
res, err := session.ExecuteWithParameter(statement, parameterMap)
if err != nil {
return err
}
if !res.IsSucceed() && !res.IsPartialSucceed() {
c.SetRespError(fmt.Sprintf("an error occurred when executing: %s, [ERROR (%d)]: %s", statement, res.GetErrorCode(), res.GetErrorMsg()))
if c.IsPlayingData() {
return nil
}
}
t1 += res.GetLatency()
if c.Output() {
duration := printResultSet(res, start)
t2 += int64(duration / 1000)
fmt.Println(time.Now().In(time.Local).Format(time.RFC1123))
fmt.Println()
}
c.SetSpace(res.GetSpaceName())
}
t1 += res.GetLatency()
if c.Output() {
duration := printResultSet(res, start)
t2 += int64(duration / 1000)
fmt.Println(time.Now().In(time.Local).Format(time.RFC1123))
if g_repeats > 1 {
fmt.Printf("Executed %v times, (total time spent %d/%d us), (average time spent %d/%d us)\n", g_repeats, t1, t2, t1/int64(g_repeats), t2/int64(g_repeats))
fmt.Println()
}
c.SetSpace(res.GetSpaceName())
g_repeats = 1
}
if g_repeats > 1 {
fmt.Printf("Executed %v times, (total time spent %d/%d us), (average time spent %d/%d us)\n", g_repeats, t1, t2, t1/int64(g_repeats), t2/int64(g_repeats))
fmt.Println()
}
g_repeats = 1
}
}

Expand Down Expand Up @@ -502,7 +509,17 @@ func main() {
// Check if flags are valid
validateFlags()

interactive := *script == "" && *file == ""
var reader io.Reader
if *script != "" {
reader = strings.NewReader(*script)
} else if *file != "" {
fd, err := os.Open(*file)
if err != nil {
log.Panicf("Open file %s failed, %s", *file, err.Error())
}
reader = fd
}
interactive := reader == nil

historyHome := os.Getenv("HOME")
if historyHome == "" {
Expand Down Expand Up @@ -550,14 +567,8 @@ func main() {
if interactive {
historyFile := path.Join(historyHome, ".nebula_history")
c = cli.NewiCli(historyFile, *username, *goPrompt)
} else if *script != "" {
c = cli.NewnCli(strings.NewReader(*script), true, *username, nil)
} else if *file != "" {
fd, err := os.Open(*file)
if err != nil {
log.Panicf("Open file %s failed, %s", *file, err.Error())
}
c = cli.NewnCli(fd, true, *username, func() { fd.Close() })
} else if reader != nil {
c = cli.NewnCli(reader, true, *username, nil)
}

if c == nil {
Expand Down

0 comments on commit 8d1d289

Please sign in to comment.