bigquery: add standard query tests
@@ -645,6 +645,59 @@ func TestIntegration_TimeTypes(t *testing.T) {
checkRead(t, "TimeTypes", table.Read(ctx), wantRows)
}
+func TestIntegration_StandardQuery(t *testing.T) {
+ if client == nil {
+ t.Skip("Integration tests skipped")
+ }
+ ctx := context.Background()
+
+ d := civil.Date{2016, 3, 20}
+ tm := civil.Time{15, 04, 05, 0}
+ ts := time.Date(2016, 3, 20, 15, 04, 05, 0, time.UTC)
+ tmd := ts.Format("2006-01-02 15:04:05")
+
+ // Constructs Value slices made up of int64s.
+ ints := func(args ...int) []Value {
+ vals := make([]Value, len(args))
+ for i, arg := range args {
+ vals[i] = int64(arg)
+ }
+ return vals
+ }
+
+ testCases := []struct {
+ query string
+ wantRow []Value
+ }{
+ {"SELECT 1", ints(1)},
+ {"SELECT 1.3", []Value{1.3}},
+ {"SELECT TRUE", []Value{true}},
+ {"SELECT 'ABC'", []Value{"ABC"}},
+ {"SELECT CAST('foo' AS BYTES)", []Value{[]byte("foo")}},
+ {fmt.Sprintf("SELECT TIMESTAMP '%s'", tmd), []Value{ts}},
+ {fmt.Sprintf("SELECT [TIMESTAMP '%s', TIMESTAMP '%s']", tmd, tmd), []Value{[]Value{ts, ts}}},
+ {fmt.Sprintf("SELECT ('hello', TIMESTAMP '%s')", tmd), []Value{[]Value{"hello", ts}}},
+ {fmt.Sprintf("SELECT DATETIME(TIMESTAMP '%s')", tmd), []Value{civil.DateTime{d, tm}}},
+ {fmt.Sprintf("SELECT DATE(TIMESTAMP '%s')", tmd), []Value{d}},
+ {fmt.Sprintf("SELECT TIME(TIMESTAMP '%s')", tmd), []Value{tm}},
+ {"SELECT (1, 2)", []Value{ints(1, 2)}},
+ {"SELECT [1, 2, 3]", []Value{ints(1, 2, 3)}},
+ {"SELECT ([1, 2], 3, [4, 5])", []Value{[]Value{ints(1, 2), int64(3), ints(4, 5)}}},
+ {"SELECT [(1, 2, 3), (4, 5, 6)]", []Value{[]Value{ints(1, 2, 3), ints(4, 5, 6)}}},
+ {"SELECT [([1, 2, 3], 4), ([5, 6], 7)]", []Value{[]Value{[]Value{ints(1, 2, 3), int64(4)}, []Value{ints(5, 6), int64(7)}}}},
+ {"SELECT ARRAY(SELECT STRUCT([1, 2]))", []Value{[]Value{[]Value{ints(1, 2)}}}},
+ }
+ for _, c := range testCases {
+ q := client.Query(c.query)
+ q.UseStandardSQL = true
+ it, err := q.Read(ctx)
+ if err != nil {
+ t.Fatal(err)
+ }
+ checkRead(t, "StandardQuery", it, [][]Value{c.wantRow})
+ }
+}
+
// Creates a new, temporary table with a unique name and the given schema.
func newTable(t *testing.T, s Schema) *Table {
fiveMinutesFromNow = time.Now().Add(5 * time.Minute).Round(time.Second)
