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

add support for VNG in API responses and load requests #4345

Merged
merged 1 commit into from
Jan 31, 2023
Merged
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
5 changes: 5 additions & 0 deletions api/mime.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const (
MediaTypeLine = "application/x-line"
MediaTypeNDJSON = "application/x-ndjson"
MediaTypeParquet = "application/x-parquet"
MediaTypeVNG = "application/x-vng"
MediaTypeZeek = "application/x-zeek"
MediaTypeZJSON = "application/x-zjson"
MediaTypeZNG = "application/x-zng"
Expand Down Expand Up @@ -54,6 +55,8 @@ func MediaTypeToFormat(s string, dflt string) (string, error) {
return "ndjson", nil
case MediaTypeParquet:
return "parquet", nil
case MediaTypeVNG:
return "vng", nil
case MediaTypeZeek:
return "zeek", nil
case MediaTypeZJSON:
Expand All @@ -80,6 +83,8 @@ func FormatToMediaType(format string) string {
return MediaTypeNDJSON
case "parquet":
return MediaTypeParquet
case "vng":
return MediaTypeVNG
case "zeek":
return MediaTypeZeek
case "zjson":
Expand Down
9 changes: 8 additions & 1 deletion api/queryio/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/brimdata/zed/zio"
"github.com/brimdata/zed/zio/anyio"
"github.com/brimdata/zed/zio/jsonio"
"github.com/brimdata/zed/zio/vngio"
)

type controlWriter interface {
Expand Down Expand Up @@ -44,7 +45,13 @@ func NewWriter(w io.WriteCloser, format string, flusher http.Flusher, ctrl bool)
case "ndjson":
d.writer = jsonio.NewWriter(w)
default:
d.writer, err = anyio.NewWriter(zio.NopCloser(w), anyio.WriterOpts{Format: format})
d.writer, err = anyio.NewWriter(zio.NopCloser(w), anyio.WriterOpts{
Format: format,
VNG: vngio.WriterOpts{
ColumnThresh: vngio.DefaultColumnThresh,
SkewThresh: vngio.DefaultSkewThresh,
},
})
}
return d, err
}
Expand Down
4 changes: 2 additions & 2 deletions service/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,8 @@ func handleBranchLoad(c *Core, w *ResponseWriter, r *Request) {
w.Error(err)
return
}
if format == "parquet" {
// This format requires a reader that implements io.ReaderAt and
if format == "parquet" || format == "vng" {
// These formats require a reader that implements io.ReaderAt and
// io.Seeker. Copy the reader to a temporary file and use that.
//
// TODO: Add a way to disable this or limit file size.
Expand Down
21 changes: 21 additions & 0 deletions service/ztests/curl-load-vng.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
script: |
source service.sh
zed create -q test
zq -f vng in.zson |
curl -H Content-Type:application/x-vng --data-binary @- \
--fail $ZED_LAKE/pool/test/branch/main | zq -z commit:=0 -
echo //
zed query -z 'from test'

inputs:
- name: in.zson
data: |
{x:1}
- name: service.sh

outputs:
- name: stdout
data: |
{commit:0,warnings:[]([string])}
//
{x:1}
11 changes: 8 additions & 3 deletions service/ztests/curl-query.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ script: |
echo === application/vnd.apache.arrow.stream ===
curl -H 'Accept: application/vnd.apache.arrow.stream' -d '{"query":"from test"}' $ZED_LAKE/query |
zq -z -i arrows -
echo === application/x-parquet ===
curl -H 'Accept: application/x-parquet' -d '{"query":"from test"}' -o out.parquet $ZED_LAKE/query
zq -z out.parquet
for format in parquet vng; do
echo === application/x-$format ===
curl -H "Accept: application/x-$format" -d '{"query":"from test"}' -o out.$format $ZED_LAKE/query
zq -z out.$format
done

inputs:
- name: service.sh
Expand Down Expand Up @@ -60,3 +62,6 @@ outputs:
=== application/x-parquet ===
{a:"hello",b:{c:"world",d:"goodbye"}}
{a:"one",b:{c:"two",d:"three"}}
=== application/x-vng ===
{a:"hello",b:{c:"world",d:"goodbye"}}
{a:"one",b:{c:"two",d:"three"}}