-
Notifications
You must be signed in to change notification settings - Fork 59
Bug Fix: Support array(varchar) results returned as JSON strings #83
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
base: master
Are you sure you want to change the base?
Conversation
Reviewer's GuideEnhanced array handling in the Presto Go client by extending ConvertValue to parse JSON-encoded string arrays, refactoring slice normalization into a new helper, updating NullSliceString.Scan accordingly, bumping a dependency, and adding a CI workflow for integration tests. Class diagram for updated array handling in Presto Go clientclassDiagram
class typeConverter {
+ConvertValue(v interface{}) (driver.Value, error)
}
class NullSliceString {
+SliceString []sql.NullString
+Valid bool
+Scan(value interface{}) error
}
class "normalizeToInterfaceSlice" {
+normalizeToInterfaceSlice(value interface{}) ([]interface{}, error)
}
typeConverter --> "normalizeToInterfaceSlice": uses
NullSliceString --> "normalizeToInterfaceSlice": uses
NullSliceString --> sql.NullString: contains
Class diagram for new normalizeToInterfaceSlice helperclassDiagram
class "normalizeToInterfaceSlice" {
+normalizeToInterfaceSlice(value interface{}) ([]interface{}, error)
}
"normalizeToInterfaceSlice" <.. NullSliceString: used by
"normalizeToInterfaceSlice" <.. typeConverter: used by
Flow diagram for array(varchar) value normalizationflowchart TD
A["Presto REST API returns array(varchar) value"] --> B["typeConverter.ConvertValue receives value"]
B --> C{Is value a string?}
C -- Yes --> D["json.Unmarshal to []interface{}"]
C -- No --> E{Is value []interface{}?}
E -- Yes --> F["Return as-is"]
E -- No --> G["Error: cannot convert to slice"]
D --> H["Return []interface{}"]
F --> H
G --> I["Return error"]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When querying a Presto table with an
array(varchar)column (e.g. from an Iceberg catalog), queries fail with:This happens because the Presto Go client’s
typeConverterassumes thatarray(...)results are always[]interface{}, but in practice the Presto REST API sometimes serializes array values as JSON-encoded strings. The SDK does not handle this case, resulting in runtime errors when scanning results.Repro:
Go code using the SDK:
Result → ❌
cannot convert [...] (string) to slice✅ Fix:
"array"case intypeConverter.ConvertValueto support both[]interface{}andstring(JSON-encoded) inputs.vis astring, attempt tojson.Unmarshalit into a[]interface{}.vis already a[]interface{}, return as-is.🔨 Implementation details:
🧪 Tests:
array(varchar)column (Iceberg catalog).ARRAY[ARRAY['a','b']].[]interface{}instead of JSON strings.