Skip to content

Commit

Permalink
SNOW-859548 Do not drop test tables
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-pfus committed Jul 25, 2023
1 parent f734fc8 commit 3ec3a78
Show file tree
Hide file tree
Showing 12 changed files with 9 additions and 65 deletions.
6 changes: 2 additions & 4 deletions arrow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,7 @@ func TestArrowFloatPrecision(t *testing.T) {

func TestArrowTimePrecision(t *testing.T) {
runTests(t, dsn, func(dbt *DBTest) {
dbt.mustExec("CREATE TABLE t (col5 TIME(5), col6 TIME(6), col7 TIME(7), col8 TIME(8));")
defer dbt.mustExec("DROP TABLE IF EXISTS t")
dbt.mustExec("CREATE OR REPLACE TABLE t (col5 TIME(5), col6 TIME(6), col7 TIME(7), col8 TIME(8));")
dbt.mustExec("INSERT INTO t VALUES ('23:59:59.99999', '23:59:59.999999', '23:59:59.9999999', '23:59:59.99999999');")

rows := dbt.mustQuery("select * from t")
Expand All @@ -377,7 +376,7 @@ func TestArrowTimePrecision(t *testing.T) {
t.Errorf("the value did not match. expected: %v, got: %v", expected, c5)
}

dbt.mustExec(`CREATE TABLE t_ntz (
dbt.mustExec(`CREATE OR REPLACE TABLE t_ntz (
col1 TIMESTAMP_NTZ(1),
col2 TIMESTAMP_NTZ(2),
col3 TIMESTAMP_NTZ(3),
Expand All @@ -387,7 +386,6 @@ func TestArrowTimePrecision(t *testing.T) {
col7 TIMESTAMP_NTZ(7),
col8 TIMESTAMP_NTZ(8)
);`)
defer dbt.mustExec("DROP TABLE IF EXISTS t_ntz")
dbt.mustExec(`INSERT INTO t_ntz VALUES (
'9999-12-31T23:59:59.9',
'9999-12-31T23:59:59.99',
Expand Down
2 changes: 0 additions & 2 deletions async_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,8 @@ func TestAsyncModeMultiStatement(t *testing.T) {
"rollback;"

runTests(t, dsn, func(dbt *DBTest) {
dbt.mustExec("drop table if exists test_multi_statement_async")
dbt.mustExec(`create or replace table test_multi_statement_async(
c1 number, c2 string) as select 10, 'z'`)
defer dbt.mustExec("drop table if exists test_multi_statement_async")

res := dbt.mustExecContext(ctx, multiStmtQuery)
count, err := res.RowsAffected()
Expand Down
31 changes: 7 additions & 24 deletions bindings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,18 @@ const (
createTableSQL = `create or replace table test_prep_statement(c1 INTEGER,
c2 FLOAT, c3 BOOLEAN, c4 STRING, C5 BINARY, C6 TIMESTAMP_NTZ,
C7 TIMESTAMP_LTZ, C8 TIMESTAMP_TZ, C9 DATE, C10 TIME)`
deleteTableSQL = "drop table if exists TEST_PREP_STATEMENT"
insertSQL = "insert into TEST_PREP_STATEMENT values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
selectAllSQL = "select * from TEST_PREP_STATEMENT ORDER BY 1"
insertSQL = "insert into TEST_PREP_STATEMENT values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
selectAllSQL = "select * from TEST_PREP_STATEMENT ORDER BY 1"

createTableSQLBulkArray = `create or replace table test_bulk_array(c1 INTEGER,
c2 FLOAT, c3 BOOLEAN, c4 STRING, C5 BINARY)`
deleteTableSQLBulkArray = "drop table if exists test_bulk_array"
insertSQLBulkArray = "insert into test_bulk_array values(?, ?, ?, ?, ?)"
selectAllSQLBulkArray = "select * from test_bulk_array ORDER BY 1"
insertSQLBulkArray = "insert into test_bulk_array values(?, ?, ?, ?, ?)"
selectAllSQLBulkArray = "select * from test_bulk_array ORDER BY 1"

createTableSQLBulkArrayDateTimeTimestamp = `create or replace table test_bulk_array_DateTimeTimestamp(
C1 TIMESTAMP_NTZ, C2 TIMESTAMP_LTZ, C3 TIMESTAMP_TZ, C4 DATE, C5 TIME)`
deleteTableSQLBulkArrayDateTimeTimestamp = "drop table if exists test_bulk_array_DateTimeTimestamp"
insertSQLBulkArrayDateTimeTimestamp = "insert into test_bulk_array_DateTimeTimestamp values(?, ?, ?, ?, ?)"
selectAllSQLBulkArrayDateTimeTimestamp = "select * from test_bulk_array_DateTimeTimestamp ORDER BY 1"
insertSQLBulkArrayDateTimeTimestamp = "insert into test_bulk_array_DateTimeTimestamp values(?, ?, ?, ?, ?)"
selectAllSQLBulkArrayDateTimeTimestamp = "select * from test_bulk_array_DateTimeTimestamp ORDER BY 1"
)

func TestBindingFloat64(t *testing.T) {
Expand All @@ -55,7 +52,6 @@ func TestBindingFloat64(t *testing.T) {
} else {
dbt.Errorf("%s: no data", v)
}
dbt.mustExec("DROP TABLE IF EXISTS test")
}
})
}
Expand All @@ -73,7 +69,6 @@ func TestBindingUint64(t *testing.T) {
} else {
logger.Infof("expected err: %v", err)
}
dbt.mustExec("DROP TABLE IF EXISTS test")
}
})
}
Expand Down Expand Up @@ -143,7 +138,6 @@ func TestBindingDateTimeTimestamp(t *testing.T) {
} else {
dbt.Error("no data")
}
dbt.mustExec("DROP TABLE tztest")
})

createDSN("UTC")
Expand All @@ -167,7 +161,6 @@ func TestBindingBinary(t *testing.T) {
} else {
dbt.Errorf("no data")
}
dbt.mustExec("DROP TABLE bintest")
})
}

