本文整理匯總了Golang中github.com/influxdb/influxdb/influxql.Eval函數的典型用法代碼示例。如果您正苦於以下問題:Golang Eval函數的具體用法?Golang Eval怎麽用?Golang Eval使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Eval函數的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestEval
// Ensure an expression can be reduced.
func TestEval(t *testing.T) {
for i, tt := range []struct {
in string
out interface{}
data map[string]interface{}
}{
// Number literals.
{in: `1 + 2`, out: float64(3)},
{in: `(foo*2) + ( (4/2) + (3 * 5) - 0.5 )`, out: float64(26.5), data: map[string]interface{}{"foo": float64(5)}},
{in: `foo / 2`, out: float64(2), data: map[string]interface{}{"foo": float64(4)}},
{in: `4 = 4`, out: true},
{in: `4 <> 4`, out: false},
{in: `6 > 4`, out: true},
{in: `4 >= 4`, out: true},
{in: `4 < 6`, out: true},
{in: `4 <= 4`, out: true},
{in: `4 AND 5`, out: nil},
// Boolean literals.
{in: `true AND false`, out: false},
{in: `true OR false`, out: true},
// String literals.
{in: `'foo' = 'bar'`, out: false},
{in: `'foo' = 'foo'`, out: true},
// Variable references.
{in: `foo`, out: "bar", data: map[string]interface{}{"foo": "bar"}},
{in: `foo = 'bar'`, out: true, data: map[string]interface{}{"foo": "bar"}},
{in: `foo = 'bar'`, out: nil, data: map[string]interface{}{"foo": nil}},
{in: `foo <> 'bar'`, out: true, data: map[string]interface{}{"foo": "xxx"}},
} {
// Evaluate expression.
out := influxql.Eval(MustParseExpr(tt.in), tt.data)
// Compare with expected output.
if !reflect.DeepEqual(tt.out, out) {
t.Errorf("%d. %s: unexpected output:\n\nexp=%#v\n\ngot=%#v\n\n", i, tt.in, tt.out, out)
continue
}
}
}
示例2: Next
func (c *seriesCursor) Next(fieldName string, fieldID uint8, tmin, tmax int64) (key int64, value interface{}) {
// TODO: clean this up when we make it so series ids are only queried against the shards they exist in.
// Right now we query for all series ids on a query against each shard, even if that shard may not have the
// data, so cur could be nil.
if c.cur == nil {
return 0, nil
}
for {
var k, v []byte
if !c.initialized {
k, v = c.cur.Seek(u64tob(uint64(tmin)))
c.initialized = true
} else {
k, v = c.cur.Next()
}
// Exit if there is no more data.
if k == nil {
return 0, nil
}
// Marshal key & value.
key, value = int64(btou64(k)), unmarshalValue(v, fieldID)
if key > tmax {
return 0, nil
}
// Evaluate condition. Move to next key/value if non-true.
if c.condition != nil {
if ok, _ := influxql.Eval(c.condition, map[string]interface{}{fieldName: value}).(bool); !ok {
continue
}
}
return key, value
}
}
示例3: matchesWhere
// matchesFilter returns true if the value matches the where clause
func matchesWhere(f influxql.Expr, fields map[string]interface{}) bool {
if ok, _ := influxql.Eval(f, fields).(bool); !ok {
return false
}
return true
}