func main() { session := integration.TestSession("127.0.0.1", "cqlc") integration.Truncate(session, REVERSE_TIMESERIES) result := "FAILED" ctx := cqlc.NewContext() batch := gocql.NewBatch(gocql.LoggedBatch) events := 100 for i := 0; i < events; i++ { unix := time.Now().Unix() t := time.Unix(unix+int64(i), 0) ctx.Upsert(REVERSE_TIMESERIES). SetString(REVERSE_TIMESERIES.EVENT_TYPE, "x"). SetTimestamp(REVERSE_TIMESERIES.INSERTION_TIME, t). SetBytes(REVERSE_TIMESERIES.EVENT, []byte("neb")). Batch(batch) } if err := session.ExecuteBatch(batch); err != nil { log.Fatalf("Could not execute batch: %v", err) os.Exit(1) } iter, err := ctx.Select().From(REVERSE_TIMESERIES).Fetch(session) if err != nil { log.Fatalf("Could not read REVERSE_TIMESERIES: %v", err) os.Exit(1) } var previous time.Time err = MapReverseTimeseries(iter, func(e ReverseTimeseries) (bool, error) { current := e.InsertionTime if !previous.IsZero() { if current.After(previous) { return false, fmt.Errorf("Wrong ordering (DESC): previous was %v but current is %v", previous, current) } } previous = current return true, nil }) if err != nil { log.Fatalf("Unexpected order of REVERSE_TIMESERIES: %v", err) os.Exit(1) } result = "PASSED" os.Stdout.WriteString(result) }
func main() { session := integration.TestSession("127.0.0.1", "cqlc") integration.Truncate(session, REALLY_BASIC) result := "FAILED" ctx := cqlc.NewContext() basic := ReallyBasic{ Id: "y", Int32Column: 2001, } err := ctx.Store(REALLY_BASIC.Bind(basic)).Exec(session) if err != nil { log.Fatalf("Could not bind data: %v", err) os.Exit(1) } fetched := fetchFirstReallyBasic(ctx, session, "y") if reflect.DeepEqual(fetched, basic) { result = "PASSED" } else { result = fmt.Sprintf("[%+v] [%+v]", fetched, basic) } os.Stdout.WriteString(result) }
func main() { session := integration.TestSession("127.0.0.1", "cqlc") session.SetPageSize(1000) integration.Truncate(session, EVENTS) result := "FAILED" ctx := cqlc.NewContext() batch := gocql.NewBatch(gocql.LoggedBatch) rounds := 10 distinct := 10 for i := 0; i < rounds; i++ { for j := 0; j < distinct; j++ { ctx.Upsert(EVENTS). SetInt64(EVENTS.SENSOR, int64(j)). SetTimeUUID(EVENTS.TIMESTAMP, gocql.TimeUUID()). SetFloat32(EVENTS.TEMPERATURE, 19.8). SetInt32(EVENTS.PRESSURE, 357). Batch(batch) } } err := session.ExecuteBatch(batch) if err != nil { log.Fatalf("Could not execute batch: %v", err) os.Exit(1) } iter, err := ctx.SelectDistinct(EVENTS.SENSOR).From(EVENTS).Fetch(session) if err != nil { log.Fatalf("Could not prepare query: %v", err) os.Exit(1) } count := 0 MapEvents(iter, func(e Events) (bool, error) { count++ return true, nil }) if err := iter.Close(); err != nil { log.Fatalf("Could not close iterator: %v", err) os.Exit(1) } if count == distinct { result = "PASSED" } else { result = fmt.Sprintf("Expected %d distinct rows; got %d", distinct, count) } os.Stdout.WriteString(result) }
func main() { session := integration.TestSession("127.0.0.1", "cqlc") integration.Truncate(session, BASIC_CLUSTERED) result := "FAILED" rows := 10 ctx := cqlc.NewContext() batch := gocql.NewBatch(gocql.LoggedBatch) for i := 0; i < rows; i++ { err := ctx.Upsert(BASIC_CLUSTERED). SetInt64(BASIC_CLUSTERED.ID, int64(0)). SetInt32(BASIC_CLUSTERED.INT32_CLUSTER, int32(i)). SetInt32(BASIC_CLUSTERED.INT32_COLUMN, int32(i)). Batch(batch) if err != nil { log.Fatalf("Could not batch upsert: %v", err) os.Exit(1) } } err := session.ExecuteBatch(batch) if err != nil { log.Fatalf("Could not execute batch: %v", err) os.Exit(1) } iter, err := ctx.Select().From(BASIC_CLUSTERED).Where(BASIC_CLUSTERED.ID.Eq(0)).Fetch(session) basics, err := BindBasicClustered(iter) if err != nil { log.Fatalf("Could not bind data: %v", err) os.Exit(1) } err = iter.Close() if err != nil { log.Fatalf("Could not bind data: %v", err) os.Exit(1) } if len(basics) == rows { result = "PASSED" } os.Stdout.WriteString(result) }
func main() { session := integration.TestSession("127.0.0.1", "cqlc") integration.Truncate(session, EVENTS) result := "FAILED" ctx := cqlc.NewContext() var sensorId int64 = 100 ctx.Upsert(EVENTS). SetInt64(EVENTS.SENSOR, sensorId). SetTimeUUID(EVENTS.TIMESTAMP, gocql.TimeUUID()). SetFloat32(EVENTS.TEMPERATURE, 19.8). SetInt32(EVENTS.PRESSURE, 357). Exec(session) iter, err := ctx.Select(). From(EVENTS). Where( EVENTS.SENSOR.Eq(sensorId), EVENTS.TIMESTAMP.Lt(gocql.TimeUUID())). Fetch(session) if err != nil { log.Fatalf("Could not execute query: %v", err) return } events, err := BindEvents(iter) if err != nil { log.Fatalf("Could not bind data: %v", err) return } err = iter.Close() if err != nil { log.Fatalf("Could not bind data: %v", err) return } if len(events) == 1 { result = "PASSED" } os.Stdout.WriteString(result) }
func main() { session := integration.TestSession("127.0.0.1", "cqlc") integration.Truncate(session, REALLY_BASIC) result := "FAILED" ctx := cqlc.NewContext() err := ctx.Upsert(REALLY_BASIC). SetString(REALLY_BASIC.ID, "x"). SetInt32(REALLY_BASIC.INT32_COLUMN, 222). Exec(session) if err != nil { log.Fatalf("Could not execute upsert: %v", err) os.Exit(1) } err = ctx.Delete(REALLY_BASIC.INT32_COLUMN).From(REALLY_BASIC).Where(REALLY_BASIC.ID.Eq("x")).Exec(session) if err != nil { log.Fatalf("Could not execute delete: %v", err) os.Exit(1) } basic := fetchFirstBasic(ctx, session, "x") if basic.Int32Column != 0 { log.Fatalf("Got bogus basic: %v", basic) os.Exit(1) } err = ctx.Delete().From(REALLY_BASIC).Where(REALLY_BASIC.ID.Eq("x")).Exec(session) if err != nil { log.Fatalf("Could not execute delete: %v", err) os.Exit(1) } basic = fetchFirstBasic(ctx, session, "x") if basic == nil { result = "PASSED" } os.Stdout.WriteString(result) }
func main() { session := integration.TestSession("127.0.0.1", "cqlc") integration.Truncate(session, ORIGINAL) result := "FAILED" ctx := cqlc.NewContext() o := Original{ Id: "x", Date: time.Now().UTC().Truncate(time.Millisecond), Comment: "foo", } if err := ctx.Store(ORIGINAL.Bind(o)).Exec(session); err != nil { log.Fatalf("Could not upsert ORIGINAL: %v", err) os.Exit(1) } iter, err := ctx.Select().From(ORIGINAL).Fetch(session) if err != nil { log.Fatalf("Could not read ORIGINAL: %v", err) os.Exit(1) } var c Clone err = MapOriginal(iter, func(o Original) (bool, error) { c = duplicate(&o) return false, nil }) if err != nil { log.Fatalf("Could not map ORIGINAL: %v", err) os.Exit(1) } if o.Id == c.Id && o.Date == c.Date { result = "PASSED" } else { result = fmt.Sprintf("Original: %+v; clone: %+v", o, c) } os.Stdout.WriteString(result) }
func main() { session := integration.TestSession("127.0.0.1", "cqlc") integration.Truncate(session, CLUSTER_BY_STRING_AND_INT) result := "FAILED" ctx := cqlc.NewContext() err := ctx.Upsert(CLUSTER_BY_STRING_AND_INT). SetString(CLUSTER_BY_STRING_AND_INT.ID, "a"). SetString(CLUSTER_BY_STRING_AND_INT.STRING_CLUSTER, "y"). SetInt64(CLUSTER_BY_STRING_AND_INT.INT64_CLUSTER, 4). SetInt64(CLUSTER_BY_STRING_AND_INT.LAST_CLUSTER_ELEMENT, 40). SetInt32(CLUSTER_BY_STRING_AND_INT.INT32_COLUMN, 100). Exec(session) if err != nil { log.Fatalf("Could not execute upsert: %v", err) os.Exit(1) } id := CLUSTER_BY_STRING_AND_INT.ID.Eq("a") passed := expectComparisonResult(ctx, session, expect(1), id, CLUSTER_BY_STRING_AND_INT.STRING_CLUSTER.Gt("x")) passed = expectComparisonResult(ctx, session, expect(0), id, CLUSTER_BY_STRING_AND_INT.STRING_CLUSTER.Gt("y")) passed = expectComparisonResult(ctx, session, expect(0), id, CLUSTER_BY_STRING_AND_INT.STRING_CLUSTER.Ge("z")) passed = expectComparisonResult(ctx, session, expect(1), id, CLUSTER_BY_STRING_AND_INT.STRING_CLUSTER.Lt("z")) passed = expectComparisonResult(ctx, session, expect(1), id, CLUSTER_BY_STRING_AND_INT.STRING_CLUSTER.Le("y")) passed = expectComparisonResult(ctx, session, expect(0), id, CLUSTER_BY_STRING_AND_INT.STRING_CLUSTER.Lt("y")) passed = expectComparisonResult(ctx, session, expect(0), id, CLUSTER_BY_STRING_AND_INT.STRING_CLUSTER.Lt("y")) stringCluster := CLUSTER_BY_STRING_AND_INT.STRING_CLUSTER.Eq("y") int64Cluster := CLUSTER_BY_STRING_AND_INT.INT64_CLUSTER.Eq(4) lastClusterElement := CLUSTER_BY_STRING_AND_INT.LAST_CLUSTER_ELEMENT.In(39, 40, 41) passed = expectComparisonResult(ctx, session, expect(1), id, stringCluster, int64Cluster, lastClusterElement) passed = expectComparisonResult(ctx, session, expect(1), CLUSTER_BY_STRING_AND_INT.ID.In("a")) if passed { result = "PASSED" } os.Stdout.WriteString(result) }
func main() { session := integration.TestSession("127.0.0.1", "cqlc") integration.Truncate(session, SIMPLE_INDEXED_COMPOSITE) result := "FAILED" ctx := cqlc.NewContext() s := SimpleIndexedComposite{ X: 1, Y: 2, Z: 3, } if err := ctx.Store(SIMPLE_INDEXED_COMPOSITE.Bind(s)).Exec(session); err != nil { log.Fatalf("Could not upsert ORIGINAL: %v", err) os.Exit(1) } var z int32 found, err := ctx.Select(SIMPLE_INDEXED_COMPOSITE.Z). From(SIMPLE_INDEXED_COMPOSITE). Where(SIMPLE_INDEXED_COMPOSITE.X.Eq(s.X), SIMPLE_INDEXED_COMPOSITE.Y.Eq(s.Y)). Bind(SIMPLE_INDEXED_COMPOSITE.Z.To(&z)). FetchOne(session) if !found { log.Fatalf("Could not find SIMPLE_INDEXED_COMPOSITE with key %v", 1) os.Exit(1) } if err != nil { log.Fatalf("Could not retrieve SIMPLE_INDEXED_COMPOSITE: %v", err) os.Exit(1) } if z == s.Z { result = "PASSED" } os.Stdout.WriteString(result) }
func main() { s := integration.TestSession("127.0.0.1", "cqlc") cqlc.Truncate(s, REALLY_BASIC) result := "FAILED" ctx := cqlc.NewContext() basic := ReallyBasic{ Id: "y", Int32Column: 2001, } err := ctx.Store(REALLY_BASIC.Bind(basic)).Exec(s) if err != nil { log.Fatalf("Could not store data: %v", err) os.Exit(1) } query := ctx.Select().From(REALLY_BASIC).Where(REALLY_BASIC.ID.Eq("y")) var fetched ReallyBasic found, err := query.Into(REALLY_BASIC.To(&fetched)).FetchOne(s) if err != nil { log.Fatalf("Could not retrieve data: %v", err) os.Exit(1) } if found { if reflect.DeepEqual(fetched, basic) { result = "PASSED" } else { result = fmt.Sprintf("[%+v] [%+v]", fetched, basic) } } os.Stdout.WriteString(result) }
func main() { session := integration.TestSession("127.0.0.1", "cqlc") integration.Truncate(session, COUNTER) result := "FAILED" ctx := cqlc.NewContext() err := ctx.UpdateCounter(COUNTER). Increment(COUNTER.COUNTER_COLUMN, 13). Having(COUNTER.ID.Eq("x")). Exec(session) if err != nil { log.Fatalf("Could not execute counter increment: %v", err) } found, counter := readCounter(session, "x") if found && counter == 13 { result = "PASSED" } c := BasicCounter{ Id: "x", CounterColumn: 11, } err = ctx.Add(COUNTER.Bind(c)).Exec(session) if err != nil { log.Fatalf("Could not execute counter increment: %v", err) } found, counter = readCounter(session, "x") if !found && counter != 24 { result = fmt.Sprintf("Expected 24, but counter was %d", counter) } os.Stdout.WriteString(result) }
func main() { session := integration.TestSession("127.0.0.1", "cqlc") integration.Truncate(session, BASIC_BLOB) result := "FAILED" ctx := cqlc.NewContext() blob := BasicBlob{ Id: "baz", BlobColumn: []byte("foo"), } err := ctx.Store(BASIC_BLOB.Bind(blob)).Exec(session) if err != nil { log.Fatalf("Could not bind data: %v", err) os.Exit(1) } var b []byte found, err := ctx.Select(). From(BASIC_BLOB). Where(BASIC_BLOB.ID.Eq("baz")). Bind(BASIC_BLOB.BLOB_COLUMN.To(&b)). FetchOne(session) if found && bytes.Equal(blob.BlobColumn, b) { result = "PASSED" } else { result = fmt.Sprintf("Blob was %s", string(b)) } os.Stdout.WriteString(result) }
func main() { session := integration.TestSession("127.0.0.1", "cqlc") integration.Truncate(session, REALLY_BASIC) result := "FAILED" applied, _, _ := compareAndSwap(session, "a", 1) if applied { applied, id, int32column := compareAndSwap(session, "a", 1) if !applied { if id == "a" && int32column == 1 { result = "PASSED" } } // TODO Right now there is no support for CAS operations // on UPDATE statements so because this lacks a WHERE // clause, the value cannot be upated for a key that // already exists applied, id, int32column = compareAndSwap(session, "a", 2) if !applied { if id == "a" && int32column == 1 { result = "PASSED" } } } os.Stdout.WriteString(result) }
func main() { s := integration.TestSession("127.0.0.1", "cqlc") cqlc.Truncate(s, COLLECTIONS) result := "FAILED" Input.Id = 12 ctx := cqlc.NewContext() if err := ctx.Store(COLLECTIONS.Bind(Input)).Exec(s); err != nil { log.Fatalf("Could not store collections: %v", err) os.Exit(1) } var output Collections found, err := ctx.Select().From(COLLECTIONS).Where(COLLECTIONS.ID.Eq(Input.Id)).Into(COLLECTIONS.To(&output)).FetchOne(s) if err != nil { log.Fatalf("Could not store collections: %v", err) os.Exit(1) } if found { lhs := fmt.Sprintf("%+v", Input) rhs := fmt.Sprintf("%+v", output) if lhs == rhs { result = "PASSED" } else { result = fmt.Sprintf("Expected %s but got %s", lhs, rhs) } } os.Stdout.WriteString(result) }
func main() { session := integration.TestSession("127.0.0.1", "cqlc") integration.Truncate(session, FIRST_TIMELINE) integration.Truncate(session, SECOND_TIMELINE) result := "FAILED" timestamp := gocql.TimeUUID() first := FirstTimeline{ When: timestamp, Tag: "foobar", } second := SecondTimeline{ When: timestamp, Latitude: 50.12, Longitude: 0.87, } ctx := cqlc.NewContext() err := ctx.Store(FIRST_TIMELINE.Bind(first)).Exec(session) err = ctx.Store(SECOND_TIMELINE.Bind(second)).Exec(session) if err != nil { log.Fatalf("Could not execute upsert: %v", err) os.Exit(1) } var tag string var latitude float32 f1, err := fetchOne(ctx, session, FIRST_TIMELINE, timestamp, FIRST_TIMELINE.TAG.To(&tag)) f2, err := fetchOne(ctx, session, SECOND_TIMELINE, timestamp, SECOND_TIMELINE.LATITUDE.To(&latitude)) if err != nil { log.Fatalf("Could not execute select: %v", err) os.Exit(1) } if f1 && f2 && tag == "foobar" && math.Float32bits(latitude) == math.Float32bits(50.12) { // TODO Implement a FROM binding t := "bar" l := float32(72.34) err = upsert(ctx, session, FIRST_TIMELINE, timestamp, FIRST_TIMELINE.TAG.To(&t)) err = upsert(ctx, session, SECOND_TIMELINE, timestamp, SECOND_TIMELINE.LATITUDE.To(&l)) if err != nil { log.Fatalf("Could not execute upsert: %v", err) os.Exit(1) } f1, err = fetchOne(ctx, session, FIRST_TIMELINE, timestamp, FIRST_TIMELINE.TAG.To(&tag)) f2, err = fetchOne(ctx, session, SECOND_TIMELINE, timestamp, SECOND_TIMELINE.LATITUDE.To(&latitude)) if err != nil { log.Fatalf("Could not execute select: %v", err) os.Exit(1) } if f1 && f2 && tag == t && math.Float32bits(latitude) == math.Float32bits(l) { err = deleteByTimestamp(ctx, session, FIRST_TIMELINE, timestamp) err = deleteByTimestamp(ctx, session, SECOND_TIMELINE, timestamp) if err != nil { log.Fatalf("Could not execute delete: %v", err) os.Exit(1) } var tag string var latitude float32 f1, err = fetchOne(ctx, session, FIRST_TIMELINE, timestamp, FIRST_TIMELINE.TAG.To(&tag)) f2, err = fetchOne(ctx, session, SECOND_TIMELINE, timestamp, SECOND_TIMELINE.LATITUDE.To(&latitude)) if err != nil { log.Fatalf("Could not execute select: %v", err) os.Exit(1) } if !f1 && !f2 && tag == "" && latitude == 0.0 { result = "PASSED" } else { result = fmt.Sprintf("After delete - Tag was: %s; Latitude was %f", tag, latitude) } } else { result = fmt.Sprintf("After upsert - Tag was: %s; Latitude was %f", tag, latitude) } } else { result = fmt.Sprintf("Before delete - Tag was: %s; Latitude was %f", tag, latitude) } os.Stdout.WriteString(result) }
func main() { s := integration.TestSession("127.0.0.1", "cqlc") cqlc.Truncate(s, COLLECTIONS) result := "FAILED" ctx := cqlc.NewContext() if err := ctx.Upsert(COLLECTIONS).AppendInt32Slice(COLLECTIONS.INT32_COLUMN, 1, 2).Where(COLLECTIONS.ID.Eq(20)).Exec(s); err != nil { log.Fatalf("Could not increment collections: %v", err) os.Exit(1) } var output []int32 found, err := ctx.Select(COLLECTIONS.INT32_COLUMN). From(COLLECTIONS). Where(COLLECTIONS.ID.Eq(20)). Bind(COLLECTIONS.INT32_COLUMN.To(&output)). FetchOne(s) if err != nil { log.Fatalf("Could not retreive collections: %v", err) os.Exit(1) } if found { if reflect.DeepEqual([]int32{1, 2}, output) { if err := ctx.Upsert(COLLECTIONS).AppendInt32Slice(COLLECTIONS.INT32_COLUMN, 3, 4).Where(COLLECTIONS.ID.Eq(20)).Exec(s); err != nil { log.Fatalf("Could not increment collections: %v", err) os.Exit(1) } var output []int32 found, err := ctx.Select(COLLECTIONS.INT32_COLUMN). From(COLLECTIONS). Where(COLLECTIONS.ID.Eq(20)). Bind(COLLECTIONS.INT32_COLUMN.To(&output)). FetchOne(s) if err != nil { log.Fatalf("Could not retreive collections: %v", err) os.Exit(1) } if found { if reflect.DeepEqual([]int32{1, 2, 3, 4}, output) { if err := ctx.Upsert(COLLECTIONS).PrependInt32Slice(COLLECTIONS.INT32_COLUMN, 0).Where(COLLECTIONS.ID.Eq(20)).Exec(s); err != nil { log.Fatalf("Could not increment collections: %v", err) os.Exit(1) } var output []int32 found, err := ctx.Select(COLLECTIONS.INT32_COLUMN). From(COLLECTIONS). Where(COLLECTIONS.ID.Eq(20)). Bind(COLLECTIONS.INT32_COLUMN.To(&output)). FetchOne(s) if err != nil { log.Fatalf("Could not retreive collections: %v", err) os.Exit(1) } if found { if reflect.DeepEqual([]int32{0, 1, 2, 3, 4}, output) { if err := ctx.Upsert(COLLECTIONS).RemoveInt32Slice(COLLECTIONS.INT32_COLUMN, 3, 1).Where(COLLECTIONS.ID.Eq(20)).Exec(s); err != nil { log.Fatalf("Could not increment collections: %v", err) os.Exit(1) } var output []int32 found, err := ctx.Select(COLLECTIONS.INT32_COLUMN). From(COLLECTIONS). Where(COLLECTIONS.ID.Eq(20)). Bind(COLLECTIONS.INT32_COLUMN.To(&output)). FetchOne(s) if err != nil { log.Fatalf("Could not retreive collections: %v", err) os.Exit(1) } if found { if reflect.DeepEqual([]int32{0, 2, 4}, output) { result = "PASSED" } } } } } } } } os.Stdout.WriteString(result) }
func main() { session := integration.TestSession("127.0.0.1", "cqlc") integration.Truncate(session, BASIC) result := "FAILED" ctx := cqlc.NewContext() basic := Basic{ Id: "x", Int32Column: 999, Int64Column: 1 << 55, AsciiColumn: "do-re-me", TimestampColumn: time.Date(1999, time.December, 31, 23, 59, 59, 59, time.UTC), // Keep it simple for reflect.DeepEqual BooleanColumn: true, TextColumn: "ipso", VarcharColumn: "lorem", FloatColumn: math.MaxFloat32, DoubleColumn: math.MaxFloat64, DecimalColumn: inf.NewDec(1, 9), TimeuuidColumn: gocql.TimeUUID(), MapColumn: map[string]string{"baz": "quux"}, ArrayColumn: []string{"baz", "quux"}, } err := ctx.Store(BASIC.Bind(basic)).Exec(session) if err != nil { log.Fatalf("Could not bind data: %v", err) os.Exit(1) } var int32Column int32 var decimalColumn *inf.Dec found, err := ctx.Select(). From(BASIC). Where(BASIC.ID.Eq("x")). Bind(BASIC.INT32_COLUMN.To(&int32Column), BASIC.DECIMAL_COLUMN.To(&decimalColumn)). FetchOne(session) if err != nil { log.Fatalf("Could not bind data: %v", err) os.Exit(1) } if err != nil { log.Fatalf("Could not bind data: %v", err) os.Exit(1) } if int32Column == 999 && reflect.DeepEqual(decimalColumn, basic.DecimalColumn) && found { found, err := ctx.Select(). From(BASIC). Where(BASIC.ID.Eq("y")). Bind(BASIC.INT32_COLUMN.To(&int32Column), BASIC.DECIMAL_COLUMN.To(&decimalColumn)). FetchOne(session) if err != nil { log.Fatalf("Could not bind data: %v", err) os.Exit(1) } if !found { result = "PASSED" } } else { result = fmt.Sprintf("int32Column: %d, decimalColumn %v", int32Column, decimalColumn) } os.Stdout.WriteString(result) }
func main() { session := integration.TestSession("127.0.0.1", "cqlc") cqlc.Truncate(session, BASIC) result := "FAILED" ctx := cqlc.NewContext() uuid, _ := gocql.RandomUUID() biggie := new(big.Int) biggie.SetString("830169365738487321165427203929228", 10) basic := Basic{ Id: "x", Int32Column: 111, Int64Column: 1 << 32, AsciiColumn: "ABC", TimestampColumn: time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC), // Keep it simple for reflect.DeepEqual BooleanColumn: true, TextColumn: "foo", VarcharColumn: "bar", FloatColumn: math.MaxFloat32, DoubleColumn: math.MaxFloat64, DecimalColumn: inf.NewDec(1, 3), VarintColumn: biggie, TimeuuidColumn: gocql.TimeUUID(), UuidColumn: uuid, MapColumn: map[string]string{"baz": "quux"}, ArrayColumn: []string{"baz", "quux"}, SetColumn: []string{"baz", "quux"}, } create(ctx, session, basic) iter, err := ctx.Select( BASIC.ID, BASIC.ASCII_COLUMN, BASIC.INT32_COLUMN, BASIC.INT64_COLUMN, BASIC.FLOAT_COLUMN, BASIC.DOUBLE_COLUMN, BASIC.DECIMAL_COLUMN, BASIC.VARINT_COLUMN, BASIC.TIMESTAMP_COLUMN, BASIC.TIMEUUID_COLUMN, BASIC.UUID_COLUMN, BASIC.BOOLEAN_COLUMN, BASIC.TEXT_COLUMN, BASIC.VARCHAR_COLUMN, BASIC.MAP_COLUMN, BASIC.ARRAY_COLUMN, BASIC.SET_COLUMN). From(BASIC). Where(BASIC.ID.Eq("x")). Fetch(session) if err != nil { log.Fatalf("Could not bind data: %v", err) os.Exit(1) } result, _ = checkBasics(iter, basic) iter, err = ctx.Select( BASIC.ID, BASIC.ASCII_COLUMN, BASIC.INT32_COLUMN, BASIC.INT64_COLUMN, BASIC.FLOAT_COLUMN, BASIC.DOUBLE_COLUMN, BASIC.DECIMAL_COLUMN, BASIC.VARINT_COLUMN, BASIC.TIMESTAMP_COLUMN, BASIC.TIMEUUID_COLUMN, BASIC.UUID_COLUMN, BASIC.BOOLEAN_COLUMN, BASIC.TEXT_COLUMN, BASIC.VARCHAR_COLUMN, BASIC.MAP_COLUMN, BASIC.ARRAY_COLUMN, BASIC.SET_COLUMN). From(BASIC). Fetch(session) if err != nil { log.Fatalf("Could not bind data: %v", err) os.Exit(1) } result, _ = checkBasics(iter, basic) // TODO write test case for a non-matching WHERE clause os.Stdout.WriteString(result) }
func main() { session := integration.TestSession("127.0.0.1", "cqlc") integration.Truncate(session, EVENTS) result := "FAILED" ctx := cqlc.NewContext() batch := gocql.NewBatch(gocql.LoggedBatch) events := 50 * 1000 batchSize := 1000 for i := 0; i < events; i++ { ctx.Upsert(EVENTS). SetInt64(EVENTS.SENSOR, int64(i)). SetTimeUUID(EVENTS.TIMESTAMP, gocql.TimeUUID()). SetFloat32(EVENTS.TEMPERATURE, 19.8). SetInt32(EVENTS.PRESSURE, 357). Batch(batch) if i%batchSize == 0 { if err := session.ExecuteBatch(batch); err != nil { log.Fatalf("Could not execute batch: %v", err) os.Exit(1) } batch = gocql.NewBatch(gocql.LoggedBatch) } } err := session.ExecuteBatch(batch) if err != nil { log.Fatalf("Could not execute batch: %v", err) os.Exit(1) } query, err := ctx.Select().From(EVENTS).Prepare(session) if err != nil { log.Fatalf("Could not prepare query: %v", err) os.Exit(1) } query.PageSize(100) iter := query.Iter() count := 0 MapEvents(iter, func(e Events) (bool, error) { count++ return true, nil }) if err := iter.Close(); err != nil { log.Fatalf("Could not close iterator: %v", err) os.Exit(1) } if count == events { result = "PASSED" } os.Stdout.WriteString(result) }
func main() { session := integration.TestSession("127.0.0.1", "cqlc") integration.Truncate(session, EVENTS) result := "FAILED" ctx := cqlc.NewContext() batch := gocql.NewBatch(gocql.LoggedBatch) events := 100 for i := 0; i < events; i++ { ctx.Upsert(EVENTS). SetInt64(EVENTS.SENSOR, int64(100)). SetTimeUUID(EVENTS.TIMESTAMP, gocql.TimeUUID()). SetFloat32(EVENTS.TEMPERATURE, 19.8). SetInt32(EVENTS.PRESSURE, 357). Batch(batch) } if err := session.ExecuteBatch(batch); err != nil { log.Fatalf("Could not execute batch: %v", err) os.Exit(1) } limit := 11 iter, err := ctx.Select(EVENTS.SENSOR). From(EVENTS). Limit(limit). Fetch(session) if err != nil { log.Fatalf("Could not execute query: %v", err) os.Exit(1) } count := 0 MapEvents(iter, func(e Events) (bool, error) { count++ return true, nil }) if count == limit { limit = 14 iter, err = ctx.Select(). From(EVENTS). Where(EVENTS.SENSOR.Eq(int64(100))). Limit(limit). Fetch(session) count := 0 MapEvents(iter, func(e Events) (bool, error) { count++ return true, nil }) if count == limit { result = "PASSED" } else { result = fmt.Sprintf("Expected limit of %d; got %d rows", limit, count) } } else { result = fmt.Sprintf("Expected limit of %d; got %d rows", limit, count) } if err != nil { log.Fatalf("Could not execute query: %v", err) os.Exit(1) } os.Stdout.WriteString(result) }
func main() { session := integration.TestSession("127.0.0.1", "cqlc") integration.Truncate(session, USER_ACCOUNTS) result := "FAILED" ctx := cqlc.NewContext() batch := gocql.NewBatch(gocql.LoggedBatch) f, err := os.Open(os.Args[1]) if err != nil { log.Fatalf("Could not open CSV file: %s", err) os.Exit(1) } b, err := csvb.NewBinder(f, nil) if err != nil { log.Fatalf("Could not create binder: %s", err) os.Exit(1) } s := make(map[string]string) s["username"] = "******" s["email"] = "Email" s["password"] = "******" s["last_visited"] = "LastVisited" s["country"] = "Country" err = b.ForEach(func(row csvb.Row) (bool, error) { var u UserAccounts if err := row.Bind(&u, s); err != nil { return false, err } ctx.Store(USER_ACCOUNTS.Bind(u)).Batch(batch) return true, nil }) if err != nil { log.Fatalf("Could not bind CSV file: %s", err) os.Exit(1) } if err := session.ExecuteBatch(batch); err != nil { log.Fatalf("Could not execute batch: %v", err) os.Exit(1) } iter, err := ctx.Select(). From(USER_ACCOUNTS). Where(USER_ACCOUNTS.COUNTRY.Eq("uk")). Fetch(session) if err != nil { log.Fatalf("Could not query by secondary index: %s", err) os.Exit(1) } count := 0 err = MapUserAccounts(iter, func(u UserAccounts) (bool, error) { count++ if u.Country != "uk" { return false, fmt.Errorf("Expected country %s; got %s", "uk", u.Country) } return true, nil }) if err != nil { log.Fatalf("Could not query by secondary index: %s", err) os.Exit(1) } if count == 1 { result = "PASSED" } os.Stdout.WriteString(result) }
func main() { session := integration.TestSession("127.0.0.1", "cqlc") integration.Truncate(session, SIGNIFICANT_EVENTS) result := "FAILED" ctx := cqlc.NewContext() batch := gocql.NewBatch(gocql.LoggedBatch) events := 100 var first, last gocql.UUID for i := 0; i < events; i++ { ts := gocql.TimeUUID() ctx.Upsert(SIGNIFICANT_EVENTS). SetInt64(SIGNIFICANT_EVENTS.SENSOR, 100). SetTimeUUID(SIGNIFICANT_EVENTS.TIMESTAMP, ts). SetInt32(SIGNIFICANT_EVENTS.SIGNIFICANCE, int32(i/10)). SetFloat32(SIGNIFICANT_EVENTS.TEMPERATURE, 19.8). SetInt32(SIGNIFICANT_EVENTS.PRESSURE, 357). Batch(batch) switch i { case 0: first = ts case events - 1: last = ts } } if err := session.ExecuteBatch(batch); err != nil { log.Fatalf("Could not execute batch: %v", err) os.Exit(1) } count, err := checkOrdering(session, SIGNIFICANT_EVENTS.TIMESTAMP) if err != nil { log.Fatal(err) os.Exit(1) } if count == events { count, err = checkOrdering(session, SIGNIFICANT_EVENTS.TIMESTAMP.Desc()) if err != nil { log.Fatal(err) os.Exit(1) } if count == events { firstRead, err := checkOrderedLimit(session, SIGNIFICANT_EVENTS.TIMESTAMP, SIGNIFICANT_EVENTS.SIGNIFICANCE) if err != nil { log.Fatal(err) os.Exit(1) } lastRead, err := checkOrderedLimit(session, SIGNIFICANT_EVENTS.TIMESTAMP.Desc()) if err != nil { log.Fatal(err) os.Exit(1) } if first == firstRead { if last == lastRead { result = "PASSED" } else { result = fmt.Sprintf("Expected last %v; got %v", last.Time(), lastRead.Time()) } } else { result = fmt.Sprintf("Expected first %v; got %v", first.Time(), firstRead.Time()) } } } else { result = fmt.Sprintf("Expected %d rows; got %d rows", events, count) } os.Stdout.WriteString(result) }