Skip to content

Commit

Permalink
Revert "fix: contain semicolons in lines (#181)" (#184)
Browse files Browse the repository at this point in the history
This reverts commit 8d1d289.
  • Loading branch information
veezhang authored Nov 9, 2022
1 parent 96f343f commit c7012ff
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 51 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: 39 additions & 50 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"encoding/json"
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"os"
Expand Down Expand Up @@ -340,49 +339,43 @@ 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
}
statements := strings.Split(line, ";")
for _, statement := range statements {
if statement == "" {
continue
// Console side command
if isLocal, cmd, args := isConsoleCmd(line); isLocal {
if cmd == Quit {
return nil
}
// Console side command
if isLocal, cmd, args := isConsoleCmd(statement); isLocal {
if cmd == Quit {
return nil
}
executeConsoleCmd(c, cmd, args)
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
}
// 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()
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() {
return nil
}
c.SetSpace(res.GetSpaceName())
}
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))
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()
}
g_repeats = 1
c.SetSpace(res.GetSpaceName())
}
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 @@ -506,17 +499,7 @@ func main() {
// Check if flags are valid
validateFlags()

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
interactive := *script == "" && *file == ""

historyHome := os.Getenv("HOME")
if historyHome == "" {
Expand Down Expand Up @@ -564,8 +547,14 @@ func main() {
if interactive {
historyFile := path.Join(historyHome, ".nebula_history")
c = cli.NewiCli(historyFile, *username, *goPrompt)
} else if reader != nil {
c = cli.NewnCli(reader, true, *username, nil)
} 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() })
}

if c == nil {
Expand Down

0 comments on commit c7012ff

Please sign in to comment.