Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export NewJSONReader to use in dolthubapi #1098

Merged
merged 1 commit into from
Dec 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 3 additions & 9 deletions go/libraries/doltcore/table/typed/json/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,19 @@ type JSONReader struct {

func OpenJSONReader(nbf *types.NomsBinFormat, path string, fs filesys.ReadableFS, sch schema.Schema) (*JSONReader, error) {
r, err := fs.OpenForRead(path)

if err != nil {
return nil, err
}

return newJsonReader(nbf, r, fs, sch, path)
return NewJSONReader(nbf, r, sch)
}

func newJsonReader(nbf *types.NomsBinFormat, r io.ReadCloser, fs filesys.ReadableFS, sch schema.Schema, tblPath string) (*JSONReader, error) {
func NewJSONReader(nbf *types.NomsBinFormat, r io.ReadCloser, sch schema.Schema) (*JSONReader, error) {
if sch == nil {
return nil, errors.New("schema must be provided to JsonReader")
}

tblData, err := fs.OpenForRead(tblPath)
if err != nil {
return nil, err
}

decoder := jstream.NewDecoder(tblData, 2) // extract JSON values at a depth level of 1
decoder := jstream.NewDecoder(r, 2) // extract JSON values at a depth level of 1

return &JSONReader{nbf: nbf, closer: r, sch: sch, jsonStream: decoder}, nil
}
Expand Down