Esempio n. 1
0
// runCommand runs all the BQL statements available in the file.
func runCommand(ctx context.Context, cmd *command.Command, args []string, store storage.Store, chanSize int) int {
	if len(args) < 3 {
		fmt.Fprintf(os.Stderr, "[ERROR] Missing required file path. ")
		cmd.Usage()
		return 2
	}
	file := strings.TrimSpace(args[len(args)-1])
	lines, err := io.GetStatementsFromFile(file)
	if err != nil {
		fmt.Fprintf(os.Stderr, "[ERROR] Failed to read file %s\n\n\t%v\n\n", file, err)
		return 2
	}
	fmt.Printf("Processing file %s\n\n", args[len(args)-1])
	for idx, stm := range lines {
		fmt.Printf("Processing statement (%d/%d):\n%s\n\n", idx+1, len(lines), stm)
		tbl, err := BQL(ctx, stm, store, chanSize)
		if err != nil {
			fmt.Printf("[FAIL] %v\n\n", err)
			continue
		}
		fmt.Println("Result:")
		if tbl.NumRows() > 0 {
			fmt.Println(tbl)
		}
		fmt.Printf("OK\n\n")
	}
	return 0
}
Esempio n. 2
0
// runBQLFromFile loads all the statements in the file and runs them.
func runBQLFromFile(ctx context.Context, driver storage.Store, chanSize int, line string) (string, int, error) {
	ss := strings.Split(strings.TrimSpace(line), " ")
	if len(ss) != 2 {
		return "", 0, fmt.Errorf("wrong syntax: run <file_with_bql_statements>")
	}
	path := ss[1]
	lines, err := io.GetStatementsFromFile(path)
	if err != nil {
		return "", 0, fmt.Errorf("failed to read file %q with error %v on\n", path, err)
	}
	for idx, stm := range lines {
		fmt.Printf("Processing statement (%d/%d)\n", idx+1, len(lines))
		_, err := runBQL(ctx, stm, driver, chanSize)
		if err != nil {
			return "", 0, fmt.Errorf("%v on\n%s\n", err, stm)
		}
	}
	fmt.Println()
	return path, len(lines), nil
}