Пример #1
0
func (req *ArchiveRequest) GetSmapMessage(thing interface{}) *common.SmapMessage {
	var msg = new(common.SmapMessage)
	var rdg = new(common.SmapNumberReading)

	value := ob.Eval(req.value, thing)
	switch t := value.(type) {
	case int64:
		rdg.Value = float64(t)
	case uint64:
		rdg.Value = float64(t)
	case float64:
		rdg.Value = t
	}

	rdg.Time = req.getTime(thing)

	if len(req.uuid) > 0 && req.uuidActual == "" {
		req.uuidActual = common.UUID(ob.Eval(req.uuid, thing).(string))
	} else if req.uuidActual == "" {
		req.uuidActual = common.UUID(req.UUID)
	}
	msg.UUID = req.uuidActual
	msg.Path = req.URI + "/" + req.Value
	msg.Readings = []common.Reading{rdg}

	if len(req.metadataExpr) > 0 {
		msg.Metadata = make(common.Dict)
		msg.Properties = new(common.SmapProperties)
		if md, ok := ob.Eval(req.metadataExpr, thing).(map[string]interface{}); ok {
			for k, v := range md {
				val := fmt.Sprintf("%s", v)
				if k == "UnitofTime" {
					msg.Properties.UnitOfTime, _ = common.ParseUOT(val)
				} else if k == "UnitofMeasure" {
					msg.Properties.UnitOfMeasure = val
				}
				msg.Metadata[k] = val
			}
		}
	}

	return msg
}
Пример #2
0
func getProperties(msg map[string]interface{}) (properties *common.SmapProperties, err error) {
	properties = &common.SmapProperties{}
	if prop, found := msg["Properties"]; found {
		if propmap, ok := prop.(map[string]interface{}); ok {
			// UnitofTime
			if uot, found := propmap["UnitofTime"]; found {
				uotstr, ok := uot.(string)
				if !ok {
					err = errors.New("UnitofTime was not string")
				} else {
					var uot common.UnitOfTime
					uot, err = common.ParseUOT(uotstr)
					properties.UnitOfTime = common.UnitOfTime(uot)
				}
			}
			// UnitofMeasure
			if uom, found := propmap["UnitofMeasure"]; found {
				uomstr, ok := uom.(string)
				if !ok {
					err = errors.New("UnitofMeasure was not string")
				} else {
					properties.UnitOfMeasure = uomstr
				}
			}
			// StreamType
			if st, found := propmap["StreamType"]; found {
				ststr, ok := st.(string)
				if !ok || (ststr != "numeric" && ststr != "object") {
					err = errors.New("StreamType was not 'numeric' or 'object'")
				} else if ststr == "numeric" {
					properties.StreamType = common.NUMERIC_STREAM
				} else if ststr == "object" {
					properties.StreamType = common.OBJECT_STREAM
				}
			}
		}
		return properties, nil
	}
	return properties, PropertiesNotFound
}
Пример #3
0
func (req *ArchiveRequest) GetMetadata(msg *bw.SimpleMessage) *common.SmapMessage {
	var ret = new(common.SmapMessage)
	req.Lock()
	if req.UUID != "" && req.uuidActual == "" {
		req.uuidActual = common.UUID(req.UUID)
	}
	req.Unlock()
	ret.UUID = req.uuidActual
	ret.Path = req.URI + "/" + req.Value
	ret.Metadata = make(common.Dict)
	ret.Properties = new(common.SmapProperties)

	for _, po := range msg.POs {
		var md map[string]interface{}
		if po.IsTypeDF(bw.PODFMsgPack) {
			err := po.(bw.MsgPackPayloadObject).ValueInto(&md)
			if err != nil {
				log.Error(errors.Wrap(err, "Could not unmarshal msgpack metadata"))
				return nil
			}
		} else if po.IsTypeDF(bw.PODFSMetadata) {
			md = make(map[string]interface{})
			tuple := po.(bw.MetadataPayloadObject).Value()
			md[getMetadataKey(msg.URI)] = tuple.Value
		}
		for k, v := range md {
			val := fmt.Sprintf("%s", v)
			if k == "UnitofTime" {
				ret.Properties.UnitOfTime, _ = common.ParseUOT(val)
			} else if k == "UnitofMeasure" {
				ret.Properties.UnitOfMeasure = val
			}
			ret.Metadata[k] = val
		}
	}
	return ret
}
Пример #4
0
func (sqrcvr *sqParserImpl) Parse(sqlex sqLexer) int {
	var sqn int
	var sqVAL sqSymType
	var sqDollar []sqSymType
	_ = sqDollar // silence set and not used
	sqS := sqrcvr.stack[:]

	Nerrs := 0   /* number of errors */
	Errflag := 0 /* error recovery flag */
	sqstate := 0
	sqrcvr.char = -1
	sqtoken := -1 // sqrcvr.char translated into internal numbering
	defer func() {
		// Make sure we report no lookahead when not parsing.
		sqstate = -1
		sqrcvr.char = -1
		sqtoken = -1
	}()
	sqp := -1
	goto sqstack

ret0:
	return 0

ret1:
	return 1

sqstack:
	/* put a state and value onto the stack */
	if sqDebug >= 4 {
		__yyfmt__.Printf("char %v in %v\n", sqTokname(sqtoken), sqStatname(sqstate))
	}

	sqp++
	if sqp >= len(sqS) {
		nyys := make([]sqSymType, len(sqS)*2)
		copy(nyys, sqS)
		sqS = nyys
	}
	sqS[sqp] = sqVAL
	sqS[sqp].yys = sqstate

sqnewstate:
	sqn = sqPact[sqstate]
	if sqn <= sqFlag {
		goto sqdefault /* simple state */
	}
	if sqrcvr.char < 0 {
		sqrcvr.char, sqtoken = sqlex1(sqlex, &sqrcvr.lval)
	}
	sqn += sqtoken
	if sqn < 0 || sqn >= sqLast {
		goto sqdefault
	}
	sqn = sqAct[sqn]
	if sqChk[sqn] == sqtoken { /* valid shift */
		sqrcvr.char = -1
		sqtoken = -1
		sqVAL = sqrcvr.lval
		sqstate = sqn
		if Errflag > 0 {
			Errflag--
		}
		goto sqstack
	}

sqdefault:
	/* default state action */
	sqn = sqDef[sqstate]
	if sqn == -2 {
		if sqrcvr.char < 0 {
			sqrcvr.char, sqtoken = sqlex1(sqlex, &sqrcvr.lval)
		}

		/* look through exception table */
		xi := 0
		for {
			if sqExca[xi+0] == -1 && sqExca[xi+1] == sqstate {
				break
			}
			xi += 2
		}
		for xi += 2; ; xi += 2 {
			sqn = sqExca[xi+0]
			if sqn < 0 || sqn == sqtoken {
				break
			}
		}
		sqn = sqExca[xi+1]
		if sqn < 0 {
			goto ret0
		}
	}
	if sqn == 0 {
		/* error ... attempt to resume parsing */
		switch Errflag {
		case 0: /* brand new error */
			sqlex.Error(sqErrorMessage(sqstate, sqtoken))
			Nerrs++
			if sqDebug >= 1 {
				__yyfmt__.Printf("%s", sqStatname(sqstate))
				__yyfmt__.Printf(" saw %s\n", sqTokname(sqtoken))
			}
			fallthrough

		case 1, 2: /* incompletely recovered error ... try again */
			Errflag = 3

			/* find a state where "error" is a legal shift action */
			for sqp >= 0 {
				sqn = sqPact[sqS[sqp].yys] + sqErrCode
				if sqn >= 0 && sqn < sqLast {
					sqstate = sqAct[sqn] /* simulate a shift of "error" */
					if sqChk[sqstate] == sqErrCode {
						goto sqstack
					}
				}

				/* the current p has no shift on "error", pop stack */
				if sqDebug >= 2 {
					__yyfmt__.Printf("error recovery pops state %d\n", sqS[sqp].yys)
				}
				sqp--
			}
			/* there is no state on the stack with an error shift ... abort */
			goto ret1

		case 3: /* no shift yet; clobber input char */
			if sqDebug >= 2 {
				__yyfmt__.Printf("error recovery discards %s\n", sqTokname(sqtoken))
			}
			if sqtoken == sqEofCode {
				goto ret1
			}
			sqrcvr.char = -1
			sqtoken = -1
			goto sqnewstate /* try again in the same state */
		}
	}

	/* reduction by production sqn */
	if sqDebug >= 2 {
		__yyfmt__.Printf("reduce %v in:\n\t%v\n", sqn, sqStatname(sqstate))
	}

	sqnt := sqn
	sqpt := sqp
	_ = sqpt // guard against "declared and not used"

	sqp -= sqR2[sqn]
	// sqp is now the index of $0. Perform the default action. Iff the
	// reduced production is ε, $1 is possibly out of range.
	if sqp+1 >= len(sqS) {
		nyys := make([]sqSymType, len(sqS)*2)
		copy(nyys, sqS)
		sqS = nyys
	}
	sqVAL = sqS[sqp+1]

	/* consult goto table to find next state */
	sqn = sqR1[sqn]
	sqg := sqPgo[sqn]
	sqj := sqg + sqS[sqp].yys + 1

	if sqj >= sqLast {
		sqstate = sqAct[sqg]
	} else {
		sqstate = sqAct[sqj]
		if sqChk[sqstate] != -sqn {
			sqstate = sqAct[sqg]
		}
	}
	// dummy call; replaced with literal code
	switch sqnt {

	case 1:
		sqDollar = sqS[sqpt-4 : sqpt+1]
		//line query.y:59
		{
			sqlex.(*sqLex).query.Contents = sqDollar[2].list
			sqlex.(*sqLex).query.where = sqDollar[3].dict
			sqlex.(*sqLex).query.qtype = SELECT_TYPE
		}
	case 2:
		sqDollar = sqS[sqpt-3 : sqpt+1]
		//line query.y:65
		{
			sqlex.(*sqLex).query.Contents = sqDollar[2].list
			sqlex.(*sqLex).query.qtype = SELECT_TYPE
		}
	case 3:
		sqDollar = sqS[sqpt-4 : sqpt+1]
		//line query.y:70
		{
			sqlex.(*sqLex).query.where = sqDollar[3].dict
			sqlex.(*sqLex).query.data = sqDollar[2].data
			sqlex.(*sqLex).query.qtype = DATA_TYPE
		}
	case 4:
		sqDollar = sqS[sqpt-4 : sqpt+1]
		//line query.y:76
		{
			sqlex.(*sqLex).query.where = sqDollar[3].dict
			sqlex.(*sqLex).query.set = sqDollar[2].dict
			sqlex.(*sqLex).query.qtype = SET_TYPE
		}
	case 5:
		sqDollar = sqS[sqpt-3 : sqpt+1]
		//line query.y:82
		{
			sqlex.(*sqLex).query.set = sqDollar[2].dict
			sqlex.(*sqLex).query.qtype = SET_TYPE
		}
	case 6:
		sqDollar = sqS[sqpt-4 : sqpt+1]
		//line query.y:87
		{
			sqlex.(*sqLex).query.Contents = sqDollar[2].list
			sqlex.(*sqLex).query.where = sqDollar[3].dict
			sqlex.(*sqLex).query.qtype = DELETE_TYPE
		}
	case 7:
		sqDollar = sqS[sqpt-4 : sqpt+1]
		//line query.y:93
		{
			sqlex.(*sqLex).query.data = sqDollar[2].data
			sqlex.(*sqLex).query.where = sqDollar[3].dict
			sqlex.(*sqLex).query.qtype = DELETE_TYPE
		}
	case 8:
		sqDollar = sqS[sqpt-3 : sqpt+1]
		//line query.y:99
		{
			sqlex.(*sqLex).query.Contents = []string{}
			sqlex.(*sqLex).query.where = sqDollar[2].dict
			sqlex.(*sqLex).query.qtype = DELETE_TYPE
		}
	case 9:
		sqDollar = sqS[sqpt-1 : sqpt+1]
		//line query.y:107
		{
			sqVAL.list = List{sqDollar[1].str}
		}
	case 10:
		sqDollar = sqS[sqpt-3 : sqpt+1]
		//line query.y:111
		{
			sqVAL.list = append(List{sqDollar[1].str}, sqDollar[3].list...)
		}
	case 11:
		sqDollar = sqS[sqpt-3 : sqpt+1]
		//line query.y:117
		{
			sqVAL.list = sqDollar[2].list
		}
	case 12:
		sqDollar = sqS[sqpt-1 : sqpt+1]
		//line query.y:122
		{
			sqVAL.list = List{sqDollar[1].str}
		}
	case 13:
		sqDollar = sqS[sqpt-3 : sqpt+1]
		//line query.y:126
		{
			sqVAL.list = append(List{sqDollar[1].str}, sqDollar[3].list...)
		}
	case 14:
		sqDollar = sqS[sqpt-3 : sqpt+1]
		//line query.y:132
		{
			sqVAL.dict = common.Dict{sqDollar[1].str: sqDollar[3].str}
		}
	case 15:
		sqDollar = sqS[sqpt-3 : sqpt+1]
		//line query.y:136
		{
			sqVAL.dict = common.Dict{sqDollar[1].str: sqDollar[3].str}
		}
	case 16:
		sqDollar = sqS[sqpt-3 : sqpt+1]
		//line query.y:140
		{
			sqVAL.dict = common.Dict{sqDollar[1].str: sqDollar[3].list}
		}
	case 17:
		sqDollar = sqS[sqpt-5 : sqpt+1]
		//line query.y:144
		{
			sqDollar[5].dict[sqDollar[1].str] = sqDollar[3].str
			sqVAL.dict = sqDollar[5].dict
		}
	case 18:
		sqDollar = sqS[sqpt-5 : sqpt+1]
		//line query.y:149
		{
			sqDollar[5].dict[sqDollar[1].str] = sqDollar[3].str
			sqVAL.dict = sqDollar[5].dict
		}
	case 19:
		sqDollar = sqS[sqpt-5 : sqpt+1]
		//line query.y:154
		{
			sqDollar[5].dict[sqDollar[1].str] = sqDollar[3].list
			sqVAL.dict = sqDollar[5].dict
		}
	case 20:
		sqDollar = sqS[sqpt-1 : sqpt+1]
		//line query.y:161
		{
			sqlex.(*sqLex).query.Contents = sqDollar[1].list
			sqVAL.list = sqDollar[1].list
		}
	case 21:
		sqDollar = sqS[sqpt-1 : sqpt+1]
		//line query.y:166
		{
			sqVAL.list = List{}
		}
	case 22:
		sqDollar = sqS[sqpt-2 : sqpt+1]
		//line query.y:170
		{
			sqlex.(*sqLex).query.distinct = true
			sqVAL.list = List{sqDollar[2].str}
		}
	case 23:
		sqDollar = sqS[sqpt-1 : sqpt+1]
		//line query.y:175
		{
			sqlex.(*sqLex).query.distinct = true
			sqVAL.list = List{}
		}
	case 24:
		sqDollar = sqS[sqpt-9 : sqpt+1]
		//line query.y:182
		{
			sqVAL.data = &DataQuery{Dtype: IN_TYPE, Start: sqDollar[4].time, End: sqDollar[6].time, Limit: sqDollar[8].limit, Timeconv: sqDollar[9].timeconv, IsStatistical: false, IsWindow: false}
		}
	case 25:
		sqDollar = sqS[sqpt-7 : sqpt+1]
		//line query.y:186
		{
			sqVAL.data = &DataQuery{Dtype: IN_TYPE, Start: sqDollar[3].time, End: sqDollar[5].time, Limit: sqDollar[6].limit, Timeconv: sqDollar[7].timeconv, IsStatistical: false, IsWindow: false}
		}
	case 26:
		sqDollar = sqS[sqpt-13 : sqpt+1]
		//line query.y:190
		{
			num, err := strconv.ParseInt(sqDollar[3].str, 10, 64)
			if err != nil {
				sqlex.(*sqLex).Error(fmt.Sprintf("Could not parse integer \"%v\" (%v)", sqDollar[1].str, err.Error()))
			}
			sqVAL.data = &DataQuery{Dtype: IN_TYPE, Start: sqDollar[8].time, End: sqDollar[10].time, Limit: sqDollar[12].limit, Timeconv: sqDollar[13].timeconv, IsStatistical: true, IsWindow: false, PointWidth: uint64(num)}
		}
	case 27:
		sqDollar = sqS[sqpt-13 : sqpt+1]
		//line query.y:198
		{
			num, err := strconv.ParseInt(sqDollar[3].str, 10, 64)
			if err != nil {
				sqlex.(*sqLex).Error(fmt.Sprintf("Could not parse integer \"%v\" (%v)", sqDollar[1].str, err.Error()))
			}
			sqVAL.data = &DataQuery{Dtype: IN_TYPE, Start: sqDollar[8].time, End: sqDollar[10].time, Limit: sqDollar[12].limit, Timeconv: sqDollar[13].timeconv, IsStatistical: true, IsWindow: false, PointWidth: uint64(num)}
		}
	case 28:
		sqDollar = sqS[sqpt-14 : sqpt+1]
		//line query.y:206
		{
			dur, err := common.ParseReltime(sqDollar[3].str, sqDollar[4].str)
			if err != nil {
				sqlex.(*sqLex).Error(fmt.Sprintf("Error parsing relative time \"%v %v\" (%v)", sqDollar[3].str, sqDollar[4].str, err.Error()))
			}
			sqVAL.data = &DataQuery{Dtype: IN_TYPE, Start: sqDollar[9].time, End: sqDollar[11].time, Limit: sqDollar[13].limit, Timeconv: sqDollar[14].timeconv, IsStatistical: false, IsWindow: true, Width: uint64(dur.Nanoseconds())}
		}
	case 29:
		sqDollar = sqS[sqpt-5 : sqpt+1]
		//line query.y:214
		{
			sqVAL.data = &DataQuery{Dtype: BEFORE_TYPE, Start: sqDollar[3].time, Limit: sqDollar[4].limit, Timeconv: sqDollar[5].timeconv, IsStatistical: false, IsWindow: false}
		}
	case 30:
		sqDollar = sqS[sqpt-5 : sqpt+1]
		//line query.y:218
		{
			sqVAL.data = &DataQuery{Dtype: AFTER_TYPE, Start: sqDollar[3].time, Limit: sqDollar[4].limit, Timeconv: sqDollar[5].timeconv, IsStatistical: false, IsWindow: false}
		}
	case 31:
		sqDollar = sqS[sqpt-1 : sqpt+1]
		//line query.y:224
		{
			sqVAL.time = sqDollar[1].time
		}
	case 32:
		sqDollar = sqS[sqpt-2 : sqpt+1]
		//line query.y:228
		{
			sqVAL.time = sqDollar[1].time.Add(sqDollar[2].timediff)
		}
	case 33:
		sqDollar = sqS[sqpt-2 : sqpt+1]
		//line query.y:234
		{
			foundtime, err := common.ParseAbsTime(sqDollar[1].str, sqDollar[2].str)
			if err != nil {
				sqlex.(*sqLex).Error(fmt.Sprintf("Could not parse time \"%v %v\" (%v)", sqDollar[1].str, sqDollar[2].str, err.Error()))
			}
			sqVAL.time = foundtime
		}
	case 34:
		sqDollar = sqS[sqpt-1 : sqpt+1]
		//line query.y:242
		{
			num, err := strconv.ParseInt(sqDollar[1].str, 10, 64)
			if err != nil {
				sqlex.(*sqLex).Error(fmt.Sprintf("Could not parse integer \"%v\" (%v)", sqDollar[1].str, err.Error()))
			}
			sqVAL.time = _time.Unix(num, 0)
		}
	case 35:
		sqDollar = sqS[sqpt-1 : sqpt+1]
		//line query.y:250
		{
			found := false
			for _, format := range supported_formats {
				t, err := _time.Parse(format, sqDollar[1].str)
				if err != nil {
					continue
				}
				sqVAL.time = t
				found = true
				break
			}
			if !found {
				sqlex.(*sqLex).Error(fmt.Sprintf("No time format matching \"%v\" found", sqDollar[1].str))
			}
		}
	case 36:
		sqDollar = sqS[sqpt-1 : sqpt+1]
		//line query.y:266
		{
			sqVAL.time = _time.Now()
		}
	case 37:
		sqDollar = sqS[sqpt-2 : sqpt+1]
		//line query.y:272
		{
			var err error
			sqVAL.timediff, err = common.ParseReltime(sqDollar[1].str, sqDollar[2].str)
			if err != nil {
				sqlex.(*sqLex).Error(fmt.Sprintf("Error parsing relative time \"%v %v\" (%v)", sqDollar[1].str, sqDollar[2].str, err.Error()))
			}
		}
	case 38:
		sqDollar = sqS[sqpt-3 : sqpt+1]
		//line query.y:280
		{
			newDuration, err := common.ParseReltime(sqDollar[1].str, sqDollar[2].str)
			if err != nil {
				sqlex.(*sqLex).Error(fmt.Sprintf("Error parsing relative time \"%v %v\" (%v)", sqDollar[1].str, sqDollar[2].str, err.Error()))
			}
			sqVAL.timediff = common.AddDurations(newDuration, sqDollar[3].timediff)
		}
	case 39:
		sqDollar = sqS[sqpt-0 : sqpt+1]
		//line query.y:290
		{
			sqVAL.limit = Limit{Limit: -1, Streamlimit: -1}
		}
	case 40:
		sqDollar = sqS[sqpt-2 : sqpt+1]
		//line query.y:294
		{
			num, err := strconv.ParseInt(sqDollar[2].str, 10, 64)
			if err != nil {
				sqlex.(*sqLex).Error(fmt.Sprintf("Could not parse integer \"%v\" (%v)", sqDollar[2].str, err.Error()))
			}
			sqVAL.limit = Limit{Limit: num, Streamlimit: -1}
		}
	case 41:
		sqDollar = sqS[sqpt-2 : sqpt+1]
		//line query.y:302
		{
			num, err := strconv.ParseInt(sqDollar[2].str, 10, 64)
			if err != nil {
				sqlex.(*sqLex).Error(fmt.Sprintf("Could not parse integer \"%v\" (%v)", sqDollar[2].str, err.Error()))
			}
			sqVAL.limit = Limit{Limit: -1, Streamlimit: num}
		}
	case 42:
		sqDollar = sqS[sqpt-4 : sqpt+1]
		//line query.y:310
		{
			limit_num, err := strconv.ParseInt(sqDollar[2].str, 10, 64)
			if err != nil {
				sqlex.(*sqLex).Error(fmt.Sprintf("Could not parse integer \"%v\" (%v)", sqDollar[2].str, err.Error()))
			}
			slimit_num, err := strconv.ParseInt(sqDollar[4].str, 10, 64)
			if err != nil {
				sqlex.(*sqLex).Error(fmt.Sprintf("Could not parse integer \"%v\" (%v)", sqDollar[2].str, err.Error()))
			}
			sqVAL.limit = Limit{Limit: limit_num, Streamlimit: slimit_num}
		}
	case 43:
		sqDollar = sqS[sqpt-0 : sqpt+1]
		//line query.y:324
		{
			sqVAL.timeconv = common.UOT_MS
		}
	case 44:
		sqDollar = sqS[sqpt-2 : sqpt+1]
		//line query.y:328
		{
			uot, err := common.ParseUOT(sqDollar[2].str)
			if err != nil {
				sqlex.(*sqLex).Error(fmt.Sprintf("Could not parse unit of time %v (%v)", sqDollar[2].str, err))
			}
			sqVAL.timeconv = uot
		}
	case 45:
		sqDollar = sqS[sqpt-2 : sqpt+1]
		//line query.y:340
		{
			sqVAL.dict = sqDollar[2].dict
		}
	case 46:
		sqDollar = sqS[sqpt-3 : sqpt+1]
		//line query.y:347
		{
			sqVAL.dict = common.Dict{fixMongoKey(sqDollar[1].str): common.Dict{"$regex": sqDollar[3].str}}
		}
	case 47:
		sqDollar = sqS[sqpt-3 : sqpt+1]
		//line query.y:351
		{
			sqVAL.dict = common.Dict{fixMongoKey(sqDollar[1].str): sqDollar[3].str}
		}
	case 48:
		sqDollar = sqS[sqpt-3 : sqpt+1]
		//line query.y:355
		{
			sqVAL.dict = common.Dict{fixMongoKey(sqDollar[1].str): sqDollar[3].str}
		}
	case 49:
		sqDollar = sqS[sqpt-3 : sqpt+1]
		//line query.y:359
		{
			sqVAL.dict = common.Dict{fixMongoKey(sqDollar[1].str): common.Dict{"$neq": sqDollar[3].str}}
		}
	case 50:
		sqDollar = sqS[sqpt-2 : sqpt+1]
		//line query.y:363
		{
			sqVAL.dict = common.Dict{fixMongoKey(sqDollar[2].str): common.Dict{"$exists": true}}
		}
	case 51:
		sqDollar = sqS[sqpt-3 : sqpt+1]
		//line query.y:367
		{
			sqVAL.dict = common.Dict{fixMongoKey(sqDollar[3].str): common.Dict{"$in": sqDollar[1].list}}
		}
	case 52:
		sqDollar = sqS[sqpt-4 : sqpt+1]
		//line query.y:371
		{
			sqVAL.dict = common.Dict{fixMongoKey(sqDollar[3].str): common.Dict{"$not": common.Dict{"$in": sqDollar[1].list}}}
		}
	case 53:
		sqDollar = sqS[sqpt-3 : sqpt+1]
		//line query.y:375
		{
			sqVAL.dict = sqDollar[2].dict
		}
	case 54:
		sqDollar = sqS[sqpt-1 : sqpt+1]
		//line query.y:381
		{
			sqVAL.str = sqDollar[1].str[1 : len(sqDollar[1].str)-1]
		}
	case 55:
		sqDollar = sqS[sqpt-1 : sqpt+1]
		//line query.y:387
		{

			sqlex.(*sqLex)._keys[sqDollar[1].str] = struct{}{}
			sqVAL.str = cleantagstring(sqDollar[1].str)
		}
	case 56:
		sqDollar = sqS[sqpt-3 : sqpt+1]
		//line query.y:395
		{
			sqVAL.dict = common.Dict{"$and": []common.Dict{sqDollar[1].dict, sqDollar[3].dict}}
		}
	case 57:
		sqDollar = sqS[sqpt-3 : sqpt+1]
		//line query.y:399
		{
			sqVAL.dict = common.Dict{"$or": []common.Dict{sqDollar[1].dict, sqDollar[3].dict}}
		}
	case 58:
		sqDollar = sqS[sqpt-2 : sqpt+1]
		//line query.y:403
		{
			tmp := make(common.Dict)
			for k, v := range sqDollar[2].dict {
				tmp[k] = common.Dict{"$ne": v}
			}
			sqVAL.dict = tmp
		}
	case 59:
		sqDollar = sqS[sqpt-1 : sqpt+1]
		//line query.y:411
		{
			sqVAL.dict = sqDollar[1].dict
		}
	}
	goto sqstack /* stack new state and value */
}
Пример #5
0
// First, we check that all the fields are valid and the necessary ones are populated.
// This also involves filling in the optional ones with sane values.
// Then we build a chain on the URI to the VK -- if this fails, then we stop
// Then we build the operator chains for the expressions required
// Then we subscribe to the URI indicated.
func (bwh *BOSSWaveHandler) ParseArchiveRequest(request *ArchiveRequest) (*URIArchiver, error) {
	if request.FromVK == "" {
		return nil, errors.New("VK was empty in ArchiveRequest")
	}
	request.value = ob.Parse(request.Value)

	if request.UUID == "" {
		request.UUID = uuid.NewV3(NAMESPACE_UUID, request.URI+string(request.PO)+request.Value).String()
	} else {
		request.uuid = ob.Parse(request.UUID)
	}

	if request.Time != "" {
		request.time = ob.Parse(request.Time)
	}

	if request.MetadataExpr != "" {
		request.metadataExpr = ob.Parse(request.MetadataExpr)
	}
	if request.InheritMetadata {
		md, _, err := bwh.bw.GetMetadata(request.URI)
		if err != nil {
			return nil, err
		}
		var ret = new(common.SmapMessage)
		request.Lock()
		if request.UUID != "" && request.uuidActual == "" {
			request.uuidActual = common.UUID(request.UUID)
		}
		request.Unlock()
		ret.UUID = request.uuidActual
		ret.Path = request.URI + "/" + request.Value
		ret.Metadata = make(common.Dict)
		ret.Properties = new(common.SmapProperties)
		for k, v := range md {
			val := fmt.Sprintf("%s", v.Value)
			if k == "UnitofTime" {
				ret.Properties.UnitOfTime, _ = common.ParseUOT(val)
			} else if k == "UnitofMeasure" {
				ret.Properties.UnitOfMeasure = val
			}
			ret.Metadata[k] = val
		}
		if err = bwh.a.AddData(ret); err != nil {
			log.Error(errors.Wrap(err, "Could not add data"))
		}
	}

	var metadataChan = make(chan *bw.SimpleMessage)
	if len(request.MetadataURIs) > 0 {
		for _, metadataURI := range request.MetadataURIs {
			sub1, err := bwh.bw.Subscribe(&bw.SubscribeParams{
				URI: strings.TrimSuffix(metadataURI, "/") + "/!meta/+",
			})
			if err != nil {
				return nil, err
			}
			go func() {
				for msg := range sub1 {
					metadataChan <- msg
				}
			}()

			q1, err := bwh.bw.Query(&bw.QueryParams{
				URI: strings.TrimSuffix(metadataURI, "/") + "/!meta/+",
			})
			if err != nil {
				return nil, err
			}
			go func() {
				for msg := range q1 {
					metadataChan <- msg
				}
			}()
		}
	}
	//TODO: subscribe then query MetadataBlock

	log.Debugf("Subscribing for Archival on %s", request.URI)
	sub, err := bwh.bw.Subscribe(&bw.SubscribeParams{
		URI: request.URI,
	})
	if err != nil {
		return nil, errors.Wrap(err, "Could not subscribe")
	}
	log.Debugf("Got archive request")
	request.Dump()

	archiver := &URIArchiver{sub, metadataChan, request}
	go archiver.Listen(bwh.a)

	return archiver, nil
}