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

chore: refactor serialization in query service #4234

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

worstell
Copy link
Contributor

No description provided.

@worstell worstell requested review from a team and alecthomas as code owners January 30, 2025 00:32
@alecthomas alecthomas mentioned this pull request Jan 30, 2025
@wesbillman wesbillman requested a review from Copilot January 30, 2025 16:44
Copy link
Collaborator

@wesbillman wesbillman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice little cleanup here!

Comment on lines +282 to +289
case float64:
v.SetBool(n != 0)
case int64:
v.SetBool(n != 0)
case bool:
v.SetBool(n)
case string:
v.SetBool(n == "true")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reminds me of javascript bool 😂

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 6 out of 10 changed files in this pull request and generated 3 comments.

Files not reviewed (4)
  • frontend/console/src/protos/xyz/block/ftl/query/v1/query_pb.ts: Evaluated as low risk
  • go-runtime/ftl/option.go: Evaluated as low risk
  • python-runtime/ftl/src/ftl/protos/xyz/block/ftl/query/v1/query_pb2.py: Evaluated as low risk
  • python-runtime/ftl/src/ftl/protos/xyz/block/ftl/query/v1/query_pb2.pyi: Evaluated as low risk
Comments suppressed due to low confidence (4)

backend/runner/query/service.go:342

  • [nitpick] The parseTimeString function is called for every string parameter, which might not always be a time string. This could lead to unexpected behavior. Consider adding a more robust check or handling for time strings.
if str, ok := param.(string); ok {

backend/protos/xyz/block/ftl/query/v1/query.proto:40

  • Ensure that there are test cases covering the parsing of the new 'parameters_json' field to verify that it correctly handles various data types and formats.
string parameters_json = 3; // JSON array of parameter values in order

backend/protos/xyz/block/ftl/query/v1/query.proto:61

  • Ensure that there are test cases covering the handling of the new 'json_rows' field to verify that it correctly maps column names to values and handles various data types.
string json_rows = 1; // JSON object mapping column names to values

backend/runner/query/client.go:60

  • Ensure that the params variable is correctly marshaled to JSON and that the resulting JSON string is not empty.
paramsJSON, err := encoding.Marshal(params)

for i, col := range resultColumns {
structFields[i] = reflect.StructField{
Name: col.TypeName,
Type: reflect.TypeFor[any](),
Copy link
Preview

Copilot AI Jan 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function reflect.TypeForany is not valid. It should be reflect.TypeOf(new(any)).Elem().

Suggested change
Type: reflect.TypeFor[any](),
Type: reflect.TypeOf(new(any)).Elem(),

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
@@ -443,11 +478,16 @@ func getDriverName(engine string) string {
}

func handleNoRows(stream *connect.ServerStream[querypb.ExecuteQueryResponse]) error {
err := stream.Send(&querypb.ExecuteQueryResponse{
emptyJSON, err := encoding.Marshal(make(map[string]any))
Copy link
Preview

Copilot AI Jan 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Using encoding.Marshal to create an empty JSON object is unnecessary. Consider using a simpler approach like '{}'.

Suggested change
emptyJSON, err := encoding.Marshal(make(map[string]any))
emptyJSON := "{}"

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
for stream.Receive() {
resp := stream.Msg()
switch r := resp.Result.(type) {
case *querypb.ExecuteQueryResponse_ExecResult:
return nil, nil
case *querypb.ExecuteQueryResponse_RowResults:
if len(r.RowResults.Rows) == 0 {
if r.RowResults.JsonRows == "" {
Copy link
Preview

Copilot AI Jan 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty JSON strings should be treated as empty result sets. Consider handling empty JSON strings properly.

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants