Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion expr_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import (
"bytes"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"io"
"math"
"sort"
"strings"
Expand Down Expand Up @@ -488,8 +490,21 @@ func decodeExpr(raw json.RawMessage, schema *Schema, caseSensitive bool) (Boolea
// without inspecting bytes by hand.
func firstToken(raw json.RawMessage) (json.Token, error) {
dec := json.NewDecoder(bytes.NewReader(raw))
tok, err := dec.Token()
if err != nil {
return nil, err
}
if _, ok := tok.(bool); ok {
if _, err := dec.Token(); !errors.Is(err, io.EOF) {
if err == nil {
return nil, errors.New("trailing data after boolean expression")
}

return nil, err
}
}

return dec.Token()
return tok, nil
}

func decodePredicate(op Operation, node exprNode, schema *Schema, caseSensitive bool) (BooleanExpression, error) {
Expand Down
14 changes: 14 additions & 0 deletions expr_json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,20 @@ func TestUnmarshalExpressionErrors(t *testing.T) {
}
}

func TestUnmarshalBooleanExpressionRejectsTrailingData(t *testing.T) {
for _, input := range []string{
`true false`,
`false null`,
`true{}`,
`false garbage`,
} {
t.Run(input, func(t *testing.T) {
_, err := iceberg.ParseExpr([]byte(input), nil)
require.ErrorIs(t, err, iceberg.ErrInvalidArgument)
})
}
}

// TestExpressionTransformTermRoundTrip covers a residual filter whose term is a
// partition transform, e.g. a Java server's bucket[100](id) <= 50.
func TestExpressionTransformTermRoundTrip(t *testing.T) {
Expand Down
Loading