Skip to content

Commit

Permalink
Fixes (#14)
Browse files Browse the repository at this point in the history
* ocf: Fixed issue with ResetReader

* avro: Fixed fast path to use entire buffer

* avro: FIxed formatting
  • Loading branch information
nrwiersma authored Apr 30, 2019
1 parent d5bea8d commit f56072d
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 57 deletions.
2 changes: 1 addition & 1 deletion internal/bytesx/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (r *ResetReader) Read(p []byte) (int, error) {
return 0, io.EOF
}

n := copy(p, r.buf)
n := copy(p, r.buf[r.head:])
r.head += n

return n, nil
Expand Down
2 changes: 1 addition & 1 deletion reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func (r *Reader) ReadString() string {
}

// The string is entirely in the current buffer, fast path.
if r.head+size < r.tail {
if r.head+size <= r.tail {
ret := string(r.buf[r.head : r.head+size])
r.head += size
return ret
Expand Down
2 changes: 1 addition & 1 deletion schema_parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

var (
schemaReserved = []string{"doc", "fields", "items", "name", "namespace", "size", "symbols", "values", "type", "aliases"}
fieldReserved = []string{"default", "doc", "name", "order", "type", "aliases"}
fieldReserved = []string{"default", "doc", "name", "order", "type", "aliases"}
)

// Parse parses a schema string.
Expand Down
108 changes: 54 additions & 54 deletions schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,94 +246,94 @@ func TestRecordSchema(t *testing.T) {

func TestRecordSchema_ValidatesDefault(t *testing.T) {
tests := []struct {
name string
schema string
wantErr bool
name string
schema string
wantErr bool
}{
{
name: "String",
schema: `{"type":"record", "name":"test", "namespace": "org.apache.avro", "fields":[{"name": "a", "type": "string", "default": "test"}]}`,
wantErr: false,
name: "String",
schema: `{"type":"record", "name":"test", "namespace": "org.apache.avro", "fields":[{"name": "a", "type": "string", "default": "test"}]}`,
wantErr: false,
},
{
name: "Int",
schema: `{"type":"record", "name":"test", "namespace": "org.apache.avro", "fields":[{"name": "a", "type": "int", "default": 1}]}`,
wantErr: false,
name: "Int",
schema: `{"type":"record", "name":"test", "namespace": "org.apache.avro", "fields":[{"name": "a", "type": "int", "default": 1}]}`,
wantErr: false,
},
{
name: "Long",
schema: `{"type":"record", "name":"test", "namespace": "org.apache.avro", "fields":[{"name": "a", "type": "long", "default": 1}]}`,
wantErr: false,
name: "Long",
schema: `{"type":"record", "name":"test", "namespace": "org.apache.avro", "fields":[{"name": "a", "type": "long", "default": 1}]}`,
wantErr: false,
},
{
name: "Float",
schema: `{"type":"record", "name":"test", "namespace": "org.apache.avro", "fields":[{"name": "a", "type": "float", "default": 1}]}`,
wantErr: false,
name: "Float",
schema: `{"type":"record", "name":"test", "namespace": "org.apache.avro", "fields":[{"name": "a", "type": "float", "default": 1}]}`,
wantErr: false,
},
{
name: "Double",
schema: `{"type":"record", "name":"test", "namespace": "org.apache.avro", "fields":[{"name": "a", "type": "double", "default": 1}]}`,
wantErr: false,
name: "Double",
schema: `{"type":"record", "name":"test", "namespace": "org.apache.avro", "fields":[{"name": "a", "type": "double", "default": 1}]}`,
wantErr: false,
},
{
name: "Array",
schema: `{"type":"record", "name":"test", "namespace": "org.apache.avro", "fields":[{"name": "a", "type": {"type":"array", "items": "int"}, "default": [1,2]}]}`,
wantErr: false,
name: "Array",
schema: `{"type":"record", "name":"test", "namespace": "org.apache.avro", "fields":[{"name": "a", "type": {"type":"array", "items": "int"}, "default": [1,2]}]}`,
wantErr: false,
},
{
name: "Array Not Array",
schema: `{"type":"record", "name":"test", "namespace": "org.apache.avro", "fields":[{"name": "a", "type": {"type":"array", "items": "int"}, "default": "test"}]}`,
wantErr: true,
name: "Array Not Array",
schema: `{"type":"record", "name":"test", "namespace": "org.apache.avro", "fields":[{"name": "a", "type": {"type":"array", "items": "int"}, "default": "test"}]}`,
wantErr: true,
},
{
name: "Array Invalid Type",
schema: `{"type":"record", "name":"test", "namespace": "org.apache.avro", "fields":[{"name": "a", "type": {"type":"array", "items": "int"}, "default": ["test"]}]}`,
wantErr: true,
name: "Array Invalid Type",
schema: `{"type":"record", "name":"test", "namespace": "org.apache.avro", "fields":[{"name": "a", "type": {"type":"array", "items": "int"}, "default": ["test"]}]}`,
wantErr: true,
},
{
name: "Map",
schema: `{"type":"record", "name":"test", "namespace": "org.apache.avro", "fields":[{"name": "a", "type": {"type":"map", "values": "int"}, "default": {"b": 1}}]}`,
wantErr: false,
name: "Map",
schema: `{"type":"record", "name":"test", "namespace": "org.apache.avro", "fields":[{"name": "a", "type": {"type":"map", "values": "int"}, "default": {"b": 1}}]}`,
wantErr: false,
},
{
name: "Map Not Map",
schema: `{"type":"record", "name":"test", "namespace": "org.apache.avro", "fields":[{"name": "a", "type": {"type":"map", "values": "int"}, "default": "test"}]}`,
wantErr: true,
name: "Map Not Map",
schema: `{"type":"record", "name":"test", "namespace": "org.apache.avro", "fields":[{"name": "a", "type": {"type":"map", "values": "int"}, "default": "test"}]}`,
wantErr: true,
},
{
name: "Map Invalid Type",
schema: `{"type":"record", "name":"test", "namespace": "org.apache.avro", "fields":[{"name": "a", "type": {"type":"map", "values": "int"}, "default": {"b": "test"}}]}`,
wantErr: true,
name: "Map Invalid Type",
schema: `{"type":"record", "name":"test", "namespace": "org.apache.avro", "fields":[{"name": "a", "type": {"type":"map", "values": "int"}, "default": {"b": "test"}}]}`,
wantErr: true,
},
{
name: "Union",
schema: `{"type":"record", "name":"test", "namespace": "org.apache.avro", "fields":[{"name": "a", "type": ["null", "string"], "default": null}]}`,
wantErr: false,
name: "Union",
schema: `{"type":"record", "name":"test", "namespace": "org.apache.avro", "fields":[{"name": "a", "type": ["null", "string"], "default": null}]}`,
wantErr: false,
},
{
name: "Union Invalid Type",
schema: `{"type":"record", "name":"test", "namespace": "org.apache.avro", "fields":[{"name": "a", "type": ["null", "string"], "default": "string"}]}`,
wantErr: true,
name: "Union Invalid Type",
schema: `{"type":"record", "name":"test", "namespace": "org.apache.avro", "fields":[{"name": "a", "type": ["null", "string"], "default": "string"}]}`,
wantErr: true,
},
{
name: "Record",
schema: `{"type":"record", "name":"test", "namespace": "org.apache.avro", "fields":[{"name": "a", "type": {"type":"record", "name": "test2", "fields":[{"name": "b", "type": "int"},{"name": "c", "type": "int", "default": 1}]}, "default": {"b": 1}}]}`,
wantErr: false,
name: "Record",
schema: `{"type":"record", "name":"test", "namespace": "org.apache.avro", "fields":[{"name": "a", "type": {"type":"record", "name": "test2", "fields":[{"name": "b", "type": "int"},{"name": "c", "type": "int", "default": 1}]}, "default": {"b": 1}}]}`,
wantErr: false,
},
{
name: "Record Not Map",
schema: `{"type":"record", "name":"test", "namespace": "org.apache.avro", "fields":[{"name": "a", "type": {"type":"record", "name": "test2", "fields":[{"name": "b", "type": "int"},{"name": "c", "type": "int", "default": 1}]}, "default": "test"}]}`,
wantErr: true,
name: "Record Not Map",
schema: `{"type":"record", "name":"test", "namespace": "org.apache.avro", "fields":[{"name": "a", "type": {"type":"record", "name": "test2", "fields":[{"name": "b", "type": "int"},{"name": "c", "type": "int", "default": 1}]}, "default": "test"}]}`,
wantErr: true,
},
{
name: "Record Invalid Type",
schema: `{"type":"record", "name":"test", "namespace": "org.apache.avro", "fields":[{"name": "a", "type": {"type":"record", "name": "test2", "fields":[{"name": "b", "type": "int"},{"name": "c", "type": "int", "default": 1}]}, "default": {"b": "test"}}]}`,
wantErr: true,
name: "Record Invalid Type",
schema: `{"type":"record", "name":"test", "namespace": "org.apache.avro", "fields":[{"name": "a", "type": {"type":"record", "name": "test2", "fields":[{"name": "b", "type": "int"},{"name": "c", "type": "int", "default": 1}]}, "default": {"b": "test"}}]}`,
wantErr: true,
},
{
name: "Record Invalid Field Type",
schema: `{"type":"record", "name":"test", "namespace": "org.apache.avro", "fields":[{"name": "a", "type": {"type":"record", "name": "test2", "fields":[{"name": "b", "type": "int"},{"name": "c", "type": "int", "default": "test"}]}, "default": {"b": 1}}]}`,
wantErr: true,
name: "Record Invalid Field Type",
schema: `{"type":"record", "name":"test", "namespace": "org.apache.avro", "fields":[{"name": "a", "type": {"type":"record", "name": "test2", "fields":[{"name": "b", "type": "int"},{"name": "c", "type": "int", "default": "test"}]}, "default": {"b": 1}}]}`,
wantErr: true,
},
}

Expand Down

0 comments on commit f56072d

Please sign in to comment.