Ejemplo n.º 1
0
func (no *NaiveOptimizer) MoveWhereToDataSource(plan planner.Plan) {
	// look for a WHERE clause immediately followed by a data source
	// then ask the datasource if can support this WHERE clause
	// if it can, have it do so, and remove the in memory WHERE
	var last planner.PlanPipelineComponent
	curr := plan.Root.GetSource()
	for curr != nil {
		switch currFilter := curr.(type) {
		case planner.Filter:
			next := curr.GetSource()
			switch nextDataSource := next.(type) {
			case planner.DataSource:
				//log.Printf("Found where clause immidiately followed by datasource %v", last)
				err := nextDataSource.SetFilter(currFilter.GetFilter())
				if err != nil {
					//log.Printf("this datasource cannot support this filter")
				} else {
					//log.Printf("datasource accepted the filter, removing old filter")
					if last == nil {
						plan.Root.SetSource(next)
					} else {
						last.SetSource(next)
					}
				}
			}
		}
		last = curr
		curr = curr.GetSource()
	}
}
Ejemplo n.º 2
0
func (no *NaiveOptimizer) MoveGroupByToDataSource(plan planner.Plan) {
	// look for a GROUP BY clause immediately followed by a data source
	// then ask the datasource if it can support this GROUP BY clause
	// if it can, have it do so, and remove the in memory GROUP BY
	var last planner.PlanPipelineComponent
	curr := plan.Root.GetSource()
	for curr != nil {
		switch currGrouper := curr.(type) {
		case planner.Grouper:
			next := curr.GetSource()
			switch nextDataSource := next.(type) {
			case planner.DataSource:
				//log.Printf("Found group by clause immidiately followed by datasource %v", last)
				err := nextDataSource.SetGroupByWithStatsFields(currGrouper.GetGroupByWithStatsFields())
				if err != nil {
					//log.Printf("this datasource cannot support this group by")
				} else {
					//log.Printf("datasource accepted the group by, removing old group by")
					if last == nil {
						plan.Root.SetSource(next)
					} else {
						last.SetSource(next)
					}
				}
			}
		}
		last = curr
		curr = curr.GetSource()
	}
}
Ejemplo n.º 3
0
func (no *NaiveOptimizer) MoveOffsetToDataSource(plan planner.Plan) {
	// look for a OFFSET clause immediately followed by a data source
	// then ask the datasource if it can support this OFFSET clause
	// if it can, have it do so, and remove the in memory OFFSET
	var last planner.PlanPipelineComponent
	curr := plan.Root.GetSource()
	for curr != nil {
		switch currOffsetter := curr.(type) {
		case planner.Offsetter:
			next := curr.GetSource()
			switch nextDataSource := next.(type) {
			case planner.DataSource:
				//log.Printf("Found offset clause immidiately followed by datasource %v", last)
				err := nextDataSource.SetOffset(currOffsetter.GetOffset())
				if err != nil {
					//log.Printf("this datasource cannot support this offset")
				} else {
					//log.Printf("datasource accepted the offset, removing old group by")
					if last == nil {
						plan.Root.SetSource(next)
					} else {
						last.SetSource(next)
					}
				}
			}
		}
		last = curr
		curr = curr.GetSource()
	}
}