bamcis-io/PrestoClient

GetQueryList can fail when Trino was queried with CLI

Opened this issue · 0 comments

When developing #16, I ran across a test failure for TestListQueries which started happening randomly. I updated the test case to log the LastError, and saw this

Stack Trace
System.ArgumentOutOfRangeException: Invalid time zone key 1890. (Parameter 'key')
   at BAMCIS.PrestoClient.Model.SPI.Type.TimeZoneKey.GetTimeZoneKey(Int16 key) in /app/PrestoClient/Model/SPI/Type/TimeZoneKey.cs:line 63
   at BAMCIS.PrestoClient.Serialization.TimeZoneKeyConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer) in /app/PrestoClient/Serialization/TimeZoneKeyConverter.cs:line 37
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ResolvePropertyAndCreatorValues(JsonObjectContract contract, JsonProperty containerProperty, JsonReader reader, Type objectType)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObjectUsingCreatorWithParameters(JsonReader reader, JsonObjectContract contract, JsonProperty containerProperty, ObjectConstructor`1 creator, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value)
   at BAMCIS.PrestoClient.Model.Query.ListQueriesV1Response..ctor(String rawContent) in /app/PrestoClient/Model/Query/ListQueriesV1Response.cs:line 53

When I compared the library's TimeZoneKey with upstream Trino to rule out any API changes, I noticed upstream supports nearly all timezones whereas we only expect UTC

And the 1890 value refers to Toronto time (in zone-index.properties), which likely got entered into the Trino query history when I used the Trino CLI to troubleshoot mid development.

In real world use cases, it is highly likely for multiple downstream clients (including Trino CLI) to connect to Trino server, and leave behind timestamps that are non UTC in the queries table. It would be nice if we could upgrade the library to handle non UTC timezones in the GetQueries command.