add more tests for TopK, Rows, and SetRowAttrs

This commit is contained in:
Maxton Huff 2021-02-25 16:04:31 -06:00
parent 6b75a8b500
commit ab41d0492c
3 changed files with 82 additions and 1 deletions

View file

@ -7246,6 +7246,15 @@ toronto,2,11
},
csvVerifier: "pilosa\nzebra\nicecream\n",
},
{
query: "Rows(affinity<0),field=likes)",
qrVerifier: func(t *testing.T, resp pilosa.QueryResponse) {
if !reflect.DeepEqual(resp.Results[0].(*pilosa.Row).Keys, []string{"pilosa", "zebra", "icecream"}) {
t.Errorf("wrong values: %+v", resp.Results[0])
}
},
csvVerifier: "pilosa\nzebra\nicecream\n",
},
{
query: "Distinct(Row(affinity>0),field=likes)",
qrVerifier: func(t *testing.T, resp pilosa.QueryResponse) {

View file

@ -54,7 +54,7 @@ singlequotedstring <- ( '\\\'' / '\\\\' / '\\n' / '\\t' / [^'\\] )*
fieldExpr <- ( [[A-Z]] / '_' ) ( [[A-Z]] / [0-9] / '_' / '-' )*
field <- <fieldExpr / reserved> { p.addField(text) }
reserved <- '_row' / '_col' / '_start' / '_end' / '_timestamp' / '_field'
posfield <- <fieldExpr> { p.addPosStr("_field", text) }
posfield <- 'field='? <fieldExpr> { p.addPosStr("_field", text) }
col <- < digits > {p.addPosNum("_col", text)}
/ < '\'' singlequotedstring '\'' > {p.addPosStr("_col", text)}
/ < '"' doublequotedstring '"' > {p.addPosStr("_col", text)}

View file

@ -425,6 +425,54 @@ func TestPQLDeepEquality(t *testing.T) {
{Name: "Row", Args: map[string]interface{}{"unicode": <>漢д ☮♬ ♞🜻💣"}},
},
}},
{
name: "TopK",
call: "TopK(myfield, Row(), a=7)",
exp: &Call{
Name: "TopK",
Args: map[string]interface{}{
"a": int64(7),
"_field": "myfield",
},
Children: []*Call{
{Name: "Row"},
},
}},
{
name: "TopKWithField=",
call: "TopK(field=myfield, Row(), a=7)",
exp: &Call{
Name: "TopK",
Args: map[string]interface{}{
"a": int64(7),
"_field": "myfield",
},
Children: []*Call{
{Name: "Row"},
},
}},
{
name: "Rows",
call: "Rows(myfield, 9, z=4)",
exp: &Call{
Name: "Rows",
Args: map[string]interface{}{
"z": int64(4),
"_field": "myfield",
"_row": int64(9),
},
}},
{
name: "RowsWithField=",
call: "Rows(field=myfield, 9, z=4)",
exp: &Call{
Name: "Rows",
Args: map[string]interface{}{
"z": int64(4),
"_field": "myfield",
"_row": int64(9),
},
}},
{
name: "SetRowAttrs",
call: "SetRowAttrs(myfield, 9, z=4)",
@ -436,6 +484,17 @@ func TestPQLDeepEquality(t *testing.T) {
"_row": int64(9),
},
}},
{
name: "SetRowAttrsWithField=",
call: "SetRowAttrs(field=myfield, 9, z=4)",
exp: &Call{
Name: "SetRowAttrs",
Args: map[string]interface{}{
"z": int64(4),
"_field": "myfield",
"_row": int64(9),
},
}},
{
name: "SetRowAttrsWithRowKeySingleQuote",
call: "SetRowAttrs(myfield, 'rowKey', z=4)",
@ -522,6 +581,19 @@ func TestPQLDeepEquality(t *testing.T) {
{Name: "Row"},
},
}},
{
name: "TopNwithField=",
call: "TopN(field=myfield, Row(), a=7)",
exp: &Call{
Name: "TopN",
Args: map[string]interface{}{
"a": int64(7),
"_field": "myfield",
},
Children: []*Call{
{Name: "Row"},
},
}},
{
name: "RangeEQ",
call: "Row(a==7)",