Repository: snowflakedb/gosnowflake
Pull request #1187 (2024-07-30 20:48:47)

Fix null in structured types arrays regression
### Description

Undone some refactoring that caused a regression

### Checklist
- [ ] Created tests which fail without the change (if possible)
- [ ] Extended the README / documentation, if necessary


codecov[bot]: ## [Codecov](https://app.codecov.io/gh/snowflakedb/gosnowflake/pull/1187?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=snowflakedb) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 82.55%. Comparing base [(`2e40d2e`)](https://app.codecov.io/gh/snowflakedb/gosnowflake/commit/2e40d2ed2dc96f73aed2396b416282dacd86cac4?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=snowflakedb) to head [(`e229316`)](https://app.codecov.io/gh/snowflakedb/gosnowflake/commit/e229316807033b94b4ed34a30b8d8820cc7e182d?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=snowflakedb).
> Report is 1 commits behind head on master.

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##           master    #1187      +/-   ##
==========================================
+ Coverage   82.54%   82.55%   +0.01%     
==========================================
  Files          54       54              
  Lines       12815    12823       +8     
==========================================
+ Hits        10578    10586       +8     
  Misses       2237     2237              
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/snowflakedb/gosnowflake/pull/1187?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=snowflakedb).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=snowflakedb).


Patch:
diff --git a/structured_type.go b/structured_type.go
index 17b7b91..7fdf174 100644
--- a/structured_type.go
+++ b/structured_type.go
@@ -1150,8 +1150,8 @@ func (st *structuredType) fieldMetadataByFieldName(fieldName string) (fieldMetad
 	return fieldMetadata{}, errors.New("no metadata for field " + fieldName)
 }
 
-func optionEnabled(ctx context.Context, option contextKey) bool {
-	v := ctx.Value(option)
+func structuredTypesEnabled(ctx context.Context) bool {
+	v := ctx.Value(enableStructuredTypes)
 	if v == nil {
 		return false
 	}
@@ -1159,16 +1159,22 @@ func optionEnabled(ctx context.Context, option contextKey) bool {
 	return ok && d
 }
 
-func structuredTypesEnabled(ctx context.Context) bool {
-	return optionEnabled(ctx, enableStructuredTypes)
-}
-
 func mapValuesNullableEnabled(ctx context.Context) bool {
-	return optionEnabled(ctx, mapValuesNullable)
+	v := ctx.Value(mapValuesNullable)
+	if v == nil {
+		return false
+	}
+	d, ok := v.(bool)
+	return ok && d
 }
 
 func arrayValuesNullableEnabled(ctx context.Context) bool {
-	return optionEnabled(ctx, arrayValuesNullable)
+	v := ctx.Value(arrayValuesNullable)
+	if v == nil {
+		return false
+	}
+	d, ok := v.(bool)
+	return ok && d
 }
 
 func getSfFieldName(field reflect.StructField) string {


Test patch:
diff --git a/structured_type_read_test.go b/structured_type_read_test.go
index 906ff24..1d49119 100644
--- a/structured_type_read_test.go
+++ b/structured_type_read_test.go
@@ -1757,7 +1757,6 @@ func TestArraysWithNullValues(t *testing.T) {
 				} else {
 					assertDeepEqualE(t, tc.actual, tc.expected)
 				}
-				fmt.Printf("%v", reflect.TypeOf(tc.actual))
 			})
 		}
 	})