Exemple #1
0
func runParse(repeat int, sql string, readContext expr.ContextReader) {
	for i := 0; i < repeat; i++ {
		sqlVm, err := expr.ParseSqlVm(sql)
		if err != nil {
			panic(err.Error())
		}
		sel := sqlVm.(*expr.SqlSelect)
		writeContext := datasource.NewContextSimple()
		_, err = vm.EvalSql(sel, writeContext, readContext)
		if err != nil {
			panic(err.Error())
		}
	}
}
Exemple #2
0
// Create Job made up of sub-tasks in DAG that is the
//  plan for execution of this query/job
func BuildSqlJob(conf *datasource.RuntimeConfig, connInfo, sqlText string) (*SqlJob, error) {

	stmt, err := expr.ParseSqlVm(sqlText)
	if err != nil {
		return nil, err
	}

	builder := NewJobBuilder(conf, connInfo)
	ex, err := stmt.Accept(builder)

	if err != nil {
		return nil, err
	}
	if ex == nil {
		return nil, fmt.Errorf("No job runner? %v", sqlText)
	}
	tasks, ok := ex.(Tasks)
	if !ok {
		return nil, fmt.Errorf("expected tasks but got: %T", ex)
	}
	return &SqlJob{tasks, stmt, conf}, nil
}
Exemple #3
0
// Create partial job of just source
func buildSource(t *testing.T, conf *datasource.RuntimeSchema, connInfo, sqlText string, rw *ResultBuffer) *SqlJob {

	stmt, err := expr.ParseSqlVm(sqlText)
	assert.T(t, err == nil)

	tasks := make(Tasks, 0)
	job := NewJobBuilder(conf, connInfo)

	sql := stmt.(*expr.SqlSelect)
	sql.Rewrite()

	// Note, we are doing a custom Job Plan here to
	//   isolate and test just the Source/Where
	task, err := job.VisitSubselect(sql.From[0])
	assert.T(t, err == nil)

	tasks.Add(task.(TaskRunner))
	tasks.Add(rw)

	taskRoot := NewSequential("select", tasks)
	return &SqlJob{taskRoot, stmt, conf}
}
Exemple #4
0
// SqlVm parsers a sql query into columns, where guards, etc
//
func NewSqlVm(sqlText string) (*SqlVm, error) {

	stmt, err := expr.ParseSqlVm(sqlText)
	if err != nil {
		return nil, err
	}
	m := &SqlVm{
		Statement: stmt,
	}
	switch v := stmt.(type) {
	case *expr.SqlSelect:
		m.Keyword = lex.TokenSelect
		m.sel = v
	case *expr.SqlInsert:
		m.Keyword = lex.TokenInsert
		m.ins = v
	case *expr.SqlDelete:
		m.Keyword = lex.TokenDelete
		m.del = v
	}
	return m, nil
}