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

Fix v2 show if result is empty #30

Merged
merged 8 commits into from
Aug 19, 2022
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## v0.3.1-alpha
* Fix v2 show result if empty result.

## v0.3.0-alpha
* Deprecated metadata json format.
* Removed `TransactionAsyncMetadataResponse` model.
Expand Down
17 changes: 9 additions & 8 deletions rai/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ func unmarshal(rsp *http.Response, result interface{}) error {
switch data.(type) {

case []byte: // Got back a JSON response

if dstValues.Type() == reflect.TypeOf(TransactionAsyncResult{}) {
// But the user asked for the whole TransactionResult struct,
// so we need to parse the JSON TransactionResponse, and fill it in
Expand Down Expand Up @@ -311,24 +310,30 @@ func unmarshal(rsp *http.Response, result interface{}) error {
case []TransactionAsyncFile: // Multipart response
if dstValues.Type() == reflect.TypeOf(TransactionAsyncResult{}) {
rsp, err := readTransactionAsyncFiles(data.([]TransactionAsyncFile))
if err != nil {
return err
}
rsp.GotCompleteResult = true
srcValues := reflect.ValueOf(*rsp)
dstValues.Set(srcValues)
return err
return nil
}

if dstValues.Type() == reflect.TypeOf([]ArrowRelation{}) {
rsp, err := readArrowFiles(data.([]TransactionAsyncFile))
if err != nil {
return err
}
srcValues := reflect.ValueOf(rsp)
dstValues.Set(srcValues)
return err
return nil
}

return errors.Errorf("unhandled unmarshal type %T", result)
case generated.MetadataInfo:
srcValues := reflect.ValueOf(data)
dstValues.Set(srcValues)
return err
return nil
default:
return errors.Errorf("unsupported result type %T", reflect.TypeOf(data))
}
Expand Down Expand Up @@ -514,10 +519,6 @@ func readTransactionAsyncFiles(files []TransactionAsyncFile) (*TransactionAsyncR
return nil, errors.Errorf("transaction part is missing")
}

if len(metadata.Relations) == 0 {
return nil, errors.Errorf("metadata.proto is empty")
}

if problems == nil {
return nil, errors.Errorf("problems part is missing")
}
Expand Down
4 changes: 2 additions & 2 deletions rai/metadata.pb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
>
3
"

�output

�output



Expand Down
4 changes: 2 additions & 2 deletions rai/metadata.pb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ relations {
constant_type {
rel_type {
tag: PRIMITIVE_TYPE
primitive_type: SYMBOL
primitive_type: STRING
}
value {
arguments {
tag: SYMBOL
tag: STRING
string_val: "output"
}
}
Expand Down
6 changes: 6 additions & 0 deletions rai/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ func (tx *TransactionAsyncResult) ShowIO(io io.Writer) {
k := r.RelationID
v := r.Table
fmt.Fprintf(io, "%s\n", k)

if len(v) == 0 {
fmt.Fprintln(io, "()")
continue
}

iter := zip(v...)
for tuple := iter(); tuple != nil; tuple = iter() {
for i, element := range tuple {
Expand Down