Skip to content

Commit 5d28db8

Browse files
SNOW-1163210 Add tests for Max Lob Size (#1153)
1 parent 5610d92 commit 5d28db8

File tree

2 files changed

+72
-20
lines changed

2 files changed

+72
-20
lines changed

bindings_test.go

+61-20
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,27 @@ const (
3737
insertSQLBulkArrayDateTimeTimestamp = "insert into test_bulk_array_DateTimeTimestamp values(?, ?, ?, ?, ?)"
3838
selectAllSQLBulkArrayDateTimeTimestamp = "select * from test_bulk_array_DateTimeTimestamp ORDER BY 1"
3939

40-
enableFeatureMaxLOBSize = "ALTER SESSION SET FEATURE_INCREASED_MAX_LOB_SIZE_IN_MEMORY='ENABLED'"
41-
unsetFeatureMaxLOBSize = "ALTER SESSION UNSET FEATURE_INCREASED_MAX_LOB_SIZE_IN_MEMORY"
40+
enableFeatureMaxLOBSize = "ALTER SESSION SET FEATURE_INCREASED_MAX_LOB_SIZE_IN_MEMORY='ENABLED'"
41+
unsetFeatureMaxLOBSize = "ALTER SESSION UNSET FEATURE_INCREASED_MAX_LOB_SIZE_IN_MEMORY"
42+
enableLargeVarcharAndBinary = "ALTER SESSION SET ENABLE_LARGE_VARCHAR_AND_BINARY_IN_RESULT=TRUE"
43+
disableLargeVarcharAndBinary = "ALTER SESSION SET ENABLE_LARGE_VARCHAR_AND_BINARY_IN_RESULT=FALSE"
44+
unsetLargeVarcharAndBinary = "ALTER SESSION UNSET ENABLE_LARGE_VARCHAR_AND_BINARY_IN_RESULT"
45+
46+
maxVarcharAndBinarySizeParam = "varchar_and_binary_max_size_in_result"
4247

43-
// For max LOB size tests
44-
// maxLOBSize = 128 * 1024 * 1024 // new max LOB size
45-
maxLOBSize = 16 * 1024 * 1024 // current max LOB size
46-
largeSize = maxLOBSize / 2
47-
mediumSize = largeSize / 2
4848
originSize = 16 * 1024 * 1024
4949
smallSize = 16
5050
// range to use for generating random numbers
5151
lobRandomRange = 100000
5252
)
5353

54+
var (
55+
// maxLOBSize = 128 * 1024 * 1024 // new max LOB size
56+
maxLOBSize = 16 * 1024 * 1024 // current max LOB size
57+
largeSize = maxLOBSize / 2
58+
mediumSize = largeSize / 2
59+
)
60+
5461
func TestBindingFloat64(t *testing.T) {
5562
runDBTest(t, func(dbt *DBTest) {
5663
types := [2]string{"FLOAT", "DOUBLE"}
@@ -220,9 +227,9 @@ func TestBindingTimePtrInStruct(t *testing.T) {
220227
id *int
221228
timeVal *time.Time
222229
}
223-
var expectedID int = 1
224-
var expectedTime time.Time = time.Now()
225-
var testStruct timePtrStruct = timePtrStruct{id: &expectedID, timeVal: &expectedTime}
230+
expectedID := 1
231+
expectedTime := time.Now()
232+
testStruct := timePtrStruct{id: &expectedID, timeVal: &expectedTime}
226233
dbt.mustExec("CREATE OR REPLACE TABLE timeStructTest (id int, tz timestamp_tz)")
227234

228235
runInsertQuery := false
@@ -267,9 +274,9 @@ func TestBindingTimeInStruct(t *testing.T) {
267274
id int
268275
timeVal time.Time
269276
}
270-
var expectedID int = 1
271-
var expectedTime time.Time = time.Now()
272-
var testStruct timeStruct = timeStruct{id: expectedID, timeVal: expectedTime}
277+
expectedID := 1
278+
expectedTime := time.Now()
279+
testStruct := timeStruct{id: expectedID, timeVal: expectedTime}
273280
dbt.mustExec("CREATE OR REPLACE TABLE timeStructTest (id int, tz timestamp_tz)")
274281

275282
runInsertQuery := false
@@ -885,7 +892,7 @@ func TestBulkArrayMultiPartBindingInt(t *testing.T) {
885892
cnt++
886893
}
887894
if cnt != endNum {
888-
t.Fatalf("expected %v rows, got %v", numRows, (cnt - startNum))
895+
t.Fatalf("expected %v rows, got %v", numRows, cnt-startNum)
889896
}
890897
dbt.mustExec("DROP TABLE binding_test")
891898
})
@@ -947,7 +954,7 @@ func TestBulkArrayMultiPartBindingWithNull(t *testing.T) {
947954
cnt++
948955
}
949956
if cnt != endNum {
950-
t.Fatalf("expected %v rows, got %v", numRows, (cnt - startNum))
957+
t.Fatalf("expected %v rows, got %v", numRows, cnt-startNum)
951958
}
952959
dbt.mustExec("DROP TABLE binding_test")
953960
})
@@ -1111,6 +1118,12 @@ func TestVariousBindingModes(t *testing.T) {
11111118
})
11121119
}
11131120

