nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: honeycombio/honeycomb-kubernetes-agent
Pull request #304 (2022-11-16 13:07:31)

Add support for building sample keys from integer fields
## Which problem is this PR solving?
If an dynamic sampler is configured to user an event field that is an int, not int64, the field is ignored. This can lead to inconsistent dynamic keys being used.

In the case only integer fields are used, eg a status field, it would result in an key `""`.

## Short description of the changes
- Add support for int field types when building an event key to use with the dynamic sampler
- Add unit test to



Patch:
diff --git a/processors/sample.go b/processors/sample.go
index b5b44e9..b1a3a71 100644
--- a/processors/sample.go
+++ b/processors/sample.go
@@ -88,10 +88,11 @@ func makeDynSampleKey(ev *event.Event, keys []string) string {
 			switch val := val.(type) {
 			case bool:
 				key[i] = strconv.FormatBool(val)
+			case int:
+				key[i] = strconv.Itoa(val)
 			case int64:
 				key[i] = strconv.FormatInt(val, 10)
 			case float64:
-
 				key[i] = strconv.FormatFloat(val, 'E', -1, 64)
 			case string:
 				key[i] = val


Test patch:
diff --git a/processors/sample_test.go b/processors/sample_test.go
new file mode 100644
index 0000000..820b57e
--- /dev/null
+++ b/processors/sample_test.go
@@ -0,0 +1,17 @@
+package processors
+
+import (
+	"testing"
+
+	"github.com/honeycombio/honeycomb-kubernetes-agent/event"
+	"github.com/stretchr/testify/assert"
+)
+
+func TestSamplerCanBuildsKeysWithInts(t *testing.T) {
+	key := makeDynSampleKey(&event.Event{
+		Data: map[string]interface{}{
+			"status": 200,
+		},
+	}, []string { "status"})
+	assert.Equal(t, "200", key)
+}
Repository: honeycombio/honeycomb-kubernetes-agent
Pull request #331 (2023-01-19 20:48:25)

maint: don't spam the logs with filtered-out filenames

## Which problem is this PR solving?

- #324 identified log spam as an issue with the filters. this fixes that part of that issue, but does NOT fix the issue itself.

## Short description of the changes

- Keep a map of files we've already complained about, and don't complain again. 


kentquirk: > Any tests possible in tailer_test.go?

I added a test that checks that a file was added to the map appropriately, but can't test the logging directly.

Patch:
diff --git a/tailer/tailer.go b/tailer/tailer.go
index 38b0bd9..6fa65c0 100644
--- a/tailer/tailer.go
+++ b/tailer/tailer.go
@@ -123,6 +123,7 @@ type PathWatcher struct {
 	handlerFactory handlers.LineHandlerFactory
 	stateRecorder  StateRecorder
 	checkInterval  time.Duration
+	filteredOut    map[string]struct{}
 
 	stop         chan bool
 	savedPattern string
@@ -142,6 +143,7 @@ func NewPathWatcher(
 		stateRecorder:  stateRecorder,
 		checkInterval:  time.Second, // TODO make configurable
 		stop:           make(chan bool),
+		filteredOut:    make(map[string]struct{}),
 	}
 
 	return p
@@ -217,9 +219,12 @@ func (p *PathWatcher) check() {
 		_, ok := p.tailers[file]
 		if !ok {
 			if p.filter != nil && !p.filter(file) {
-				logrus.WithFields(logrus.Fields{
-					"file": file,
-				}).Warn("File filtered out of tailing list")
+				if _, alreadyLogged := p.filteredOut[file]; !alreadyLogged {
+					logrus.WithFields(logrus.Fields{
+						"file": file,
+					}).Warn("File filtered out of tailing list")
+					p.filteredOut[file] = struct{}{}
+				}
 				continue
 			}
 			handler := p.handlerFactory.New(file)


Test patch:
diff --git a/tailer/tailer_test.go b/tailer/tailer_test.go
index 2ae23be..dcab07a 100644
--- a/tailer/tailer_test.go
+++ b/tailer/tailer_test.go
@@ -6,6 +6,7 @@ import (
 	"os"
 	"path"
 	"path/filepath"
+	"strings"
 	"testing"
 	"time"
 
@@ -118,7 +119,7 @@ func TestPathWatching(t *testing.T) {
 
 	watcher := NewPathWatcher(
 		func() (string, error) { return fmt.Sprintf("%s/*", dir), nil },
-		nil,
+		func(s string) bool { return !strings.HasSuffix(s, ".gz") },
 		handlerFactory,
 		stateRecorder,
 	)
@@ -136,6 +137,8 @@ func TestPathWatching(t *testing.T) {
 		err := loggers[i].Write()
 		assert.NoError(t, err)
 	}
+	gzfile, err := ioutil.TempFile(dir, "honeycomb-log-test-gzfile-*.gz")
+	assert.NoError(t, err)
 
 	// The PathWatcher only checks once a second, so we should sleep for slightly longer than that.
 	time.Sleep(2000 * time.Millisecond)
@@ -159,6 +162,11 @@ func TestPathWatching(t *testing.T) {
 		assert.Equal(t, 2, len(h.lines))
 	}
 	assert.Equal(t, len(watcher.tailers), 0)
+
+	// Test that we checked for this filename and added it to the filteredOut list
+	// (we can't test the logging because it's a global logrus)
+	_, foundFilename := watcher.filteredOut[gzfile.Name()]
+	assert.True(t, foundFilename)
 }
 
 func TestTailingWithoutStateRecorder(t *testing.T) {
Repository: ariga/atlas
Pull request #925 (2022-07-08 17:57:15)

sql/sqltool: fix small typo


Patch:
diff --git a/sql/sqltool/tool.go b/sql/sqltool/tool.go
index 5e080d81..08d4cda4 100644
--- a/sql/sqltool/tool.go
+++ b/sql/sqltool/tool.go
@@ -57,8 +57,8 @@ var (
 // implementation compatible with golang-migrate/migrate.
 type GolangMigrateDir struct{ *migrate.LocalDir }
 
-// NewGolandMigrateDir returns a new GolangMigrateDir.
-func NewGolandMigrateDir(path string) (*GolangMigrateDir, error) {
+// NewGolangMigrateDir returns a new GolangMigrateDir.
+func NewGolangMigrateDir(path string) (*GolangMigrateDir, error) {
 	dir, err := migrate.NewLocalDir(path)
 	if err != nil {
 		return nil, err


Test patch:
diff --git a/sql/sqltool/tool_test.go b/sql/sqltool/tool_test.go
index add53bb6..0f0f245a 100644
--- a/sql/sqltool/tool_test.go
+++ b/sql/sqltool/tool_test.go
@@ -113,7 +113,7 @@ CREATE TABLE t2(c int);
 }
 
 func TestScanners(t *testing.T) {
-	d, err := sqltool.NewGolandMigrateDir("testdata/golang-migrate")
+	d, err := sqltool.NewGolangMigrateDir("testdata/golang-migrate")
 	require.NoError(t, err)
 
 	files, err := d.Files()
Repository: ariga/atlas
Pull request #1012 (2022-08-03 14:53:32)

doc/website: keep sidebar title shorter


Patch:
diff --git a/doc/website/sidebars.js b/doc/website/sidebars.js
index 2a474c57..ef768a58 100644
--- a/doc/website/sidebars.js
+++ b/doc/website/sidebars.js
@@ -35,8 +35,8 @@ module.exports = {
             label: "Versioned Workflows",
             collapsed: false,
             items: [
-                {type: 'doc', id: 'versioned/diff', label: 'Planning Migrations'},
-                {type: 'doc', id: 'versioned/lint', label: 'Verifying Migration Safety'},
+                {type: 'doc', id: 'versioned/diff', label: 'Migration Planning'},
+                {type: 'doc', id: 'versioned/lint', label: 'Migration Linting'},
             ]
         },
         {
diff --git a/schemahcl/opts.go b/schemahcl/opts.go
index 956261df..299f16cf 100644
--- a/schemahcl/opts.go
+++ b/schemahcl/opts.go
@@ -5,6 +5,7 @@
 package schemahcl
 
 import (
+	"errors"
 	"fmt"
 	"reflect"
 
@@ -103,7 +104,11 @@ func rawExprImpl() function.Function {
 		},
 		Type: function.StaticReturnType(ctyRawExpr),
 		Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
-			t := &RawExpr{X: args[0].AsString()}
+			x := args[0].AsString()
+			if len(x) == 0 {
+				return cty.NilVal, errors.New("empty expression")
+			}
+			t := &RawExpr{X: x}
 			return cty.CapsuleVal(ctyRawExpr, t), nil
 		},
 	})


Test patch:
diff --git a/schemahcl/context_test.go b/schemahcl/context_test.go
index d02ead43..01737c28 100644
--- a/schemahcl/context_test.go
+++ b/schemahcl/context_test.go
@@ -412,6 +412,13 @@ variadic = enum("a","b","c")
 	require.EqualValues(t, f, string(after))
 }
 
+func TestEmptyStrSQL(t *testing.T) {
+	s := New(WithTypes(nil))
+	h := `x = sql("")`
+	err := s.EvalBytes([]byte(h), &struct{}{}, nil)
+	require.ErrorContains(t, err, "empty expression")
+}
+
 func TestOptionalArgs(t *testing.T) {
 	s := New(
 		WithTypes([]*TypeSpec{
Repository: ariga/atlas
Pull request #1087 (2022-08-23 07:17:49)

sql/migrate: support mysql comments marked with #


Patch:
diff --git a/sql/migrate/lex.go b/sql/migrate/lex.go
index 17f81a8b..23fc2ce1 100644
--- a/sql/migrate/lex.go
+++ b/sql/migrate/lex.go
@@ -96,6 +96,8 @@ func (l *lex) stmt() (stmt string, err error) {
 			if err := l.skipQuote(r); err != nil {
 				return "", err
 			}
+		case r == '#':
+			l.skipComment("#", "\n")
 		case r == '-' && l.next() == '-':
 			l.skipComment("--", "\n")
 		case r == '/' && l.next() == '*':


Test patch:
diff --git a/sql/migrate/testdata/lex/6_skip_comment.sql b/sql/migrate/testdata/lex/6_skip_comment.sql
index 1144b016..939292aa 100644
--- a/sql/migrate/testdata/lex/6_skip_comment.sql
+++ b/sql/migrate/testdata/lex/6_skip_comment.sql
@@ -1,11 +1,15 @@
 -- comment 1
 CREATE TABLE t1(id int);
+# CREATE TABLE t1(id int);
 
 -- comment 2
+# CREATE TABLE t2(id int);
 CREATE TABLE t2(id int);
 -- comment 3
 CREATE TABLE t3(id int);
 
+# CREATE TABLE t3(id int);
+
 /* comment 4 */
 CREATE TABLE t4(
     id int
Repository: ariga/atlas
Pull request #1116 (2022-09-01 06:48:34)

sql/migrate: extract directives from comments


Patch:
diff --git a/sql/migrate/lex.go b/sql/migrate/lex.go
index 77ca9a14..6842e07e 100644
--- a/sql/migrate/lex.go
+++ b/sql/migrate/lex.go
@@ -20,6 +20,26 @@ type Stmt struct {
 	Comments []string // associated comments
 }
 
+// Directive returns all directive comments with the given name.
+// See: pkg.go.dev/cmd/compile#hdr-Compiler_Directives.
+func (s *Stmt) Directive(name string) (ds []string) {
+	for _, c := range s.Comments {
+		switch {
+		case strings.HasPrefix(c, "/*") && !strings.Contains(c, "\n"):
+			if d, ok := directive(strings.TrimSuffix(c, "*/"), name, "/*"); ok {
+				ds = append(ds, d)
+			}
+		default:
+			for _, p := range []string{"#", "--", "-- "} {
+				if d, ok := directive(c, name, p); ok {
+					ds = append(ds, d)
+				}
+			}
+		}
+	}
+	return
+}
+
 // stmts provides a generic implementation for extracting
 // SQL statements from the given file contents.
 func stmts(input string) ([]*Stmt, error) {


Test patch:
diff --git a/sql/migrate/lex_test.go b/sql/migrate/lex_test.go
index 7e6b324a..ececa4f5 100644
--- a/sql/migrate/lex_test.go
+++ b/sql/migrate/lex_test.go
@@ -52,10 +52,22 @@ cmd3;
 /* comment1 */
 /* comment2 */
 cmd4;
+
+--atlas:nolint
+-- atlas:nolint destructive
+cmd5;
+
+#atlas:lint error
+/*atlas:nolint DS101*/
+/* atlas:lint not a directive */
+/*
+atlas:lint not a directive
+*/
+cmd6;
 `))
 	stmts, err := f.StmtDecls()
 	require.NoError(t, err)
-	require.Len(t, stmts, 4)
+	require.Len(t, stmts, 6)
 	require.Equal(t, "cmd1;", stmts[0].Text)
 	require.Equal(t, []string{"-- test\n"}, stmts[0].Comments)
 	require.Equal(t, "cmd2;", stmts[1].Text)
@@ -64,4 +76,11 @@ cmd4;
 	require.Equal(t, []string{"# command\n"}, stmts[2].Comments)
 	require.Equal(t, "cmd4;", stmts[3].Text)
 	require.Equal(t, []string{"/* comment1 */", "/* comment2 */"}, stmts[3].Comments)
+	require.Equal(t, "cmd5;", stmts[4].Text)
+	require.Equal(t, []string{"--atlas:nolint\n", "-- atlas:nolint destructive\n"}, stmts[4].Comments)
+	require.Equal(t, []string{"", "destructive"}, stmts[4].Directive("nolint"))
+	require.Equal(t, "cmd6;", stmts[5].Text)
+	require.Equal(t, []string{"#atlas:lint error\n", "/*atlas:nolint DS101*/", "/* atlas:lint not a directive */", "/*\natlas:lint not a directive\n*/"}, stmts[5].Comments)
+	require.Equal(t, []string{"error"}, stmts[5].Directive("lint"))
+	require.Equal(t, []string{"DS101"}, stmts[5].Directive("nolint"))
 }
Repository: ariga/atlas
Pull request #1194 (2022-10-12 20:34:37)

sql/internal/specutil: add index-part attributes to spec
Also, in case of columns-only (not expression) indexes. For example, index a column prefix


Patch:
diff --git a/sql/internal/specutil/convert.go b/sql/internal/specutil/convert.go
index 07f0f288..538cd522 100644
--- a/sql/internal/specutil/convert.go
+++ b/sql/internal/specutil/convert.go
@@ -456,10 +456,6 @@ func normalizeQuotes(s string) (string, error) {
 func FromIndex(idx *schema.Index, partFns ...func(*schema.IndexPart, *sqlspec.IndexPart)) (*sqlspec.Index, error) {
 	spec := &sqlspec.Index{Name: idx.Name, Unique: idx.Unique}
 	convertCommentFromSchema(idx.Attrs, &spec.Extra.Attrs)
-	if parts, ok := columnsOnly(idx); ok {
-		spec.Columns = parts
-		return spec, nil
-	}
 	spec.Parts = make([]*sqlspec.IndexPart, len(idx.Parts))
 	for i, p := range idx.Parts {
 		part := &sqlspec.IndexPart{Desc: p.Desc}
@@ -482,18 +478,23 @@ func FromIndex(idx *schema.Index, partFns ...func(*schema.IndexPart, *sqlspec.In
 		}
 		spec.Parts[i] = part
 	}
+	if parts, ok := columnsOnly(spec.Parts); ok {
+		spec.Parts = nil
+		spec.Columns = parts
+		return spec, nil
+	}
 	return spec, nil
 }
 
-func columnsOnly(idx *schema.Index) ([]*schemahcl.Ref, bool) {
-	parts := make([]*schemahcl.Ref, len(idx.Parts))
-	for i, p := range idx.Parts {
-		if p.C == nil || p.Desc {
+func columnsOnly(parts []*sqlspec.IndexPart) ([]*schemahcl.Ref, bool) {
+	columns := make([]*schemahcl.Ref, len(parts))
+	for i, p := range parts {
+		if p.Desc || p.Column == nil || len(p.Extra.Attrs) != 0 {
 			return nil, false
 		}
-		parts[i] = ColumnRef(p.C.Name)
+		columns[i] = p.Column
 	}
-	return parts, true
+	return columns, true
 }
 
 // FromForeignKey converts schema.ForeignKey to sqlspec.ForeignKey.


Test patch:
diff --git a/sql/mysql/sqlspec_test.go b/sql/mysql/sqlspec_test.go
index 19fd7c22..4512850b 100644
--- a/sql/mysql/sqlspec_test.go
+++ b/sql/mysql/sqlspec_test.go
@@ -639,6 +639,42 @@ func TestMarshalSpec_IndexParts(t *testing.T) {
 }
 schema "test" {
 }
+`
+	require.EqualValues(t, exp, string(buf))
+
+	// Columns only.
+	s = schema.New("test").
+		AddTables(
+			schema.NewTable("users").
+				AddColumns(c, c2).
+				AddIndexes(
+					schema.NewIndex("idx").
+						AddParts(
+							schema.NewColumnPart(c).AddAttrs(&SubPart{Len: 10}),
+						),
+				),
+		)
+	buf, err = MarshalHCL(s)
+	require.NoError(t, err)
+	exp = `table "users" {
+  schema = schema.test
+  column "name" {
+    null = false
+    type = text
+  }
+  column "Full Name" {
+    null = false
+    type = text
+  }
+  index "idx" {
+    on {
+      column = column.name
+      prefix = 10
+    }
+  }
+}
+schema "test" {
+}
 `
 	require.EqualValues(t, exp, string(buf))
 }
Repository: ariga/atlas
Pull request #1275 (2022-11-08 12:30:52)

sql/postgres: expose default diffing capabilities


Patch:
diff --git a/sql/postgres/diff.go b/sql/postgres/diff.go
index 8cf6fd0e..71059fb3 100644
--- a/sql/postgres/diff.go
+++ b/sql/postgres/diff.go
@@ -17,6 +17,11 @@ import (
 	"ariga.io/atlas/sql/schema"
 )
 
+// DefaultDiff provides basic diffing capabilities for PostgreSQL dialects.
+// Note, it is recommended to call Open, create a new Driver and use its Differ
+// when a database connection is available.
+var DefaultDiff schema.Differ = &sqlx.Diff{DiffDriver: &diff{}}
+
 // A diff provides a PostgreSQL implementation for sqlx.DiffDriver.
 type diff struct{ conn }
 
@@ -81,12 +86,16 @@ func (d *diff) defaultChanged(from, to *schema.Column) (bool, error) {
 	if trimCast(d1) == trimCast(d2) || quote(d1) == quote(d2) {
 		return false, nil
 	}
-	// Use database comparison in case of mismatch (e.g. `SELECT ARRAY[1] = '{1}'::int[]`).
-	equals, err := d.valuesEqual(d1, d2)
-	if err != nil {
-		return false, err
+	var (
+		err    error
+		equals bool
+	)
+	// In case a database connection is available (not the DefaultDiff), we use the
+	// database comparison in case of mismatch (e.g. `SELECT ARRAY[1] = '{1}'::int[]`).
+	if d.conn.ExecQuerier != nil {
+		equals, err = d.valuesEqual(d1, d2)
 	}
-	return !equals, nil
+	return !equals, err
 }
 
 // generatedChanged reports if the generated expression of a column was changed.


Test patch:
diff --git a/sql/postgres/diff_test.go b/sql/postgres/diff_test.go
index 73424613..d438b7a7 100644
--- a/sql/postgres/diff_test.go
+++ b/sql/postgres/diff_test.go
@@ -510,3 +510,16 @@ func TestDiff_SchemaDiff(t *testing.T) {
 		&schema.AddTable{T: to.Tables[1]},
 	}, changes)
 }
+
+func TestDefaultDiff(t *testing.T) {
+	changes, err := DefaultDiff.SchemaDiff(
+		schema.New("public").
+			AddTables(
+				schema.NewTable("users").AddColumns(schema.NewIntColumn("id", "int")),
+			),
+		schema.New("public"),
+	)
+	require.NoError(t, err)
+	require.Len(t, changes, 1)
+	require.IsType(t, &schema.DropTable{}, changes[0])
+}