func (c *compiledStatement) preprocess(stmt *influxql.SelectStatement) error {
	c.Ascending = stmt.TimeAscending()
	c.Limit = stmt.Limit
	c.HasTarget = stmt.Target != nil
	valuer := influxql.NowValuer{Now: c.Options.Now, Location: stmt.Location}
	cond, t, err := influxql.ConditionExpr(stmt.Condition, &valuer)
	if err != nil {
		return err
	}
	c.Condition = cond
	c.TimeRange = t
	if err := c.compileDimensions(stmt); err != nil {
		return err
	}
	c.FillOption = stmt.Fill
	if c.TimeRange.Min.IsZero() {
		c.TimeRange.Min = time.Unix(0, influxql.MinTime).UTC()
	}
	if c.TimeRange.Max.IsZero() {
		if !c.Interval.IsZero() {
			c.TimeRange.Max = c.Options.Now
		} else {
			c.TimeRange.Max = time.Unix(0, influxql.MaxTime).UTC()
		}
	}
	return nil
}
preprocess retrieves and records the global attributes of the current statement.
package query
import (
	"errors"
	"fmt"
	"strings"
	"time"
	"github.com/influxdata/influxdb/models"
	"github.com/influxdata/influxql"
)
type CompileOptions struct {
	Now time.Time
}
type Statement interface {
	Prepare(shardMapper ShardMapper, opt SelectOptions) (PreparedStatement, error)
}
type compiledStatement struct {
	Condition influxql.Expr
	TimeRange influxql.TimeRange
	Interval Interval
	InheritedInterval bool
	Ascending bool
	FunctionCalls []*influxql.Call
	OnlySelectors bool
	HasDistinct bool
	FillOption influxql.FillOption
	TopBottomFunction string
	HasAuxiliaryFields bool
	Fields []*compiledField
	TimeFieldName string
	Limit int
	HasTarget bool
	Options CompileOptions
	stmt *influxql.SelectStatement
}
func newCompiler(opt CompileOptions) *compiledStatement {
	if opt.Now.IsZero() {
		opt.Now = time.Now().UTC()
	}
	return &compiledStatement{
		OnlySelectors: true,
		TimeFieldName: "time",
		Options:       opt,
	}
}
func Compile(stmt *influxql.SelectStatement, opt CompileOptions) (Statement, error) {
	c := newCompiler(opt)
	if err := c.preprocess(stmt); err != nil {
		return nil, err
	}
	if err := c.compile(stmt); err != nil {
		return nil, err
	}
	c.stmt = stmt.Clone()
	c.stmt.TimeAlias = c.TimeFieldName
	c.stmt.Condition = c.Condition
	c.stmt.RewriteDistinct()
	c.stmt.RewriteTimeFields()
	c.stmt.RewriteRegexConditions()
	return c, nil
}