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

refactor: move the json.Marshal into BuildJSON makes it easier to use #52

Merged
merged 1 commit into from
Nov 13, 2024
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
7 changes: 1 addition & 6 deletions examples/jsondata/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package main

import (
"context"
"encoding/json"
"log"
"time"

Expand Down Expand Up @@ -88,10 +87,6 @@ func initData() ([]*table.Table, error) {
IsStudent: false,
Courses: []string{"math", "history", "chemistry"},
}
jsonData, err := json.Marshal(p)
if err != nil {
return nil, err
}

// add column at first. This is to define the schema of the table.
if err := itbl.AddFieldColumn("my_json", types.JSON); err != nil {
Expand All @@ -100,7 +95,7 @@ func initData() ([]*table.Table, error) {
if err := itbl.AddTimestampColumn("timestamp", types.TIMESTAMP_MICROSECOND); err != nil {
return nil, err
}
if err := itbl.AddRow(string(jsonData), time1); err != nil {
if err := itbl.AddRow(p, time1); err != nil {
return nil, err
}

Expand Down
7 changes: 6 additions & 1 deletion table/cell/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package cell

import (
"encoding/json"
"fmt"
"time"

Expand Down Expand Up @@ -499,7 +500,11 @@ func BuildJSON(v any) (*gpb.Value, error) {
case *string:
val = *t
default:
return nil, fmt.Errorf(formatter+"string", t, v)
jsonData, err := json.Marshal(v)
if err != nil {
return nil, err
}
val = string(jsonData)
}

return &gpb.Value{ValueData: &gpb.Value_StringValue{StringValue: val}}, nil
Expand Down
Loading