|
7 | 7 | "context"
|
8 | 8 | "database/sql/driver"
|
9 | 9 | "encoding/json"
|
| 10 | + "errors" |
10 | 11 | "fmt"
|
11 | 12 | "io"
|
12 | 13 | "math/rand"
|
@@ -533,6 +534,44 @@ func TestWithArrowBatchesAsync(t *testing.T) {
|
533 | 534 | })
|
534 | 535 | }
|
535 | 536 |
|
| 537 | +func TestWithArrowBatchesButReturningJSON(t *testing.T) { |
| 538 | + testWithArrowBatchesButReturningJSON(t, false) |
| 539 | +} |
| 540 | + |
| 541 | +func TestWithArrowBatchesButReturningJSONAsync(t *testing.T) { |
| 542 | + testWithArrowBatchesButReturningJSON(t, true) |
| 543 | +} |
| 544 | + |
| 545 | +func testWithArrowBatchesButReturningJSON(t *testing.T, async bool) { |
| 546 | + runSnowflakeConnTest(t, func(sct *SCTest) { |
| 547 | + requestID := NewUUID() |
| 548 | + pool := memory.NewCheckedAllocator(memory.DefaultAllocator) |
| 549 | + defer pool.AssertSize(t, 0) |
| 550 | + ctx := WithArrowAllocator(context.Background(), pool) |
| 551 | + ctx = WithArrowBatches(ctx) |
| 552 | + ctx = WithRequestID(ctx, requestID) |
| 553 | + if async { |
| 554 | + ctx = WithAsyncMode(ctx) |
| 555 | + } |
| 556 | + |
| 557 | + sct.mustExec(forceJSON, nil) |
| 558 | + rows := sct.mustQueryContext(ctx, "SELECT 'hello'", nil) |
| 559 | + defer rows.Close() |
| 560 | + _, err := rows.(SnowflakeRows).GetArrowBatches() |
| 561 | + assertNotNilF(t, err) |
| 562 | + var se *SnowflakeError |
| 563 | + errors.As(err, &se) |
| 564 | + assertEqualE(t, se.Message, errJSONResponseInArrowBatchesMode) |
| 565 | + |
| 566 | + ctx = WithRequestID(context.Background(), requestID) |
| 567 | + rows2 := sct.mustQueryContext(ctx, "SELECT 'hello'", nil) |
| 568 | + defer rows2.Close() |
| 569 | + scanValues := make([]driver.Value, 1) |
| 570 | + assertNilF(t, rows2.Next(scanValues)) |
| 571 | + assertEqualE(t, scanValues[0], "hello") |
| 572 | + }) |
| 573 | +} |
| 574 | + |
536 | 575 | func TestQueryArrowStream(t *testing.T) {
|
537 | 576 | runSnowflakeConnTest(t, func(sct *SCTest) {
|
538 | 577 | numrows := 50000 // approximately 10 ArrowBatch objects
|
|
0 commit comments