func (r *RenameMeasurementRule) StartWAL(path string) bool {
	return true
}
StartWAL implements Rule interface
package rules
import (
	"errors"
	"fmt"
	"log"
	"github.com/Abc-Arbitrage/infix/filter"
	"github.com/Abc-Arbitrage/infix/logging"
	"github.com/influxdata/influxdb/models"
	"github.com/influxdata/influxdb/tsdb/engine/tsm1"
	"github.com/Abc-Arbitrage/infix/storage"
)
var ErrMissingFromFilter = errors.New("missing from filter")
var ErrMissingRenameTo = errors.New("missing rename 'to'")
type RenameMeasurementRule struct {
	filter filter.Filter
	renameFn RenameFn
	renamed  map[string]string
	check  bool
	shard  storage.ShardInfo
	logger *log.Logger
}
type RenameMeasurementRuleConfig struct {
	From filter.Filter
	To   string
}
func NewRenameMeasurement(srcName string, dstName string) *RenameMeasurementRule {
	renameFn := func(measurement string) string {
		return dstName
	}
	filter := filter.NewIncludeFilter([]string{srcName})
	return NewRenameMeasurementWithFilter(filter, renameFn)
}
func NewRenameMeasurementWithPattern(pattern string, renameFn RenameFn) (*RenameMeasurementRule, error) {
	filter, err := filter.NewPatternFilter(pattern)
	if err != nil {
		return nil, err
	}
	return NewRenameMeasurementWithFilter(filter, renameFn), nil
}
func NewRenameMeasurementWithFilter(f filter.Filter, renameFn RenameFn) *RenameMeasurementRule {
	measurementFilter := filter.NewMeasurementFilter(f)
	return &RenameMeasurementRule{
		filter:   measurementFilter,
		renameFn: renameFn,
		renamed:  make(map[string]string),
		check:    false,
		logger:   logging.GetLogger("RenameMeasurementRule"),
	}
}
func (r *RenameMeasurementRule) CheckMode(check bool) {
	r.check = check
}
func (r *RenameMeasurementRule) Flags() int {
	return Standard
}
func (r *RenameMeasurementRule) WithLogger(logger *log.Logger) {
	r.logger = logger
}
func (r *RenameMeasurementRule) FilterKey(key []byte) bool {
	return r.filter.Filter(key)
}
func (r *RenameMeasurementRule) Start() {
}
func (r *RenameMeasurementRule) End() {
}
func (r *RenameMeasurementRule) StartShard(info storage.ShardInfo) bool {
	r.shard = info
	return true
}
func (r *RenameMeasurementRule) EndShard() error {
	if len(r.renamed) > 0 {
		shard := r.shard
		if shard.FieldsIndex == nil {
			return nil
		}
		for oldName, newName := range r.renamed {
			oldFields := shard.FieldsIndex.FieldsByString(oldName)
			if oldFields == nil {
				return fmt.Errorf("Could not find fields. ShardId: %d Measurement: %s", shard.ID, oldName)
			}
			r.logger.Printf("Deleting fields in index for measurement '%s'", oldName)
			shard.FieldsIndex.Delete(oldName)
			shard.FieldsIndex.Delete(newName)
			r.logger.Printf("Updating index with %d fields for new measurement '%s'", oldFields.FieldN(), newName)
			newFields := shard.FieldsIndex.CreateFieldsIfNotExists([]byte(newName))
			for name, iflxType := range oldFields.FieldSet() {
				if err := newFields.CreateFieldIfNotExists([]byte(name), iflxType); err != nil {
					return err
				}
			}
		}
		if !r.check {
			shard.FieldsIndex.Save()
		}
		r.renamed = make(map[string]string)
	}
	return nil
}
func (r *RenameMeasurementRule) StartTSM(path string) bool {
	return true
}
func (r *RenameMeasurementRule) EndTSM() {
}