Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix test
  • Loading branch information
David Coe committed Jun 15, 2025
commit 6a89fd26ae4a926803611948f456154f54536d97
86 changes: 34 additions & 52 deletions go/adbc/driver/snowflake/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1757,29 +1757,8 @@ func (suite *SnowflakeTests) TestTimestampPrecisionJson() {
suite.True(rdr.Next())
rec := rdr.Record()

result := validateRecord(
rec,
suite.Quirks.catalogName,
suite.Quirks.schemaName,
tempTable,
)

suite.True(result, "Expected primary key record not found")

query = fmt.Sprintf("DROP TABLE %s.%s.%s", suite.Quirks.catalogName, suite.Quirks.schemaName, tempTable)
stmt, _ = cnxn.NewStatement()
suite.Require().NoError(stmt.SetSqlQuery(query))
_, err = stmt.ExecuteUpdate(suite.ctx)
defer rdr.Release()
suite.Require().NoError(err)
}
suite.True(rec.NumRows() == 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suite.Equal?


func validateRecord(
rec arrow.Record,
catalogName string,
schemaName string,
tableName string,
) bool {
// Get column indexes
getColIdx := func(name string) int {
for i := 0; i < int(rec.NumCols()); i++ {
Expand All @@ -1799,41 +1778,44 @@ func validateRecord(
createdIdx := getColIdx("created_on")

if dbIdx == -1 || schemaIdx == -1 || tableIdx == -1 || colIdx == -1 || seqIdx == -1 || createdIdx == -1 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suite.Equal instead of panic?

Or just panic inside of getColIndex with the column name.

fmt.Println("Missing expected columns")
return false
panic("Missing expected columns")
}

numRows := int(rec.NumRows())
for i := 0; i < numRows; i++ {
dbName := rec.Column(dbIdx).(*array.String).Value(i)
schema := rec.Column(schemaIdx).(*array.String).Value(i)
tbl := rec.Column(tableIdx).(*array.String).Value(i)
column := rec.Column(colIdx).(*array.String).Value(i)
keySeq := rec.Column(seqIdx).(*array.Int64).Value(i)

// Created_on should be a timestamp array
createdCol := rec.Column(createdIdx).(*array.Timestamp)
created := time.Unix(0, int64(createdCol.Value(i))*int64(time.Microsecond)).UTC()

// Perform checks
if strings.EqualFold(dbName, catalogName) &&
strings.EqualFold(schema, schemaName) &&
strings.EqualFold(tbl, tableName) &&
strings.EqualFold(column, "id") &&
keySeq == 1 {

now := time.Now().UTC()
diff := now.Sub(created)
if diff < 0 {
diff = -diff
}
if diff <= 2*time.Minute {
return true
}
i := 0
dbName := rec.Column(dbIdx).(*array.String).Value(i)
schema := rec.Column(schemaIdx).(*array.String).Value(i)
tbl := rec.Column(tableIdx).(*array.String).Value(i)
column := rec.Column(colIdx).(*array.String).Value(i)
keySeq := rec.Column(seqIdx).(*array.Int64).Value(i)

// Created_on should be a timestamp array
createdCol := rec.Column(createdIdx).(*array.Timestamp)
created := time.Unix(0, int64(createdCol.Value(i))*int64(time.Microsecond)).UTC()

// Perform checks
if strings.EqualFold(dbName, suite.Quirks.catalogName) &&
strings.EqualFold(schema, suite.Quirks.schemaName) &&
strings.EqualFold(tbl, tempTable) &&
strings.EqualFold(column, "id") &&
keySeq == 1 {

now := time.Now().UTC()
diff := now.Sub(created)
if diff < 0 {
diff = -diff
}
// since this was just created, make sure the times are within a short difference
suite.Assert().True(diff <= 2*time.Minute)
} else {
panic("Invalid values")
}

return false
query = fmt.Sprintf("DROP TABLE %s.%s.%s", suite.Quirks.catalogName, suite.Quirks.schemaName, tempTable)
stmt, _ = cnxn.NewStatement()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't being cleaned up, though I suppose it doesn't seem to matter

suite.Require().NoError(stmt.SetSqlQuery(query))
_, err = stmt.ExecuteUpdate(suite.ctx)
defer rdr.Release()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this a double release? And why is it all the way down here?

suite.Require().NoError(err)
}

func (suite *SnowflakeTests) TestTimestampPrecision() {
Expand Down
Loading