Esempio n. 1
0
// CreateSketch ...
func (m *sketchManager) create(info *datamodel.Info) error {
	sketch, err := sketches.CreateSketch(info)
	if err != nil {
		return err
	}
	m.sketches[info.ID()] = sketch
	return nil
}
Esempio n. 2
0
// CreateDomain ...
func (m *Manager) CreateDomain(info *datamodel.Info) error {
	infos := make(map[string]*datamodel.Info)
	for _, typ := range datamodel.GetTypesPb() {
		styp := typ
		tmpInfo := info.Copy()
		tmpInfo.Type = &styp
		infos[tmpInfo.ID()] = tmpInfo
	}
	return m.domains.create(info.GetName(), infos)
}
Esempio n. 3
0
func (m *infoManager) create(info *datamodel.Info) error {
	if _, ok := m.info[info.ID()]; ok {
		return fmt.Errorf(`Sketch of type "%s" with name "%s" already exists`,
			info.GetType(), info.GetName())
	}
	m.info[info.ID()] = info
	return nil
}
Esempio n. 4
0
// CreateSketch ...
func (m *Manager) CreateSketch(info *datamodel.Info) error {
	if !isValidType(info) {
		return fmt.Errorf("Can not create sketch of type %s, invalid type.", info.Type)
	}
	if err := m.infos.create(info); err != nil {
		return err
	}
	if err := m.sketches.create(info); err != nil {
		// If error occurred during creation of sketch, delete info
		if err2 := m.infos.delete(info.ID()); err2 != nil {
			return fmt.Errorf("%q\n%q ", err, err2)
		}
		return err
	}
	return nil
}
Esempio n. 5
0
// CreateSketch ...
func CreateSketch(info *datamodel.Info) (*SketchProxy, error) {
	var err error
	var sketch datamodel.Sketcher
	sp := &SketchProxy{info, sketch, sync.RWMutex{}}

	switch datamodel.GetTypeString(info.GetType()) {
	case datamodel.HLLPP:
		sp.sketch, err = NewHLLPPSketch(info)
	case datamodel.CML:
		sp.sketch, err = NewCMLSketch(info)
	case datamodel.TopK:
		sp.sketch, err = NewTopKSketch(info)
	case datamodel.Bloom:
		sp.sketch, err = NewBloomSketch(info)
	default:
		return nil, fmt.Errorf("Invalid sketch type: %s", sp.GetType())
	}

	if err != nil {
		return nil, err
	}
	return sp, nil
}
Esempio n. 6
0
// LoadSketch ...
func LoadSketch(info *datamodel.Info, file *os.File) (*SketchProxy, error) {
	var sketch datamodel.Sketcher
	sp := &SketchProxy{info, sketch, sync.RWMutex{}}

	size, err := utils.GetFileSize(file)
	if err != nil {
		return nil, err
	}

	data := make([]byte, size, size)
	_, err = file.Read(data)
	if err != nil {
		return nil, fmt.Errorf("Error loading data for sketch: %s", info.ID())
	}

	switch datamodel.GetTypeString(info.GetType()) {
	case datamodel.HLLPP:
		sp.sketch = &HLLPPSketch{}
		err = sp.sketch.Unmarshal(info, data)
	case datamodel.CML:
		sp.sketch = &CMLSketch{}
		err = sp.sketch.Unmarshal(info, data)
	case datamodel.TopK:
		sp.sketch = &TopKSketch{}
		err = sp.sketch.Unmarshal(info, data)
	case datamodel.Bloom:
		sp.sketch = &BloomSketch{}
		err = sp.sketch.Unmarshal(info, data)
	default:
		return nil, fmt.Errorf("Invalid sketch type: %s", sp.GetType())
	}
	if err != nil {
		return nil, err
	}
	return sp, nil
}
Esempio n. 7
0
func isValidType(info *datamodel.Info) bool {
	if info.Type == nil {
		return false
	}
	return len(datamodel.GetTypeString(info.GetType())) != 0
}
Esempio n. 8
0
// NewDict ...
func NewDict(info *datamodel.Info) *Dict {
	sketch := make(map[string]uint)
	size := info.GetProperties().GetMaxUniqueItems() / 10
	d := Dict{info, sketch, uint(size)}
	return &d
}