@@ -727,6 +727,62 @@ func TestIntegrationTypeConversion(t *testing.T) {
727727 }
728728}
729729
730+ func TestComplexTypes (t * testing.T ) {
731+ // This test has been created to showcase some issues with parsing
732+ // complex types. It is not intended to be a comprehensive test of
733+ // the parsing logic, but rather to provide a reference for future
734+ // changes to the parsing logic.
735+ //
736+ // The current implementation of the parsing logic reads the value
737+ // in the same format as the JSON response from Trino. This means
738+ // that we don't go further to parse values as their structured types.
739+ // For example, a row like `ROW(1, X'0000')` is read as
740+ // a list of a `json.Number(1)` and a base64-encoded string.
741+ t .Skip ("skipping failing test" )
742+
743+ dsn := * integrationServerFlag
744+ db := integrationOpen (t , dsn )
745+
746+ for _ , tt := range []struct {
747+ name string
748+ query string
749+ expected interface {}
750+ }{
751+ {
752+ name : "row containing scalar values" ,
753+ query : `SELECT ROW(1, 'a', X'0000')` ,
754+ expected : []interface {}{1 , "a" , []byte {0x00 , 0x00 }},
755+ },
756+ {
757+ name : "nested row" ,
758+ query : `SELECT ROW(ROW(1, 'a'), ROW(2, 'b'))` ,
759+ expected : []interface {}{[]interface {}{1 , "a" }, []interface {}{2 , "b" }},
760+ },
761+ {
762+ name : "map with scalar values" ,
763+ query : `SELECT MAP(ARRAY['a', 'b'], ARRAY[1, 2])` ,
764+ expected : map [string ]interface {}{"a" : 1 , "b" : 2 },
765+ },
766+ {
767+ name : "map with nested row" ,
768+ query : `SELECT MAP(ARRAY['a', 'b'], ARRAY[ROW(1, 'a'), ROW(2, 'b')])` ,
769+ expected : map [string ]interface {}{"a" : []interface {}{1 , "a" }, "b" : []interface {}{2 , "b" }},
770+ },
771+ } {
772+ t .Run (tt .name , func (t * testing.T ) {
773+ var result interface {}
774+ err := db .QueryRow (tt .query ).Scan (& result )
775+ if err != nil {
776+ t .Fatal (err )
777+ }
778+
779+ if ! reflect .DeepEqual (result , tt .expected ) {
780+ t .Errorf ("expected %v, got %v" , tt .expected , result )
781+ }
782+ })
783+ }
784+ }
785+
730786func TestIntegrationArgsConversion (t * testing.T ) {
731787 dsn := * integrationServerFlag
732788 db := integrationOpen (t , dsn )
0 commit comments