apache / apache/cassandra-gocql-driver

Always encode BigInt for time.Time

Open
#1,657 8 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
2.7k
Forks
658
PR merge metrics
No merged PRs in 30d

Description

Please answer these questions before submitting your issue. Thanks!

### What version of Cassandra are you using?
Yugabyte 2.14

### What version of Gocql are you using?
v1.2.1

### What version of Go are you using?
Go 1.19

### What did you do?

```go
package main

import (
"fmt"
"time"

"github.com/gocql/gocql"
)

func main() {
cluster := gocql.NewCluster("127.0.0.1:9042")
db, err := cluster.CreateSession()
if err != nil {
panic(err)
}
err = db.Query("CREATE KEYSPACE IF NOT EXISTS test WITH replication = {'class':'SimpleStrategy', 'replication_factor' : 1};").Exec()
if err != nil {
panic(err)
}
err = db.Query("CREATE TABLE IF NOT EXISTS test.test (a TINYINT, b TIMESTAMP, PRIMARY KEY(a))").Exec()
if err != nil {
panic(err)
}
d := time.Date(2022, time.September, 20, 10, 0, 0, 0, time.UTC)
err = db.Query("INSERT INTO test.test (a, b) VALUES (?, ?)", 1, d).Exec()
if err != nil {
panic(err)
}
var d2 time.Time
err = db.Query("SELECT b FROM test.test WHERE a = ?", 1).Scan(&d2)
if err != nil {
panic(err)
}
fmt.Printf("sent: %v\n", d)
fmt.Printf("got: %v\n", d2)
d2 = time.Time{}
err = db.Query("SELECT b FROM test.test WHERE a = ? AND b = ? ALLOW FILTERING", 1, d).Scan(&d2)
if err != nil {
panic(err)
}
fmt.Printf("sent: %v\n", d)
fmt.Printf("got: %v\n", d2)
d2 = time.Time{}
err = db.Query("SELECT b FROM test.test WHERE a = ? AND b > ? ALLOW FILTERING", 1, time.Time{}).Scan(&d2)
if err != nil {
panic(err)
}
fmt.Printf("sent: %v\n", d)
fmt.Printf("got: %v\n", d2)
}
```

### What did you expect to see?
I expect the last query to not fail with not found.

Ran yugabyte with:
```bash
docker run --rm -it -p 9042:9042 --name yb yugabytedb/yugabyte:2.14.1.0-b36 bash -c "bin/yugabyted start --tserver_flags 'pgsql_proxy_bind_address=0.0.0.0:5433,cql_proxy_bind_address=0.0.0.0:9042' --daemon=false"
```

### What did you see instead?
Instead it panic's because the last query was not found.

---

Related: https://github.com/yugabyte/yugabyte-db/issues/14084

I believe this is because gocql encodes empty `time.Time` values as `[]byte{}` rather than just letting them encode as `-62135596800000`.

Contributor guide

Open the contributing guide

Research direction

Start by running the provided Go reproduction against Yugabyte 2.14, then trace how gocql encodes time.Time values for query parameters, focusing on the empty time.Time case. Done means the final range query no longer fails because the empty value is encoded as the expected timestamp rather than an empty byte slice.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.