nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: gocql/gocql
Pull request #1363 (2019-10-16 14:08:18)

query: fixes pagination with query binding
Paging state was not reset in query::Bind which effectively broke
paging when Bind was used.

Fixes: #1364 

dahankzter: What do you think @alourie ? This must be pretty common no?
alourie: @dahankzter yep, sounds about right. Do you think we might reset anything else on `Bind`, it seems as if we're basically running a completely new query at this point.
dahankzter: We may need others but this one was so clear and isolated that I thought it best to send it first.
alourie: Fine by me, I'll merge it as obviously fixing an issue. Thanks!

Patch:
diff --git a/session.go b/session.go
index e06a382..935f632 100644
--- a/session.go
+++ b/session.go
@@ -1072,6 +1072,7 @@ func (q *Query) Idempotent(value bool) *Query {
 // to an existing query instance.
 func (q *Query) Bind(v ...interface{}) *Query {
 	q.values = v
+	q.pageState = nil
 	return q
 }
 


Test patch:
diff --git a/cassandra_test.go b/cassandra_test.go
index b75b95a..20e47b7 100644
--- a/cassandra_test.go
+++ b/cassandra_test.go
@@ -313,6 +313,50 @@ func TestPaging(t *testing.T) {
 	}
 }
 
+func TestPagingWithBind(t *testing.T) {
+	session := createSession(t)
+	defer session.Close()
+
+	if session.cfg.ProtoVersion == 1 {
+		t.Skip("Paging not supported. Please use Cassandra >= 2.0")
+	}
+
+	if err := createTable(session, "CREATE TABLE gocql_test.paging_bind (id int, val int, primary key(id,val))"); err != nil {
+		t.Fatal("create table:", err)
+	}
+	for i := 0; i < 100; i++ {
+		if err := session.Query("INSERT INTO paging_bind (id,val) VALUES (?,?)", 1,i).Exec(); err != nil {
+			t.Fatal("insert:", err)
+		}
+	}
+
+	q := session.Query("SELECT val FROM paging_bind WHERE id = ? AND val < ?",1, 50).PageSize(10)
+	iter := q.Iter()
+	var id int
+	count := 0
+	for iter.Scan(&id) {
+		count++
+	}
+	if err := iter.Close(); err != nil {
+		t.Fatal("close:", err)
+	}
+	if count != 50 {
+		t.Fatalf("expected %d, got %d", 50, count)
+	}
+
+	iter = q.Bind(1, 20).Iter()
+	count = 0
+	for iter.Scan(&id) {
+		count++
+	}
+	if count != 20 {
+		t.Fatalf("expected %d, got %d", 20, count)
+	}
+	if err := iter.Close(); err != nil {
+		t.Fatal("close:", err)
+	}
+}
+
 func TestCAS(t *testing.T) {
 	cluster := createCluster()
 	cluster.SerialConsistency = LocalSerial
Repository: gocql/gocql
Pull request #1443 (2020-05-21 03:41:09)

add types metadata


Patch:
diff --git a/metadata.go b/metadata.go
index 6e4e0eb..e586dd4 100644
--- a/metadata.go
+++ b/metadata.go
@@ -22,9 +22,10 @@ type KeyspaceMetadata struct {
 	Tables          map[string]*TableMetadata
 	Functions       map[string]*FunctionMetadata
 	Aggregates      map[string]*AggregateMetadata
-	// Deprecated: use the MaterializedViews field instead.
+	// Deprecated: use the MaterializedViews field for views and UserTypes field for udts instead.
 	Views             map[string]*ViewMetadata
 	MaterializedViews map[string]*MaterializedViewMetadata
+	UserTypes         map[string]*UserTypeMetadata
 }
 
 // schema metadata for a table (a.k.a. column family)
@@ -120,6 +121,13 @@ type MaterializedViewMetadata struct {
 	baseTableName string
 }
 
+type UserTypeMetadata struct {
+	Keyspace   string
+	Name       string
+	FieldNames []string
+	FieldTypes []TypeInfo
+}
+
 // the ordering of the column with regard to its comparator
 type ColumnOrder bool
 
@@ -325,6 +333,19 @@ func compileMetadata(
 	for i := range views {
 		keyspace.Views[views[i].Name] = &views[i]
 	}
+	// Views currently holds the types and hasn't been deleted for backward compatibility issues.
+	// That's why it's ok to copy Views into Types in this case. For the real Views use MaterializedViews.
+	types := make([]UserTypeMetadata, len(views))
+	for i := range views {
+		types[i].Keyspace = views[i].Keyspace
+		types[i].Name = views[i].Name
+		types[i].FieldNames = views[i].FieldNames
+		types[i].FieldTypes = views[i].FieldTypes
+	}
+	keyspace.UserTypes = make(map[string]*UserTypeMetadata, len(views))
+	for i := range types {
+		keyspace.UserTypes[types[i].Name] = &types[i]
+	}
 	keyspace.MaterializedViews = make(map[string]*MaterializedViewMetadata, len(materializedViews))
 	for _, materializedView := range materializedViews {
 		materializedView.BaseTable = keyspace.Tables[materializedView.baseTableName]


Test patch:
diff --git a/cassandra_test.go b/cassandra_test.go
index 64ebf4e..d06274b 100644
--- a/cassandra_test.go
+++ b/cassandra_test.go
@@ -2478,6 +2478,28 @@ func TestKeyspaceMetadata(t *testing.T) {
 	if !found {
 		t.Fatal("failed to find the view in metadata")
 	}
+	_, found = keyspaceMetadata.UserTypes["basicview"]
+	if !found {
+		t.Fatal("failed to find the types in metadata")
+	}
+	textType := TypeText
+	if flagCassVersion.Before(3, 0, 0) {
+		textType = TypeVarchar
+	}
+	expectedType := UserTypeMetadata{
+		Keyspace:   "gocql_test",
+		Name:       "basicview",
+		FieldNames: []string{"birthday", "nationality", "weight", "height"},
+		FieldTypes: []TypeInfo{
+			NativeType{typ: TypeTimestamp},
+			NativeType{typ: textType},
+			NativeType{typ: textType},
+			NativeType{typ: textType},
+		},
+	}
+	if !reflect.DeepEqual(*keyspaceMetadata.UserTypes["basicview"], expectedType) {
+		t.Fatalf("type is %+v, but expected %+v", keyspaceMetadata.UserTypes["basicview"], expectedType)
+	}
 	if flagCassVersion.Major >= 3 {
 		materializedView, found := keyspaceMetadata.MaterializedViews["view_view"]
 		if !found {
Repository: gocql/gocql
Pull request #1541 (2021-03-02 17:54:43)

Allow [16]byte in marshalUUID

martin-sucha: Hello!

Thank you for the pull request!

Please update documentation of [Marshal](https://pkg.go.dev/github.com/gocql/gocql#Marshal) ([marshal.go:92](https://github.com/gocql/gocql/blob/a04dba85ed25d3091d0c6fba6fc806ecd35067c9/marshal.go#L92)) function as well.

Could you also please [add yourself to AUTHORS file](https://github.com/gocql/gocql/blob/master/CONTRIBUTING.md#minimum-requirement-checklist)?

Patch:
diff --git a/AUTHORS b/AUTHORS
index bfa72dd..bf28c12 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -119,3 +119,4 @@ Dmitriy Kozlov <hummerd@mail.ru>
 Alexey Romanovsky <alexus1024+gocql@gmail.com>
 Jaume Marhuenda Beltran <jaumemarhuenda@gmail.com>
 Piotr Dulikowski <piodul@scylladb.com>
+Árni Dagur <arni@dagur.eu>
\ No newline at end of file
diff --git a/marshal.go b/marshal.go
index e386339..0253277 100644
--- a/marshal.go
+++ b/marshal.go
@@ -70,6 +70,7 @@ type Unmarshaler interface {
 //  list, set                   | map[X]struct{}     |
 //  map                         | map[X]Y            |
 //  uuid, timeuuid              | gocql.UUID         |
+//  uuid, timeuuid              | [16]byte           | raw UUID bytes
 //  uuid, timeuuid              | []byte             | raw UUID bytes, length must be 16 bytes
 //  uuid, timeuuid              | string             | hex representation, see ParseUUID
 //  varint                      | integer types      |
@@ -1773,6 +1774,8 @@ func marshalUUID(info TypeInfo, value interface{}) ([]byte, error) {
 		return nil, nil
 	case UUID:
 		return val.Bytes(), nil
+	case [16]byte:
+		return val[:], nil
 	case []byte:
 		if len(val) != 16 {
 			return nil, marshalErrorf("can not marshal []byte %d bytes long into %s, must be exactly 16 bytes long", len(val), info)


Test patch:
diff --git a/marshal_test.go b/marshal_test.go
index d13f0b1..45f0896 100644
--- a/marshal_test.go
+++ b/marshal_test.go
@@ -95,6 +95,13 @@ var marshalTests = []struct {
 		MarshalError("can not marshal []byte 6 bytes long into timeuuid, must be exactly 16 bytes long"),
 		UnmarshalError("unable to parse UUID: UUIDs must be exactly 16 bytes long"),
 	},
+	{
+		NativeType{proto: 2, typ: TypeTimeUUID},
+		[]byte{0x3d, 0xcd, 0x98, 0x0, 0xf3, 0xd9, 0x11, 0xbf, 0x86, 0xd4, 0xb8, 0xe8, 0x56, 0x2c, 0xc, 0xd0},
+		[16]byte{0x3d, 0xcd, 0x98, 0x0, 0xf3, 0xd9, 0x11, 0xbf, 0x86, 0xd4, 0xb8, 0xe8, 0x56, 0x2c, 0xc, 0xd0},
+		nil,
+		nil,
+	},
 	{
 		NativeType{proto: 2, typ: TypeInt},
 		[]byte("\x00\x00\x00\x00"),
Repository: gocql/gocql
Pull request #1583 (2021-10-05 14:51:59)

Add check for pointer kind to unmarshalUDT
reflect.Value.Elem panics when the value is not a suitable type.
In all other places we check that we received a pointer value,
but the check was missing in unmarshalUDT.

We want to return an error instead of the panic that happened
previously:

```
panic: reflect: call of reflect.Value.Elem on map Value [recovered]
	panic: reflect: call of reflect.Value.Elem on map Value

goroutine 6 [running]:
testing.tRunner.func1.2({0x72af00, 0xc00000e150})
	/usr/local/go/src/testing/testing.go:1209 +0x24e
testing.tRunner.func1()
	/usr/local/go/src/testing/testing.go:1212 +0x218
panic({0x72af00, 0xc00000e150})
	/usr/local/go/src/runtime/panic.go:1038 +0x215
reflect.Value.Elem({0x72dd60, 0xc000108f00, 0xc000108f00})
	/usr/local/go/src/reflect/value.go:1178 +0x15a
github.com/gocql/gocql.unmarshalUDT({0x801eb0, 0xc000028360},
{0xc00001c540, 0x13, 0x13}, {0x72dd60, 0xc000108f00})
	/home/martin/Projects/gocql/marshal.go:2294 +0x69f
github.com/gocql/gocql.Unmarshal({0x801eb0, 0xc000028360},
{0xc00001c540, 0x829974, 0x13}, {0x72dd60, 0xc000108f00})
	/home/martin/Projects/gocql/marshal.go:252 +0x7b1
github.com/gocql/gocql.TestUnmarshalUDT(0xc00011ed00)
	/home/martin/Projects/gocql/marshal_test.go:2218 +0x285
testing.tRunner(0xc00011ed00, 0x79f508)
	/usr/local/go/src/testing/testing.go:1259 +0x102
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:1306 +0x35a
```


Patch:
diff --git a/marshal.go b/marshal.go
index 0253277..c12b45f 100644
--- a/marshal.go
+++ b/marshal.go
@@ -2291,7 +2291,11 @@ func unmarshalUDT(info TypeInfo, data []byte, value interface{}) error {
 		return nil
 	}
 
-	k := reflect.ValueOf(value).Elem()
+	rv := reflect.ValueOf(value)
+	if rv.Kind() != reflect.Ptr {
+		return unmarshalErrorf("can not unmarshal into non-pointer %T", value)
+	}
+	k := rv.Elem()
 	if k.Kind() != reflect.Struct || !k.IsValid() {
 		return unmarshalErrorf("cannot unmarshal %s into %T", info, value)
 	}


Test patch:
diff --git a/marshal_test.go b/marshal_test.go
index 235b63b..00d2dbc 100644
--- a/marshal_test.go
+++ b/marshal_test.go
@@ -1,4 +1,5 @@
-//+build all unit
+//go:build all || unit
+// +build all unit
 
 package gocql
 
@@ -2193,3 +2194,29 @@ func BenchmarkUnmarshalUUID(b *testing.B) {
 		}
 	}
 }
+
+func TestUnmarshalUDT(t *testing.T) {
+	info := UDTTypeInfo{
+		NativeType: NativeType{proto: 4, typ: TypeUDT},
+		Name:       "myudt",
+		KeySpace:   "myks",
+		Elements: []UDTField{
+			{
+				Name: "first",
+				Type: NativeType{proto: 4, typ: TypeAscii},
+			},
+			{
+				Name: "second",
+				Type: NativeType{proto: 4, typ: TypeSmallInt},
+			},
+		},
+	}
+	data := []byte("\x00\x00\x00\x0f\x00\x00\x00\x05Hello\x00\x00\x00\x02\x00\x2a")
+	value := map[string]interface{}{}
+	expectedErr := UnmarshalError("can not unmarshal into non-pointer map[string]interface {}")
+
+	if err := Unmarshal(info, data, value); err != expectedErr {
+		t.Errorf("(%v=>%T): %#v returned error %#v, want %#v.",
+			info, value, value, err, expectedErr)
+	}
+}