|
| 1 | +package info |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/stretchr/testify/assert" |
| 7 | + "github.com/viant/sqlx/metadata/database" |
| 8 | +) |
| 9 | + |
| 10 | +func TestDialect_CompositeIn(t *testing.T) { |
| 11 | + testCases := []struct { |
| 12 | + description string |
| 13 | + dialect *Dialect |
| 14 | + columns []string |
| 15 | + rowCount int |
| 16 | + expect string |
| 17 | + }{ |
| 18 | + { |
| 19 | + description: "mysql composite", |
| 20 | + dialect: &Dialect{Product: database.Product{Name: "MySQL"}}, |
| 21 | + columns: []string{"t.advertiser_id", "t.val"}, |
| 22 | + rowCount: 2, |
| 23 | + expect: "(t.advertiser_id, t.val) IN ((?, ?), (?, ?))", |
| 24 | + }, |
| 25 | + { |
| 26 | + description: "postgres composite", |
| 27 | + dialect: &Dialect{Product: database.Product{Name: "PostgreSQL"}}, |
| 28 | + columns: []string{"t.advertiser_id", "t.val"}, |
| 29 | + rowCount: 2, |
| 30 | + expect: "(t.advertiser_id, t.val) IN ((?, ?), (?, ?))", |
| 31 | + }, |
| 32 | + { |
| 33 | + description: "bigquery composite", |
| 34 | + dialect: &Dialect{Product: database.Product{Name: "BigQuery"}, CompositeInRenderer: func(columns []string, rowCount int) string { |
| 35 | + return "(t.advertiser_id, t.val) IN (SELECT AS STRUCT ?, ? UNION ALL SELECT AS STRUCT ?, ?)" |
| 36 | + }}, |
| 37 | + columns: []string{"t.advertiser_id", "t.val"}, |
| 38 | + rowCount: 2, |
| 39 | + expect: "(t.advertiser_id, t.val) IN (SELECT AS STRUCT ?, ? UNION ALL SELECT AS STRUCT ?, ?)", |
| 40 | + }, |
| 41 | + { |
| 42 | + description: "empty rows", |
| 43 | + dialect: &Dialect{Product: database.Product{Name: "MySQL"}}, |
| 44 | + columns: []string{"t.advertiser_id", "t.val"}, |
| 45 | + rowCount: 0, |
| 46 | + expect: "1 = 0", |
| 47 | + }, |
| 48 | + } |
| 49 | + |
| 50 | + for _, testCase := range testCases { |
| 51 | + t.Run(testCase.description, func(t *testing.T) { |
| 52 | + assert.Equal(t, testCase.expect, testCase.dialect.CompositeIn(testCase.columns, testCase.rowCount)) |
| 53 | + }) |
| 54 | + } |
| 55 | +} |
0 commit comments