Exemplo n.º 1
0
// runBQL attemps to excecute the provided query against the given store.
func runBQL(ctx context.Context, bql string, s storage.Store) (*table.Table, error) {
	p, err := grammar.NewParser(grammar.SemanticBQL())
	if err != nil {
		return nil, fmt.Errorf("Failed to initilize a valid BQL parser")
	}
	stm := &semantic.Statement{}
	if err := p.Parse(grammar.NewLLk(bql, 1), stm); err != nil {
		return nil, fmt.Errorf("Failed to parse BQL statement with error %v", err)
	}
	pln, err := planner.New(ctx, s, stm)
	if err != nil {
		return nil, fmt.Errorf("Should have not failed to create a plan using memory.DefaultStorage for statement %v with error %v", stm, err)
	}
	res, err := pln.Excecute(ctx)
	if err != nil {
		return nil, fmt.Errorf("planner.Execute: failed to execute insert plan with error %v", err)
	}
	return res, nil
}
Exemplo n.º 2
0
// runAssertion runs the assertion and compares the outcome. Returns the outcome
// of comparing the obtained result table with the assertion table if there is
// no error during the assertion.
func (a *Assertion) runAssertion(ctx context.Context, st storage.Store, chanSize int) (bool, *table.Table, *table.Table, error) {
	errorizer := func(e error) (bool, *table.Table, *table.Table, error) {
		if a.WillFail && e != nil {
			return true, nil, nil, nil
		}
		return false, nil, nil, e
	}

	// Run the query.
	p, err := grammar.NewParser(grammar.SemanticBQL())
	if err != nil {
		return errorizer(fmt.Errorf("Failed to initilize a valid BQL parser"))
	}
	stm := &semantic.Statement{}
	if err := p.Parse(grammar.NewLLk(a.Statement, 1), stm); err != nil {
		return errorizer(fmt.Errorf("Failed to parse BQL statement with error %v", err))
	}
	pln, err := planner.New(ctx, st, stm, chanSize)
	if err != nil {
		return errorizer(fmt.Errorf("Should have not failed to create a plan using memory.DefaultStorage for statement %v with error %v", stm, err))
	}
	tbl, err := pln.Execute(ctx)
	if err != nil {
		return errorizer(fmt.Errorf("planner.Execute: failed to execute assertion %q with error %v", a.Requires, err))
	}

	// Check the output.
	want, err := a.OutputTable(stm.OutputBindings())
	if err != nil {
		return errorizer(err)
	}
	// Cannot use reflect.DeepEqual, since projections only remove bindings from
	// the table but not the actual data. However, the serialized text version
	// of the tables will be equal regardless of the internal representation.
	return tbl.String() == want.String(), tbl, want, nil
}