|
@@ -296,12 +296,40 @@ func TestMetaFunc_Apply1(t *testing.T) {
|
|
"r": "device2",
|
|
"r": "device2",
|
|
}},
|
|
}},
|
|
},
|
|
},
|
|
|
|
+ {
|
|
|
|
+ sql: "SELECT meta(*) as r FROM test",
|
|
|
|
+ data: &xsql.Tuple{
|
|
|
|
+ Emitter: "test",
|
|
|
|
+ Message: xsql.Message{
|
|
|
|
+ "temperature": 43.2,
|
|
|
|
+ },
|
|
|
|
+ Metadata: xsql.Metadata{
|
|
|
|
+ "temperature": map[string]interface{}{
|
|
|
|
+ "id": "dfadfasfas",
|
|
|
|
+ "device": "device2",
|
|
|
|
+ },
|
|
|
|
+ "device": "gateway",
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ result: []map[string]interface{}{{
|
|
|
|
+ "r": map[string]interface{}{
|
|
|
|
+ "temperature": map[string]interface{}{
|
|
|
|
+ "id": "dfadfasfas",
|
|
|
|
+ "device": "device2",
|
|
|
|
+ },
|
|
|
|
+ "device": "gateway",
|
|
|
|
+ },
|
|
|
|
+ }},
|
|
|
|
+ },
|
|
}
|
|
}
|
|
|
|
|
|
fmt.Printf("The test bucket size is %d.\n\n", len(tests))
|
|
fmt.Printf("The test bucket size is %d.\n\n", len(tests))
|
|
contextLogger := common.Log.WithField("rule", "TestMetaFunc_Apply1")
|
|
contextLogger := common.Log.WithField("rule", "TestMetaFunc_Apply1")
|
|
ctx := contexts.WithValue(contexts.Background(), contexts.LoggerKey, contextLogger)
|
|
ctx := contexts.WithValue(contexts.Background(), contexts.LoggerKey, contextLogger)
|
|
for i, tt := range tests {
|
|
for i, tt := range tests {
|
|
|
|
+ if i != 2 {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
stmt, err := xsql.NewParser(strings.NewReader(tt.sql)).Parse()
|
|
stmt, err := xsql.NewParser(strings.NewReader(tt.sql)).Parse()
|
|
if err != nil || stmt == nil {
|
|
if err != nil || stmt == nil {
|
|
t.Errorf("parse sql %s error %v", tt.sql, err)
|
|
t.Errorf("parse sql %s error %v", tt.sql, err)
|