worryg0d commented on code in PR #1942:
URL:
https://github.com/apache/cassandra-gocql-driver/pull/1942#discussion_r3091569689
##########
integration_test.go:
##########
@@ -977,3 +978,52 @@ func TestSliceMapMapScanCollectionTypes(t *testing.T) {
})
}
}
+
+func TestUDT_EncodeNilMap(t *testing.T) {
+ session := createSession(t)
+ defer session.Close()
+
+ err := createTable(session, `CREATE TYPE IF NOT EXISTS
gocql_test.encode_nil_map_udt (
+ field_a text,
+ field_b int
+ );`)
+ require.NoError(t, err)
+
+ err = createTable(session, `CREATE TABLE IF NOT EXISTS
gocql_test.encode_nil_map_udt_table (
+ id int PRIMARY KEY,
+ value frozen<encode_nil_map_udt>
+ );`)
+ require.NoError(t, err)
+ session.Close()
+
+ insertNilMapAndScan := func(t *testing.T, session *Session, recordID
int) map[string]interface{} {
+ t.Helper()
+ nilMap := map[string]interface{}(nil)
+ err = session.Query("INSERT INTO encode_nil_map_udt_table (id,
value) VALUES (?, ?)", recordID, nilMap).Exec()
+ require.NoError(t, err)
+ var scanned map[string]interface{}
+ err = session.Query("SELECT value FROM encode_nil_map_udt_table
WHERE id = ?", recordID).ScanContext(context.Background(), &scanned)
+ require.NoError(t, err)
+ return scanned
+ }
+
+ t.Run("encode nil map as initialized UDT with null values", func(t
*testing.T) {
+ session := createSession(t, func(config *ClusterConfig) {
+ config.Encoding.EncodeNilMapAsInitilizedUDT = true
+ config.Logger = NewLogger(LogLevelInfo)
+ })
+ defer session.Close()
+ scanned := insertNilMapAndScan(t, session, 1)
+ expected := map[string]interface{}{"field_a": "", "field_b": 0}
Review Comment:
Actually, it is supposed to return a scan of a map with nil fields instead
of zero-valued fields, isn't it?
So we should expect having nil pointers of *string and *int types:
```go
var fieldA *string = nil
var fieldB *int = nil
expected := map[string]interface{}{"field_a": fieldA, "field_b": fieldB}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]