Skip to content

fix(queryjson): rename SessionPropertiesJSON, fix stage ID dot-prefix handling and queryPlan key#96

Draft
Copilot wants to merge 3 commits into
mainfrom
copilot/rename-sessionpropertiesjson-field
Draft

fix(queryjson): rename SessionPropertiesJSON, fix stage ID dot-prefix handling and queryPlan key#96
Copilot wants to merge 3 commits into
mainfrom
copilot/rename-sessionpropertiesjson-field

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 13, 2026

Four correctness and style fixes in the queryjson package.

Changes

  • session.go — Rename SessionPropertiesJsonSessionPropertiesJSON per Go initialism conventions; update PrepareForInsert comment to document the wire format, include a concrete example, and note that pairs are sorted alphabetically for deterministic output.

  • stage_info.go — Fix index > 0index >= 0 in processForInsert so stage IDs with a leading dot (e.g. .3) are stripped correctly instead of being left as-is. Replace strconv.Itoa(len(queryPlan)) with s.StageId as the queryPlan map key, preventing silent overwrites when stages are processed out of order or the map is pre-populated. Removes now-unused strconv import.

Example: queryPlan key fix

Before, with three stages processed in sequence:

// Keys: "0", "1", "2" — positional, not tied to stage identity
queryPlan[strconv.Itoa(len(queryPlan))] = RawPlanWrapper{...}

After:

// Keys match actual stage IDs (e.g. "0", "1", "2" from stripped StageId)
queryPlan[s.StageId] = RawPlanWrapper{...}
Original prompt
Please apply the following diffs and create a pull request.
Once the PR is ready, give it a title based on the messages of the fixes being applied.

[{"message":"The field name 'SessionPropertiesJson' does not follow Go naming conventions. 'JSON' is an initialism and should be fully capitalized. Rename to 'SessionPropertiesJSON' for consistency with Go style guidelines.","fixFiles":[{"filePath":"queryjson/session.go","diff":"diff --git a/queryjson/session.go b/queryjson/session.go\n--- a/queryjson/session.go\n+++ b/queryjson/session.go\n@@ -21,7 +21,7 @@\n \tUserAgent         *string                      `json:\"userAgent,omitempty\" presto_query_creation_info:\"user_agent\" presto_query_statistics:\"user_agent\"`\n \tClientTags        *json.RawMessage             `json:\"clientTags,omitempty\" presto_query_creation_info:\"client_tags\" presto_query_statistics:\"client_tags\"`\n \n-\tSessionPropertiesJson string `presto_query_creation_info:\"session_properties_json\" presto_query_statistics:\"session_properties_json\"`\n+\tSessionPropertiesJSON string `presto_query_creation_info:\"session_properties_json\" presto_query_statistics:\"session_properties_json\"`\n }\n \n // PrepareForInsert formats session properties into a {key=value, ...} string for database\n"}]},{"message":"The comment on line 28 states this uses 'Presto session properties wire format (not standard JSON)', but the format `{key=value, ...}` is not clearly documented. Consider adding an example in the comment to clarify the exact output format, especially regarding escaping or special characters in keys/values.","fixFiles":[{"filePath":"queryjson/session.go","diff":"diff --git a/queryjson/session.go b/queryjson/session.go\n--- a/queryjson/session.go\n+++ b/queryjson/session.go\n@@ -25,7 +25,10 @@\n }\n \n // PrepareForInsert formats session properties into a {key=value, ...} string for database\n-// insertion. This uses the Presto session properties wire format (not standard JSON).\n+// insertion. This uses the Presto session properties wire format (not standard JSON), for\n+// example: {join_distribution_type=AUTOMATIC, hive.optimize_index_filtering=TRUE}. Keys and\n+// values are concatenated as-is (no additional escaping), and pairs are joined with \", \" and\n+// wrapped in curly braces.\n func (s *Session) PrepareForInsert() {\n \tif s == nil {\n \t\treturn\n"}]},{"message":"The condition `index > 0` should be `index >= 0` to handle stage IDs that start with a dot (e.g., '.3'). Currently, if the dot is at position 0, the stage ID won't be processed correctly.","fixFiles":[{"filePath":"queryjson/stage_info.go","diff":"diff --git a/queryjson/stage_info.go b/queryjson/stage_info.go\n--- a/queryjson/stage_info.go\n+++ b/queryjson/stage_info.go\n@@ -65,7 +65,7 @@\n //  5. Add this stage's plan to the assembled query plan map\n func (s *StageInfo) processForInsert(flattened *[]*StageInfo, queryPlan map[string]RawPlanWrapper) error {\n \t// Stage IDs are formatted as \"queryId.index\"; we only keep the index for the database.\n-\tif index := strings.IndexByte(s.StageId, '.'); index > 0 && index+1 < len(s.StageId) {\n+\tif index := strings.IndexByte(s.StageId, '.'); index >= 0 && index+1 < len(s.StageId) {\n \t\ts.StageId = s.StageId[index+1:]\n \t}\n \t// Trino exposes stats directly on StageInfo as \"stageStats\", while Presto nests them\n"}]},{"message":"Using `len(queryPlan)` as a key may lead to unexpected behavior if stages are processed out of order or if the map already contains entries. Consider using the stage ID as the key instead to ensure consistency and prevent potential overwrites.","fixFiles":[{"filePath":"queryjson/stage_info.go","diff":"diff --git a/queryjson/stage_info.go b/queryjson/stage_info.go\n--- a/queryjson/stage_info.go\n+++ b/queryjson/stage_info.go\n@@ -84,7 +84,7 @@\n \t*flattened = append(*flattened, s)\n \n \tif s.Plan != nil {\n-\t\tqueryPlan[strconv.Itoa(len(queryPlan))] = RawPlanWrapper{\n+\t\tqueryPlan[s.StageId] = RawPlanWrapper{\n \t\t\tPlan: json.RawMessage(s.Plan.JsonRepresentation),\n \t\t}\n \t}\n"}]}]

@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented Apr 13, 2026

CLA Not Signed

Copilot AI and others added 2 commits April 13, 2026 19:52
… ID index check and queryPlan key, update comment

Agent-Logs-Url: https://github.com/prestodb/presto-go-client/sessions/b9114e1f-e984-4290-9ca7-cf9512555efc

Co-authored-by: ethanyzhang <6643318+ethanyzhang@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix field name to follow Go naming conventions fix(queryjson): rename SessionPropertiesJSON, fix stage ID dot-prefix handling and queryPlan key Apr 13, 2026
Copilot AI requested a review from ethanyzhang April 13, 2026 19:54
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