nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: goplus/gop
Pull request #2145 (2025-03-01 11:34:10)

#2143 gop/cl: compileDomainTextLit


Patch:
diff --git a/cl/expr.go b/cl/expr.go
index dc2241e2..da4db1b8 100644
--- a/cl/expr.go
+++ b/cl/expr.go
@@ -387,6 +387,8 @@ func compileExpr(ctx *blockCtx, expr ast.Expr, inFlags ...int) {
 		compileEnvExpr(ctx, v)
 	/* case *ast.MatrixLit:
 	compileMatrixLit(ctx, v) */
+	case *ast.DomainTextLit:
+		compileDomainTextLit(ctx, v)
 	default:
 		panic(ctx.newCodeErrorf(v.Pos(), "compileExpr failed: unknown - %T", v))
 	}
@@ -1071,6 +1073,19 @@ func compileStringLitEx(ctx *blockCtx, cb *gogen.CodeBuilder, lit *ast.BasicLit)
 	}
 }
 
+const (
+	tplPkgPath = "github.com/goplus/gop/tpl"
+)
+
+func compileDomainTextLit(ctx *blockCtx, v *ast.DomainTextLit) {
+	switch v.Domain.Name {
+	case "tpl": // tpl`...` => tpl.new(`...`)
+		ctx.cb.Val(ctx.pkg.Import(tplPkgPath).Ref("New")).
+			Val(&goast.BasicLit{Kind: gotoken.STRING, Value: v.Value}, v).
+			Call(1)
+	}
+}
+
 const (
 	compositeLitVal    = 0
 	compositeLitKeyVal = 1
diff --git a/demo/gop-parser/gopcalc-2/calc.gop b/demo/gop-parser/gopcalc-2/calc.gop
index 384cbf56..ba219945 100644
--- a/demo/gop-parser/gopcalc-2/calc.gop
+++ b/demo/gop-parser/gopcalc-2/calc.gop
@@ -3,16 +3,6 @@ import (
 	"os"
 )
 
-const tplCalc = `
-expr = termExpr % ("+" | "-")
-
-termExpr = unaryExpr % ("*" | "/")
-
-unaryExpr = operand | "-" unaryExpr
-
-operand = INT | FLOAT | "(" expr ")"
-`
-
 func calc(e any) float64 {
 	switch e := e.(type) {
 	case *tpl.Token:
@@ -41,7 +31,16 @@ func calc(e any) float64 {
 	panic("unknown expression")
 }
 
-cl := tpl.new(tplCalc)!
+cl := tpl`
+expr = termExpr % ("+" | "-")
+
+termExpr = unaryExpr % ("*" | "/")
+
+unaryExpr = operand | "-" unaryExpr
+
+operand = INT | FLOAT | "(" expr ")"
+`!
+
 print "> "
 for line <- os.Stdin {
 	e, err := cl.parseExpr(line, nil)


Test patch:
diff --git a/cl/_testgop/domaintext/in.gop b/cl/_testgop/domaintext/in.gop
new file mode 100644
index 00000000..78cac1d1
--- /dev/null
+++ b/cl/_testgop/domaintext/in.gop
@@ -0,0 +1,3 @@
+cl, err := tpl`expr = INT % ("+" | "-")`
+cl.parseExpr "1+2", nil
+_ = err
diff --git a/cl/_testgop/domaintext/out.go b/cl/_testgop/domaintext/out.go
new file mode 100644
index 00000000..af0289cf
--- /dev/null
+++ b/cl/_testgop/domaintext/out.go
@@ -0,0 +1,9 @@
+package main
+
+import "github.com/goplus/gop/tpl"
+
+func main() {
+	cl, err := tpl.New(`expr = INT % ("+" | "-")`)
+	cl.ParseExpr("1+2", nil)
+	_ = err
+}
Repository: goplus/gop
Pull request #2174 (2025-03-13 07:36:40)

cl: compileErrWrapExpr check callExpr
```
echo foo! => echo foo()!
```


Patch:
diff --git a/cl/expr.go b/cl/expr.go
index c79a67ce..f82ac816 100644
--- a/cl/expr.go
+++ b/cl/expr.go
@@ -1520,8 +1520,12 @@ func compileErrWrapExpr(ctx *blockCtx, v *ast.ErrWrapExpr, inFlags int) {
 	if !useClosure && (cb.Scope().Parent() == types.Universe) {
 		panic("TODO: can't use expr? in global")
 	}
-
-	compileExpr(ctx, v.X, inFlags)
+	expr := v.X
+	switch expr.(type) {
+	case *ast.Ident, *ast.SelectorExpr:
+		expr = &ast.CallExpr{Fun: expr}
+	}
+	compileExpr(ctx, expr, inFlags)
 	x := cb.InternalStack().Pop()
 	n := 0
 	results, ok := x.Type.(*types.Tuple)


Test patch:
diff --git a/cl/compile_test.go b/cl/compile_test.go
index b72c4ad3..88521d52 100644
--- a/cl/compile_test.go
+++ b/cl/compile_test.go
@@ -4251,3 +4251,69 @@ func main() {
 }
 `)
 }
+
+func TestErrWrapNoArgs(t *testing.T) {
+	gopClTest(t, `
+func foo(v ...int) (func(), error) {
+	return nil, nil
+}
+func Bar() (int, error) {
+	return 100, nil
+}
+foo!()
+foo(1)!()
+echo foo!
+echo bar!
+`, `package main
+
+import (
+	"fmt"
+	"github.com/qiniu/x/errors"
+)
+
+func foo(v ...int) (func(), error) {
+	return nil, nil
+}
+func Bar() (int, error) {
+	return 100, nil
+}
+func main() {
+	func() (_gop_ret func()) {
+		var _gop_err error
+		_gop_ret, _gop_err = foo()
+		if _gop_err != nil {
+			_gop_err = errors.NewFrame(_gop_err, "foo", "/foo/bar.gop", 8, "main.main")
+			panic(_gop_err)
+		}
+		return
+	}()()
+	func() (_gop_ret func()) {
+		var _gop_err error
+		_gop_ret, _gop_err = foo(1)
+		if _gop_err != nil {
+			_gop_err = errors.NewFrame(_gop_err, "foo(1)", "/foo/bar.gop", 9, "main.main")
+			panic(_gop_err)
+		}
+		return
+	}()()
+	fmt.Println(func() (_gop_ret func()) {
+		var _gop_err error
+		_gop_ret, _gop_err = foo()
+		if _gop_err != nil {
+			_gop_err = errors.NewFrame(_gop_err, "foo", "/foo/bar.gop", 10, "main.main")
+			panic(_gop_err)
+		}
+		return
+	}())
+	fmt.Println(func() (_gop_ret int) {
+		var _gop_err error
+		_gop_ret, _gop_err = Bar()
+		if _gop_err != nil {
+			_gop_err = errors.NewFrame(_gop_err, "bar", "/foo/bar.gop", 11, "main.main")
+			panic(_gop_err)
+		}
+		return
+	}())
+}
+`)
+}
Repository: TobikoData/sqlmesh
Pull request #1820 (2023-12-07 20:01:12)

Fix: Cloud_composer scheduler config supported field validation
The validator used to work in Pydantic v1 since a field's alias defaulted to the field's name if there was no alias specified. In v2, it's None if not specified.


Patch:
diff --git a/sqlmesh/core/config/scheduler.py b/sqlmesh/core/config/scheduler.py
index 8a89acb5..51f75a25 100644
--- a/sqlmesh/core/config/scheduler.py
+++ b/sqlmesh/core/config/scheduler.py
@@ -230,7 +230,7 @@ class CloudComposerSchedulerConfig(_BaseAirflowSchedulerConfig, BaseConfig, extr
     @model_validator(mode="before")
     @model_validator_v1_args
     def check_supported_fields(cls, values: t.Dict[str, t.Any]) -> t.Dict[str, t.Any]:
-        allowed_field_names = {field.alias for field in cls.all_field_infos().values()}
+        allowed_field_names = {field.alias or name for name, field in cls.all_field_infos().items()}
         allowed_field_names.add("session")
 
         for field_name in values:


Test patch:
diff --git a/tests/core/test_config.py b/tests/core/test_config.py
index 7d1de5cb..04d56834 100644
--- a/tests/core/test_config.py
+++ b/tests/core/test_config.py
@@ -295,3 +295,27 @@ def test_load_config_from_python_module_invalid_config_object(tmp_path):
         match=r"^Config needs to be a valid object.*",
     ):
         load_config_from_python_module(config_path)
+
+
+def test_cloud_composer_scheduler_config(tmp_path_factory):
+    config_path = tmp_path_factory.mktemp("yaml_config") / "config.yaml"
+    with open(config_path, "w") as fd:
+        fd.write(
+            """
+gateways:
+    another_gateway:
+        connection:
+            type: duckdb
+            database: test_db
+        scheduler:
+            type: cloud_composer
+            airflow_url: https://airflow.url
+
+model_defaults:
+    dialect: bigquery
+        """
+        )
+
+    assert load_config_from_paths(
+        project_paths=[config_path],
+    )
Repository: TobikoData/sqlmesh
Pull request #1840 (2023-12-15 03:22:21)

fix: parse errors with upgrade


Patch:
diff --git a/sqlmesh/core/dialect.py b/sqlmesh/core/dialect.py
index 1f22a5c5..63fe7f67 100644
--- a/sqlmesh/core/dialect.py
+++ b/sqlmesh/core/dialect.py
@@ -130,7 +130,7 @@ def _parse_id_var(
     tokens: t.Optional[t.Collection[TokenType]] = None,
 ) -> t.Optional[exp.Expression]:
 
-    if self._match(TokenType.L_BRACE):
+    if self._prev and self._prev.text == SQLMESH_MACRO_PREFIX and self._match(TokenType.L_BRACE):
         identifier = self.__parse_id_var(any_token=any_token, tokens=tokens)  # type: ignore
         if not self._match(TokenType.R_BRACE):
             self.raise_error("Expecting }")
@@ -142,15 +142,22 @@ def _parse_id_var(
         identifier
         and self._is_connected()
         and (
-            self._match_texts(("{", SQLMESH_MACRO_PREFIX), advance=False)
+            self._match_texts(("{", SQLMESH_MACRO_PREFIX))
             or self._curr.token_type not in self.RESERVED_TOKENS
         )
     ):
         this = identifier.name
-        brace = self._match(TokenType.L_BRACE)
+        brace = False
 
-        if brace:
+        if self._prev.text == "{":
             this += "{"
+            brace = True
+        else:
+            if self._prev.text == SQLMESH_MACRO_PREFIX:
+                this += "@"
+            if self._match(TokenType.L_BRACE):
+                this += "{"
+                brace = True
 
         next_id = self._parse_id_var(any_token=False)
 


Test patch:
diff --git a/tests/core/test_dialect.py b/tests/core/test_dialect.py
index acbc79d7..8397370b 100644
--- a/tests/core/test_dialect.py
+++ b/tests/core/test_dialect.py
@@ -182,6 +182,8 @@ def test_parse():
     assert isinstance(expressions[2], JinjaQuery)
     assert isinstance(expressions[3], JinjaStatement)
 
+    assert parse_one("{'a': 1}", read="duckdb").sql(dialect="duckdb") == "{'a': 1}"
+
 
 def test_parse_jinja_with_semicolons():
     expressions = parse(
Repository: TobikoData/sqlmesh
Pull request #2597 (2024-05-11 15:22:54)

fix: add runtime stage to jinja


Patch:
diff --git a/sqlmesh/core/renderer.py b/sqlmesh/core/renderer.py
index ef69613a..24a9ea6e 100644
--- a/sqlmesh/core/renderer.py
+++ b/sqlmesh/core/renderer.py
@@ -131,6 +131,7 @@ class BaseExpressionRenderer:
             table_mapping=table_mapping,
             deployability_index=deployability_index,
             default_catalog=self._default_catalog,
+            runtime_stage=runtime_stage.value,
         )
 
         if isinstance(self._expression, d.Jinja):


Test patch:
diff --git a/tests/core/test_model.py b/tests/core/test_model.py
index 21021add..4bdd72b6 100644
--- a/tests/core/test_model.py
+++ b/tests/core/test_model.py
@@ -4141,3 +4141,22 @@ def test_python_model_dialect():
     assert m.time_column.format == "%Y-%m-%d"
 
     model._dialect = None
+
+
+def test_jinja_runtime_stage(assert_exp_eq):
+    expressions = d.parse(
+        """
+        MODEL (
+            name test.jinja
+        );
+
+        JINJA_QUERY_BEGIN;
+
+        SELECT '{{ runtime_stage }}' as a, {{ runtime_stage == 'loading' }} as b
+
+        JINJA_END;
+        """
+    )
+
+    model = load_sql_based_model(expressions)
+    assert_exp_eq(model.render_query(), '''SELECT 'loading' as "a", TRUE as "b"''')
Repository: TobikoData/sqlmesh
Pull request #2610 (2024-05-14 22:17:11)

Fix: Parsing of session properties when only one key-value pair is provided
Expression
```
session_properties (
    'warehouse' = 'test_warehouse'
)
```
is being parsed into the `exp.Paren` expression instead of `exp.Tuple` which was not accounted for while merging the model's values with the default ones.


Patch:
diff --git a/sqlmesh/core/model/definition.py b/sqlmesh/core/model/definition.py
index 39a972d1..b7dc314b 100644
--- a/sqlmesh/core/model/definition.py
+++ b/sqlmesh/core/model/definition.py
@@ -1887,6 +1887,8 @@ def _resolve_session_properties(
     if isinstance(provided, dict):
         session_properties = {k: exp.Literal.string(k).eq(v) for k, v in provided.items()}
     elif provided:
+        if isinstance(provided, exp.Paren):
+            provided = exp.Tuple(expressions=[provided.this])
         session_properties = {expr.this.name: expr for expr in provided}
     else:
         session_properties = {}


Test patch:
diff --git a/tests/core/test_model.py b/tests/core/test_model.py
index ba3ad333..2bf36c02 100644
--- a/tests/core/test_model.py
+++ b/tests/core/test_model.py
@@ -2833,6 +2833,24 @@ def test_model_session_properties(sushi_context):
         "unquoted_identifier": exp.column("unquoted_identifier", quoted=False),
     }
 
+    model = load_sql_based_model(
+        d.parse(
+            """
+        MODEL (
+            name test_schema.test_model,
+            session_properties (
+                'warehouse' = 'test_warehouse'
+            )
+        );
+        SELECT a FROM tbl;
+        """,
+            default_dialect="snowflake",
+        )
+    )
+    assert model.session_properties == {
+        "warehouse": "test_warehouse",
+    }
+
 
 def test_model_jinja_macro_rendering():
     expressions = d.parse(
Repository: TobikoData/sqlmesh
Pull request #2623 (2024-05-16 21:15:52)

fix: don't lower selection
Prior to this change we would lower the selection and then return that lowered selection and use it to check for matching model fqns. This would result in case-sensitive model names not being correctly picked up.

The selector is overwritten by the returned value since part of getting the values is removing any prefix/postfix that exists. I'm not sure why it was lowered in the first place so just removed it.


Patch:
diff --git a/sqlmesh/core/selector.py b/sqlmesh/core/selector.py
index 63da9e25..63216608 100644
--- a/sqlmesh/core/selector.py
+++ b/sqlmesh/core/selector.py
@@ -192,7 +192,7 @@ class Selector:
             selection,
             include_upstream,
             include_downstream,
-        ) = self._get_value_and_dependency_inclusion(selection.lower())
+        ) = self._get_value_and_dependency_inclusion(selection)
 
         matched_models = set()
 


Test patch:
diff --git a/tests/core/test_selector.py b/tests/core/test_selector.py
index 34fd97b8..da8e2e61 100644
--- a/tests/core/test_selector.py
+++ b/tests/core/test_selector.py
@@ -374,6 +374,19 @@ def test_expand_model_selections(
     assert selector.expand_model_selections(selections) == output
 
 
+def test_model_selection_normalized(mocker: MockerFixture, make_snapshot):
+    models: UniqueKeyDict[str, Model] = UniqueKeyDict("models")
+    model = SqlModel(
+        name="`db.test_Model`",
+        query=d.parse_one("SELECT 1 AS a"),
+        tags=["tag1"],
+        dialect="bigquery",
+    )
+    models[model.fqn] = model
+    selector = Selector(mocker.Mock(), models, dialect="bigquery")
+    assert selector.expand_model_selections(["db.test_Model"]) == {'"db"."test_Model"'}
+
+
 @pytest.mark.parametrize(
     "expressions, expected_fqns",
     [
Repository: TobikoData/sqlmesh
Pull request #2714 (2024-05-31 22:14:43)

Fix: yet another edge case related to snowflake staged file syntax
We were previously parsing the table here `COPY INTO @'....' ....` as a staged file path because of the preceding `@`. We want this to be treated as a string template and be rendered accordingly, so it was problematic.

Thankfully, Snowflake's spec shows that staged files can either be like `@var....` or `'@....'`, so `@'...'` can also be unambiguously treated as SQLMesh's syntax.

Reference: https://docs.snowflake.com/en/user-guide/querying-stage



Patch:
diff --git a/sqlmesh/core/dialect.py b/sqlmesh/core/dialect.py
index 25d89a54..de8e711d 100644
--- a/sqlmesh/core/dialect.py
+++ b/sqlmesh/core/dialect.py
@@ -416,7 +416,7 @@ def _parse_table_parts(
 
     if isinstance(table_arg, exp.Var) and table_arg.name.startswith(SQLMESH_MACRO_PREFIX):
         # Macro functions do not clash with the staged file syntax, so we can safely parse them
-        if "(" in table_arg.name:
+        if self._prev.token_type == TokenType.STRING or "(" in table_arg.name:
             self._retreat(index)
             return Parser._parse_table_parts(self, schema=schema, is_db_reference=is_db_reference)
 


Test patch:
diff --git a/tests/core/test_macros.py b/tests/core/test_macros.py
index aa16bcca..6c68aa1b 100644
--- a/tests/core/test_macros.py
+++ b/tests/core/test_macros.py
@@ -154,6 +154,14 @@ def test_macro_var(macro_evaluator):
     assert e.find(exp.Parameter) is e.selects[0]
     assert e.sql(dialect="snowflake") == "SELECT $1 FROM @path (FILE_FORMAT => bla.foo)"
 
+    macro_evaluator.locals = {"x": 1}
+    macro_evaluator.dialect = "snowflake"
+    e = parse_one("COPY INTO @'s3://example/foo_@{x}.csv' FROM a.b.c", read="snowflake")
+    assert (
+        macro_evaluator.transform(e).sql(dialect="snowflake")
+        == "COPY INTO 's3://example/foo_1.csv' FROM a.b.c"
+    )
+
 
 def test_macro_str_replace(macro_evaluator):
     expression = parse_one("""@'@val1, @val2'""")