Expand Down Expand Up @@ -195,7 +188,6 @@ func TestBindingTimestampTZ(t *testing.T) {
} else {
dbt.Error("no data")
}
dbt.mustExec("DROP TABLE tztest")
})
}

Expand Down Expand Up @@ -242,7 +234,6 @@ func TestBindingTimePtrInStruct(t *testing.T) {
dbt.Error("no data")
}
}
dbt.mustExec("DROP TABLE timeStructTest")
})
}

Expand Down Expand Up @@ -289,7 +280,6 @@ func TestBindingTimeInStruct(t *testing.T) {
dbt.Error("no data")
}
}
dbt.mustExec("DROP TABLE timeStructTest")
})
}

Expand Down Expand Up @@ -352,7 +342,6 @@ func TestBulkArrayBindingInterfaceNil(t *testing.T) {

runTests(t, dsn, func(dbt *DBTest) {
dbt.mustExec(createTableSQL)
defer dbt.mustExec(deleteTableSQL)

dbt.mustExec(insertSQL, Array(&nilArray), Array(&nilArray),
Array(&nilArray), Array(&nilArray), Array(&nilArray),
Expand Down Expand Up @@ -434,7 +423,6 @@ func TestBulkArrayBindingInterface(t *testing.T) {

runTests(t, dsn, func(dbt *DBTest) {
dbt.mustExec(createTableSQLBulkArray)
defer dbt.mustExec(deleteTableSQLBulkArray)

dbt.mustExec(insertSQLBulkArray, Array(&intArray), Array(&fltArray),
Array(&boolArray), Array(&strArray), Array(&byteArray))
Expand Down Expand Up @@ -526,7 +514,6 @@ func TestBulkArrayBindingInterfaceDateTimeTimestamp(t *testing.T) {

runTests(t, dsn, func(dbt *DBTest) {
dbt.mustExec(createTableSQLBulkArrayDateTimeTimestamp)
defer dbt.mustExec(deleteTableSQLBulkArrayDateTimeTimestamp)

dbt.mustExec(insertSQLBulkArrayDateTimeTimestamp,
Array(&ntzArray, TimestampNTZType), Array(&ltzArray, TimestampLTZType),
Expand Down Expand Up @@ -628,7 +615,6 @@ func testBindingArray(t *testing.T, bulk bool) {

runTests(t, dsn, func(dbt *DBTest) {
dbt.mustExec(createTableSQL)
defer dbt.mustExec(deleteTableSQL)
if bulk {
if _, err := dbt.exec("ALTER SESSION SET CLIENT_STAGE_ARRAY_BINDING_THRESHOLD = 1"); err != nil {
t.Error(err)
Expand Down Expand Up @@ -740,8 +726,7 @@ func TestBulkArrayMultiPartBinding(t *testing.T) {
ctx := context.Background()

runTests(t, dsn, func(dbt *DBTest) {
dbt.mustExec(fmt.Sprintf("CREATE TABLE %s (C VARCHAR(64) NOT NULL)", tempTableName))
defer dbt.mustExec("drop table " + tempTableName)
dbt.mustExec(fmt.Sprintf("CREATE OR REPLACE TABLE %s (C VARCHAR(64) NOT NULL)", tempTableName))

for i := 0; i < randomIter; i++ {
dbt.mustExecContext(ctx,
Expand Down Expand Up @@ -802,7 +787,6 @@ func TestBulkArrayMultiPartBindingInt(t *testing.T) {
if cnt != endNum {
t.Fatalf("expected %v rows, got %v", numRows, (cnt - startNum))
}
dbt.mustExec("DROP TABLE binding_test")
})
}

Expand Down Expand Up @@ -864,7 +848,6 @@ func TestBulkArrayMultiPartBindingWithNull(t *testing.T) {
if cnt != endNum {
t.Fatalf("expected %v rows, got %v", numRows, (cnt - startNum))
}
dbt.mustExec("DROP TABLE binding_test")
})
}

Expand Down
1 change: 0 additions & 1 deletion cmd/filestransfer/filestransfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ func main() {
if err != nil {
log.Fatalf("error while creating table; err: %v", err)
}
defer db.Exec("DROP TABLE IF EXISTS GOSNOWFLAKE_FILES_TRANSFER_EXAMPLE;")

//Uploading data_to_upload.csv to internal stage for table GOSNOWFLAKE_FILES_TRANSFER_EXAMPLE
tmpFilePath := createTmpFile(customFormatCsvDataToUpload)
Expand Down
5 changes: 0 additions & 5 deletions driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,8 +579,6 @@ func testInt(t *testing.T, json bool) {
} else {
dbt.Errorf("%s: no data", v)
}

dbt.mustExec("DROP TABLE IF EXISTS test")
}
})
}
Expand Down Expand Up @@ -614,7 +612,6 @@ func testFloat32(t *testing.T, json bool) {
} else {
dbt.Errorf("%s: no data", v)
}
dbt.mustExec("DROP TABLE IF EXISTS test")
}
})
}
Expand Down Expand Up @@ -645,7 +642,6 @@ func testFloat64(t *testing.T, json bool) {
} else {
dbt.Errorf("%s: no data", v)
}
dbt.mustExec("DROP TABLE IF EXISTS test")
}
})
}
Expand Down Expand Up @@ -678,7 +674,6 @@ func testString(t *testing.T, json bool) {
} else {
dbt.Errorf("%s: no data", v)
}
dbt.mustExec("DROP TABLE IF EXISTS test")
}

// BLOB (Snowflake doesn't support BLOB type but STRING covers large text data)
Expand Down
11 changes: 0 additions & 11 deletions multistatement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ func TestMultiStatementExecuteNoResultSet(t *testing.T) {
"commit;"

runTests(t, dsn, func(dbt *DBTest) {
dbt.mustExec("drop table if exists test_multi_statement_txn")
dbt.mustExec(`create or replace table test_multi_statement_txn(
c1 number, c2 string) as select 10, 'z'`)
defer dbt.mustExec("drop table if exists test_multi_statement_txn")

res := dbt.mustExecContext(ctx, multiStmtQuery)
count, err := res.RowsAffected()
Expand Down Expand Up @@ -121,10 +119,8 @@ func TestMultiStatementExecuteResultSet(t *testing.T) {
"rollback;"

runTests(t, dsn, func(dbt *DBTest) {
dbt.mustExec("drop table if exists test_multi_statement_txn_rb")
dbt.mustExec(`create or replace table test_multi_statement_txn_rb(
c1 number, c2 string) as select 10, 'z'`)
defer dbt.mustExec("drop table if exists test_multi_statement_txn_rb")

res := dbt.mustExecContext(ctx, multiStmtQuery)
count, err := res.RowsAffected()
Expand All @@ -145,10 +141,8 @@ func TestMultiStatementQueryNoResultSet(t *testing.T) {
"commit;"

runTests(t, dsn, func(dbt *DBTest) {
dbt.mustExec("drop table if exists test_multi_statement_txn")
dbt.mustExec(`create or replace table test_multi_statement_txn(
c1 number, c2 string) as select 10, 'z'`)
defer dbt.mustExec("drop table if exists tfmuest_multi_statement_txn")

rows := dbt.mustQueryContext(ctx, multiStmtQuery)
defer rows.Close()
Expand All @@ -162,10 +156,8 @@ func TestMultiStatementExecuteMix(t *testing.T) {
"select cola from test_multi order by cola asc;"

runTests(t, dsn, func(dbt *DBTest) {
dbt.mustExec("drop table if exists test_multi_statement_txn")
dbt.mustExec(`create or replace table test_multi_statement_txn(
c1 number, c2 string) as select 10, 'z'`)
defer dbt.mustExec("drop table if exists test_multi_statement_txn")

res := dbt.mustExecContext(ctx, multiStmtQuery)
count, err := res.RowsAffected()
Expand All @@ -186,10 +178,8 @@ func TestMultiStatementQueryMix(t *testing.T) {

var count, v int
runTests(t, dsn, func(dbt *DBTest) {
dbt.mustExec("drop table if exists test_multi_statement_txn")
dbt.mustExec(`create or replace table test_multi_statement_txn(
c1 number, c2 string) as select 10, 'z'`)
defer dbt.mustExec("drop table if exists test_multi_statement_txn")

rows := dbt.mustQueryContext(ctx, multiStmtQuery)
defer rows.Close()
Expand Down Expand Up @@ -355,7 +345,6 @@ func TestMultiStatementVaryingColumnCount(t *testing.T) {
runTests(t, dsn, func(dbt *DBTest) {
dbt.mustExec("create or replace table test_tbl(c1 int, c2 int)")
dbt.mustExec("insert into test_tbl values(1, 0)")
defer dbt.mustExec("drop table if exists test_tbl")

rows := dbt.mustQueryContext(ctx, multiStmtQuery)
defer rows.Close()
Expand Down
1 change: 0 additions & 1 deletion prepared_statement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
func TestPreparedStatement(t *testing.T) {
runTests(t, dsn, func(dbt *DBTest) {
dbt.mustExec("create or replace table test_prep_statement(c1 INTEGER, c2 FLOAT, c3 BOOLEAN, c4 STRING)")
defer dbt.mustExec(deleteTableSQL)

intArray := []int{1, 2, 3}
fltArray := []float64{0.1, 2.34, 5.678}
Expand Down
3 changes: 0 additions & 3 deletions put_get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ func TestPutLocalFile(t *testing.T) {
data.awsAccessKeyID,
data.awsSecretAccessKey)
dbt.mustExec(execQuery)
defer dbt.mustExec("drop table if exists gotest_putget_t1")

execQuery = fmt.Sprintf(`put file://%v/test_data/orders_10*.csv
@%%gotest_putget_t1`, data.dir)
Expand Down Expand Up @@ -404,7 +403,6 @@ func testPutGet(t *testing.T, isStream bool) {
t.Error(err)
}
defer func() {
defer dbt.mustExec("drop table " + tableName)
if fileStream != nil {
fileStream.Close()
}
Expand Down Expand Up @@ -530,7 +528,6 @@ func TestPutGetGcsDownscopedCredential(t *testing.T) {
t.Error(err)
}
defer func() {
defer dbt.mustExec("drop table " + tableName)
if fileStream != nil {
fileStream.Close()
}
Expand Down
2 changes: 0 additions & 2 deletions put_get_user_stage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ func putGetUserStage(t *testing.T, tmpDir string, numberOfFiles int, numberOfLin
}
dbt.mustExec("rm @" + stageName)
dbt.mustExec("drop stage if exists " + stageName)
dbt.mustExec("drop table if exists " + dbname)
}()
dbt.mustExec(fmt.Sprintf("copy into %v from @%v", dbname, stageName))

Expand Down Expand Up @@ -124,7 +123,6 @@ func TestPutLoadFromUserStage(t *testing.T) {
c2 STRING, c3 STRING,c4 STRING, c5 STRING, c6 STRING, c7 STRING,
c8 STRING, c9 STRING)`
dbt.mustExec(execQuery)
defer dbt.mustExec("drop table if exists gotest_putget_t2")
defer dbt.mustExec("drop stage if exists " + data.stage)

execQuery = fmt.Sprintf("put file://%v/test_data/orders_10*.csv @%v",
Expand Down
3 changes: 0 additions & 3 deletions put_get_with_aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ func TestLoadS3(t *testing.T) {
entities__user_mentions string, favorited string, retweeted string,
lang string)`
dbt.mustExec(execQuery)
defer dbt.mustExec("drop table if exists tweets")
dbt.mustQueryAssertCount("ls @%tweets", 0)

rows := dbt.mustQuery(fmt.Sprintf(`copy into tweets from
Expand Down Expand Up @@ -123,7 +122,6 @@ func TestPutWithInvalidToken(t *testing.T) {
" (a int, b string)", nil); err != nil {
t.Fatal(err)
}
defer sc.Exec("drop table "+tableName, nil)

jsonBody, err := json.Marshal(execRequest{
SQLText: fmt.Sprintf("put 'file://%v' @%%%v", fname, tableName),
Expand Down Expand Up @@ -235,7 +233,6 @@ func TestPretendToPutButList(t *testing.T) {
" (a int, b string)", nil); err != nil {
t.Fatal(err)
}
defer sc.Exec("drop table "+tableName, nil)

jsonBody, err := json.Marshal(execRequest{
SQLText: fmt.Sprintf("put 'file://%v' @%%%v", fname, tableName),
Expand Down
1 change: 0 additions & 1 deletion rows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,6 @@ func TestWithArrowBatchesNotImplementedForResult(t *testing.T) {
if _, err = sc.Exec("create or replace table testArrowBatches (a int, b int)", nil); err != nil {
t.Fatal(err)
}
defer sc.Exec("drop table if exists testArrowBatches", nil)

result, err := sc.ExecContext(ctx, "insert into testArrowBatches values (1, 2), (3, 4), (5, 6)", []driver.NamedValue{})
if err != nil {
Expand Down
8 changes: 0 additions & 8 deletions statement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,6 @@ func TestE2EFetchResultByID(t *testing.T) {
}); err != nil {
t.Fatalf("failed to drop table: %v", err)
}

if _, err := db.Exec("drop table if exists test_fetch_result"); err != nil {
t.Fatalf("failed to drop table: %v", err)
}
}

func TestWithDescribeOnly(t *testing.T) {
Expand Down Expand Up @@ -243,10 +239,6 @@ func TestStmtExec(t *testing.T) {
}); err != nil {
t.Fatalf("failed to drop table: %v", err)
}

if _, err := conn.ExecContext(ctx, "drop table if exists test_table"); err != nil {
t.Fatalf("failed to drop table: %v", err)
}
}

func getStatusSuccessButInvalidJSONfunc(_ context.Context, _ *snowflakeRestful, _ *url.URL, _ map[string]string, _ time.Duration) (*http.Response, error) {
Expand Down

0 comments on commit 3ec3a78

Please sign in to comment.