@@ -11,6 +11,7 @@ import (
11
11
"github.com/apache/arrow/go/v12/arrow/memory"
12
12
"log"
13
13
"sync"
14
+ "time"
14
15
15
16
sf "github.com/snowflakedb/gosnowflake"
16
17
)
@@ -20,10 +21,11 @@ type sampleRecord struct {
20
21
workerID int
21
22
number int32
22
23
string string
24
+ ts * time.Time
23
25
}
24
26
25
27
func (s sampleRecord ) String () string {
26
- return fmt .Sprintf ("batchID: %v, workerID: %v, number: %v, string: %v" , s .batchID , s .workerID , s .number , s .string )
28
+ return fmt .Sprintf ("batchID: %v, workerID: %v, number: %v, string: %v, ts: %v " , s .batchID , s .workerID , s .number , s .string , s . ts )
27
29
}
28
30
29
31
func main () {
@@ -48,8 +50,14 @@ func main() {
48
50
log .Fatalf ("failed to create DSN from Config: %v, err: %v" , cfg , err )
49
51
}
50
52
51
- ctx := sf .WithArrowAllocator (sf .WithArrowBatches (context .Background ()), memory .DefaultAllocator )
52
- query := "SELECT SEQ4(), 'example ' || (SEQ4() * 2) FROM TABLE(GENERATOR(ROWCOUNT=>30000))"
53
+ ctx :=
54
+ sf .WithOriginalTimestamp (
55
+ sf .WithArrowAllocator (
56
+ sf .WithArrowBatches (context .Background ()), memory .DefaultAllocator ))
57
+
58
+ query := "SELECT SEQ4(), 'example ' || (SEQ4() * 2), " +
59
+ " TO_TIMESTAMP_NTZ('9999-01-01 13:13:13.' || LPAD(SEQ4(),9,'0')) ltz " +
60
+ " FROM TABLE(GENERATOR(ROWCOUNT=>30000))"
53
61
54
62
db , err := sql .Open ("snowflake" , dsn )
55
63
if err != nil {
@@ -88,7 +96,7 @@ func main() {
88
96
}
89
97
sampleRecordsPerBatch [batchID ] = make ([]sampleRecord , batches [batchID ].GetRowCount ())
90
98
totalRowID := 0
91
- convertFromColumnsToRows (records , sampleRecordsPerBatch , batchID , workerId , totalRowID )
99
+ convertFromColumnsToRows (records , sampleRecordsPerBatch , batchID , workerId , totalRowID , batches [ batchID ] )
92
100
}
93
101
}(& waitGroup , batchIds , workerID )
94
102
}
@@ -110,14 +118,15 @@ func main() {
110
118
}
111
119
112
120
func convertFromColumnsToRows (records * []arrow.Record , sampleRecordsPerBatch [][]sampleRecord , batchID int ,
113
- workerID int , totalRowID int ) {
121
+ workerID int , totalRowID int , batch * sf. ArrowBatch ) {
114
122
for _ , record := range * records {
115
123
for rowID , intColumn := range record .Column (0 ).(* array.Int32 ).Int32Values () {
116
124
sampleRecord := sampleRecord {
117
125
batchID : batchID ,
118
126
workerID : workerID ,
119
127
number : intColumn ,
120
128
string : record .Column (1 ).(* array.String ).Value (rowID ),
129
+ ts : batch .ArrowSnowflakeTimestampToTime (record , 2 , rowID ),
121
130
}
122
131
sampleRecordsPerBatch [batchID ][totalRowID ] = sampleRecord
123
132
totalRowID ++
0 commit comments