expected_result='from {} where (fieldname1 = "value1" and fieldname1 = "value2") select *'.format(self.table)
self.validate(detection,expected_result)
deftestAggregations(self):
# Count
detection={"selection1":{"fieldname1":"value1"},
"condition":"selection1 | count() > 1"}
expected_result='from {} where fieldname1 = "value1" select count(*) as agg where agg > 1 select *'.format(self.table)
self.validate(detection,expected_result)
# Min
detection={"selection1":{"fieldname1":"value1"},
"condition":"selection1 | min(fieldname2) by fieldname3 > 5"}
expected_result='from {} where fieldname1 = "value1" group by fieldname3 select min(fieldname2) as agg where agg > 5 select *'.format(self.table)
self.validate(detection,expected_result)
# Max
detection={"selection1":{"fieldname1":"value1"},
"condition":"selection1 | max(fieldname2) by fieldname3 > 5"}
expected_result='from {} where fieldname1 = "value1" group by fieldname3 select max(fieldname2) as agg where agg > 5 select *'.format(self.table)
self.validate(detection,expected_result)
# Avg
detection={"selection1":{"fieldname1":"value1"},
"condition":"selection1 | avg(fieldname2) by fieldname3 > 5"}
expected_result='from {} where fieldname1 = "value1" group by fieldname3 select avg(fieldname2) as agg where agg > 5 select *'.format(self.table)
self.validate(detection,expected_result)
# sum
detection={"selection1":{"fieldname1":"value1"},
"condition":"selection1 | sum(fieldname2) by fieldname3 > 5"}
expected_result='from {} where fieldname1 = "value1" group by fieldname3 select sum(fieldname2) as agg where agg > 5 select *'.format(self.table)
self.validate(detection,expected_result)
# <
detection={"selection1":{"fieldname1":"value1"},
"condition":"selection1 | sum(fieldname2) by fieldname3 < 5"}
expected_result='from {} where fieldname1 = "value1" group by fieldname3 select sum(fieldname2) as agg where agg < 5 select *'.format(self.table)
self.validate(detection,expected_result)
# ==
detection={"selection1":{"fieldname1":"value1"},
"condition":"selection1 | sum(fieldname2) by fieldname3 == 5"}
expected_result='from {} where fieldname1 = "value1" group by fieldname3 select sum(fieldname2) as agg where agg == 5 select *'.format(self.table)
self.validate(detection,expected_result)
# Multiple conditions
detection={"selection1":{"fieldname1":"value1"},
"selection2":{"fieldname2":"*","fieldname3":"*"},
"condition":"selection1 or selection2 | count(fieldname4) by fieldname5 > 3"}
expected_result='from {} where (fieldname1 = "value1" or (matches(fieldname2, nameglob("*")) and matches(fieldname3, nameglob("*")))) group by fieldname5 select count(fieldname4) as agg where agg > 3 select *'.format(self.table)
self.validate(detection,expected_result)
deftestFullTextSearch(self):
# Single str FTS
detection={"selection1":["value1"],
"condition":"selection1"}
expected_result='from {} where weaktoktains(raw, "value1", true, true) select *'.format(self.table)
self.validate(detection,expected_result)
# OR node FTS
detection={"selection1":{"fieldname1":"value1"},
"selection2|contains":["value2","value3"],
"condition":"1 of them"}
expected_result='from {} where (fieldname1 = "value1" or weaktoktains(raw, "value2", true, true) or weaktoktains(raw, "value3", true, true)) select *'.format(self.table)