diff --git a/pql/ast.go b/pql/ast.go index 2e8d31880..355b97740 100644 --- a/pql/ast.go +++ b/pql/ast.go @@ -795,7 +795,7 @@ type Condition struct { // String returns the string representation of the condition. func (cond *Condition) String() string { - return fmt.Sprintf("%s %s", cond.Op.String(), formatValue(cond.Value)) + return fmt.Sprintf("%s%s", cond.Op.String(), formatValue(cond.Value)) } // StringWithSubj returns the string representation of the condition @@ -926,6 +926,8 @@ func (cond *Condition) StringSliceValue() ([]string, bool) { func formatValue(v interface{}) string { switch v := v.(type) { + case nil: + return "null" case string: return fmt.Sprintf("%q", v) case []interface{}: diff --git a/pql/ast_test.go b/pql/ast_test.go index 157b0c6bf..6e3a3d5ad 100644 --- a/pql/ast_test.go +++ b/pql/ast_test.go @@ -36,7 +36,7 @@ func TestCall_String(t *testing.T) { "field0": &pql.Condition{Op: pql.GTE, Value: 10}, }, } - if s := c.String(); s != `Range(field0>= 10, other="f")` { + if s := c.String(); s != `Range(field0>=10, other="f")` { t.Fatalf("unexpected string: %s", s) } }) @@ -44,18 +44,20 @@ func TestCall_String(t *testing.T) { // Ensure condition string with subject is correct. func TestCondition_StringWithSubj(t *testing.T) { - op := pql.BETWEEN subj := "subj" for _, tt := range []struct { - val []interface{} + op pql.Token + val interface{} exp string }{ - {[]interface{}{int64(4), int64(8)}, "4<=subj<=8"}, - {[]interface{}{uint64(5), uint64(9)}, "5<=subj<=9"}, - {[]interface{}{pql.Decimal{Value: -401, Scale: 2}, pql.Decimal{Value: 802, Scale: 1}}, "-4.01<=subj<=80.2"}, + {pql.BETWEEN, []interface{}{int64(4), int64(8)}, "4<=subj<=8"}, + {pql.BETWEEN, []interface{}{uint64(5), uint64(9)}, "5<=subj<=9"}, + {pql.BETWEEN, []interface{}{pql.Decimal{Value: -401, Scale: 2}, pql.Decimal{Value: 802, Scale: 1}}, "-4.01<=subj<=80.2"}, + {pql.EQ, nil, "subj==null"}, + {pql.NEQ, nil, "subj!=null"}, } { c := &pql.Condition{ - Op: op, + Op: tt.op, Value: tt.val, } if sws := c.StringWithSubj(subj); sws != tt.exp { diff --git a/pql/pqlpeg_test.go b/pql/pqlpeg_test.go index faf50056f..48eaf10c4 100644 --- a/pql/pqlpeg_test.go +++ b/pql/pqlpeg_test.go @@ -46,7 +46,7 @@ SetBit(Union(Zitmap(row==4), Intersect(Qitmap(blah>4), Ritmap(field="http://zoo9 if err != nil { t.Fatalf("should have parsed: %v", err) } - if q.String() != `TopN(Bitmap(id== "other"), _field="blah", field="f", n=0)` { + if q.String() != `TopN(Bitmap(id=="other"), _field="blah", field="f", n=0)` { t.Fatalf("Failed, got: %s", q) } @@ -59,7 +59,7 @@ SetBit(Union(Zitmap(row==4), Intersect(Qitmap(blah>4), Ritmap(field="http://zoo9 if err != nil { t.Fatalf("should have parsed: %v", err) } - if q.String() != `Bitmap(did== "other", row=4)` { + if q.String() != `Bitmap(did=="other", row=4)` { t.Fatalf("got %s", q) }