1121+
func skipMaxLobSizeTestOnGithubActions(t *testing.T) {
1122+
if runningOnGithubAction() {
1123+
t.Skip("Max Lob Size parameters are not available on GH Actions")
1124+
}
1125+
}
1126+
11141127
func TestLOBRetrievalWithArrow(t *testing.T) {
11151128
testLOBRetrieval(t, true)
11161129
}
@@ -1120,18 +1133,25 @@ func TestLOBRetrievalWithJSON(t *testing.T) {
11201133
}
11211134

11221135
func testLOBRetrieval(t *testing.T, useArrowFormat bool) {
1123-
// the LOB sizes to be tested
1124-
testSizes := [5]int{smallSize, originSize, mediumSize, largeSize, maxLOBSize}
1125-
var res string
1126-
11271136
runDBTest(t, func(dbt *DBTest) {
1128-
dbt.exec(enableFeatureMaxLOBSize)
1137+
parameters := dbt.connParams()
1138+
varcharBinaryMaxSizeRaw := parameters[maxVarcharAndBinarySizeParam]
1139+
if varcharBinaryMaxSizeRaw != nil && *varcharBinaryMaxSizeRaw != "" {
1140+
varcharBinaryMaxSize, err := strconv.ParseFloat(*varcharBinaryMaxSizeRaw, 64)
1141+
assertNilF(t, err, "error during varcharBinaryMaxSize conversion")
1142+
maxLOBSize = int(varcharBinaryMaxSize)
1143+
}
1144+
1145+
dbt.Logf("using %v as max LOB size", maxLOBSize)
11291146
if useArrowFormat {
11301147
dbt.mustExec(forceARROW)
11311148
} else {
11321149
dbt.mustExec(forceJSON)
11331150
}
11341151

1152+
var res string
1153+
// the LOB sizes to be tested
1154+
testSizes := [5]int{smallSize, originSize, mediumSize, largeSize, maxLOBSize}
11351155
for _, testSize := range testSizes {
11361156
t.Run(fmt.Sprintf("testLOB_%v_useArrowFormat=%v", strconv.Itoa(testSize), strconv.FormatBool(useArrowFormat)), func(t *testing.T) {
11371157
rows, err := dbt.query(fmt.Sprintf("SELECT randstr(%v, 124)", testSize))
@@ -1151,6 +1171,27 @@ func testLOBRetrieval(t *testing.T, useArrowFormat bool) {
11511171
})
11521172
}
11531173

1174+
func TestMaxLobSize(t *testing.T) {
1175+
skipMaxLobSizeTestOnGithubActions(t)
1176+
runDBTest(t, func(dbt *DBTest) {
1177+
dbt.mustExec(enableFeatureMaxLOBSize)
1178+
defer dbt.mustExec(unsetLargeVarcharAndBinary)
1179+
t.Run("Max Lob Size disabled", func(t *testing.T) {
1180+
dbt.mustExec(disableLargeVarcharAndBinary)
1181+
_, err := dbt.query("select randstr(20000000, random())")
1182+
assertNotNilF(t, err)
1183+
assertStringContainsF(t, err.Error(), "Actual length 20000000 exceeds supported length")
1184+
})
1185+
1186+
t.Run("Max Lob Size enabled", func(t *testing.T) {
1187+
dbt.mustExec(enableLargeVarcharAndBinary)
1188+
rows, err := dbt.query("select randstr(20000000, random())")
1189+
assertNilF(t, err)
1190+
rows.Close()
1191+
})
1192+
})
1193+
}
1194+
11541195
func TestInsertLobDataWithLiteralArrow(t *testing.T) {
11551196
// TODO SNOW-1264687
11561197
skipOnJenkins(t, "skipped until SNOW-1264687 is fixed")

driver_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,17 @@ type DBTest struct {
167167
conn *sql.Conn
168168
}
169169

170+
func (dbt *DBTest) connParams() map[string]*string {
171+
var params map[string]*string
172+
err := dbt.conn.Raw(func(driverConn any) error {
173+
conn := driverConn.(*snowflakeConn)
174+
params = conn.cfg.Params
175+
return nil
176+
})
177+
assertNilF(dbt.T, err)
178+
return params
179+
}
180+
170181
func (dbt *DBTest) mustQuery(query string, args ...interface{}) (rows *RowsExtended) {
171182
// handler interrupt signal
172183
ctx, cancel := context.WithCancel(context.Background())

0 commit comments

Comments
 (0)