Skip to content

Commit 1e366b1

Browse files
authored
Merge pull request #3214 from dolthub/angela/pipes_as_concat
Implement `PIPES_AS_CONCAT` mode
2 parents 03b6054 + 643b852 commit 1e366b1

File tree

5 files changed

+122
-5
lines changed

5 files changed

+122
-5
lines changed

enginetest/queries/script_queries.go

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12140,6 +12140,108 @@ select * from t1 except (
1214012140
},
1214112141
},
1214212142
},
12143+
{
12144+
Name: "pipes as concat mode",
12145+
Dialect: "mysql",
12146+
SetUpScript: []string{
12147+
"create table names(first_name varchar(20), last_name varchar(20))",
12148+
"insert into names values ('john', 'smith'), ('bob','burger')",
12149+
},
12150+
Assertions: []ScriptTestAssertion{
12151+
{
12152+
Query: "select true || false",
12153+
Expected: []sql.Row{{true}},
12154+
},
12155+
{
12156+
Query: "select '0' || '0'",
12157+
Expected: []sql.Row{{false}},
12158+
},
12159+
{
12160+
Query: "select 'Hello' || ' ' || 'World'",
12161+
Expected: []sql.Row{{false}},
12162+
},
12163+
{
12164+
Query: "select 1 || 0",
12165+
Expected: []sql.Row{{true}},
12166+
},
12167+
{
12168+
Query: "select first_name || ' ' || last_name as full_name from names order by full_name",
12169+
Expected: []sql.Row{{false}, {false}},
12170+
},
12171+
{
12172+
Query: "select 1 + 2 || 3 + 4",
12173+
Expected: []sql.Row{{true}},
12174+
},
12175+
{
12176+
Query: "select true || 1 || 'abc'",
12177+
Expected: []sql.Row{{true}},
12178+
},
12179+
{
12180+
Query: "select (1 || 2) || (3 || 4)",
12181+
Expected: []sql.Row{{true}},
12182+
},
12183+
{
12184+
Query: "select (1 + 2) || (3 + 4)",
12185+
Expected: []sql.Row{{true}},
12186+
},
12187+
{
12188+
Query: "select ((1 || 2) || 3) || 4",
12189+
Expected: []sql.Row{{true}},
12190+
},
12191+
{
12192+
Query: "select ((1 + 2) || 3) + 4",
12193+
Expected: []sql.Row{{5}},
12194+
},
12195+
{
12196+
Query: "SET SESSION sql_mode = CONCAT(@@SESSION.sql_mode, ',PIPES_AS_CONCAT');",
12197+
Expected: []sql.Row{{types.NewOkResult(0)}},
12198+
},
12199+
{
12200+
Query: "select true || false",
12201+
Expected: []sql.Row{{"10"}},
12202+
},
12203+
{
12204+
Query: "select '0' || '0'",
12205+
Expected: []sql.Row{{"00"}},
12206+
},
12207+
{
12208+
Query: "select 'Hello' || ' ' || 'World'",
12209+
Expected: []sql.Row{{"Hello World"}},
12210+
},
12211+
{
12212+
Query: "select 1 || 0",
12213+
Expected: []sql.Row{{"10"}},
12214+
},
12215+
{
12216+
Query: "select first_name || ' ' || last_name as full_name from names order by full_name",
12217+
Expected: []sql.Row{{"bob burger"}, {"john smith"}},
12218+
},
12219+
{
12220+
Query: "select 1 + 2 || 3 + 4",
12221+
Expected: []sql.Row{{float64(28)}},
12222+
},
12223+
{
12224+
Query: "select true || 1 || 'abc'",
12225+
Expected: []sql.Row{{"11abc"}},
12226+
},
12227+
{
12228+
Query: "select (1 || 2) || (3 || 4)",
12229+
Expected: []sql.Row{{"1234"}},
12230+
},
12231+
{
12232+
Query: "select (1 + 2) || (3 + 4)",
12233+
Expected: []sql.Row{{"37"}},
12234+
},
12235+
{
12236+
Query: "select ((1 || 2) || 3) || 4",
12237+
Expected: []sql.Row{{"1234"}},
12238+
},
12239+
{
12240+
Query: "select ((1 + 2) || 3) + 4",
12241+
Expected: []sql.Row{{float64(37)}},
12242+
},
12243+
},
12244+
},
1214312245
}
1214412246

1214512247
var SpatialScriptTests = []ScriptTest{

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/dolthub/go-icu-regex v0.0.0-20250820171420-f2b78f56ce9f
77
github.com/dolthub/jsonpath v0.0.2-0.20240227200619-19675ab05c71
88
github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81
9-
github.com/dolthub/vitess v0.0.0-20250902225707-0159e964d73d
9+
github.com/dolthub/vitess v0.0.0-20250915221346-753c44800850
1010
github.com/go-sql-driver/mysql v1.9.3
1111
github.com/gocraft/dbr/v2 v2.7.2
1212
github.com/google/uuid v1.3.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81 h1:7/v8q9X
2020
github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81/go.mod h1:siLfyv2c92W1eN/R4QqG/+RjjX5W2+gCTRjZxBjI3TY=
2121
github.com/dolthub/vitess v0.0.0-20250902225707-0159e964d73d h1:oTWJxjzRmuHKuICUunCUwNuonubkXwOqPa5hXX3dXBo=
2222
github.com/dolthub/vitess v0.0.0-20250902225707-0159e964d73d/go.mod h1:tV3BrIVyDWVkkYy8dKt2o6hjJ89cHb5opY5FpCyhncQ=
23+
github.com/dolthub/vitess v0.0.0-20250915221346-753c44800850 h1:QXkIRTquxaGUgKVHnKZxU+ikARdszUUDU6C9B/76+a0=
24+
github.com/dolthub/vitess v0.0.0-20250915221346-753c44800850/go.mod h1:tV3BrIVyDWVkkYy8dKt2o6hjJ89cHb5opY5FpCyhncQ=
2325
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
2426
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
2527
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=

sql/sql_mode.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const (
3030
NoAutoValueOnZero = "NO_AUTO_VALUE_ON_ZERO"
3131
NoEngineSubstitution = "NO_ENGINE_SUBSTITUTION"
3232
StrictTransTables = "STRICT_TRANS_TABLES"
33+
PipesAsConcat = "PIPES_AS_CONCAT"
3334
DefaultSqlMode = "NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES"
3435
)
3536

@@ -98,6 +99,11 @@ func (s *SqlMode) AnsiQuotes() bool {
9899
return s.ModeEnabled(ANSIQuotes) || s.ModeEnabled(ANSI)
99100
}
100101

102+
// PipesAsConcat returns true if PIPES_AS_CONCAT SQL mode is enabled.
103+
func (s *SqlMode) PipesAsConcat() bool {
104+
return s.ModeEnabled(PipesAsConcat)
105+
}
106+
101107
// ModeEnabled returns true if |mode| was explicitly specified in the SQL_MODE string that was used to
102108
// create this SqlMode instance. Note this function does not support expanding compound modes into the
103109
// individual modes they contain (e.g. if "ANSI" is the SQL_MODE string, then this function will not
@@ -111,7 +117,8 @@ func (s *SqlMode) ModeEnabled(mode string) bool {
111117
// ParserOptions returns a ParserOptions struct, with options set based on what SQL modes are enabled.
112118
func (s *SqlMode) ParserOptions() sqlparser.ParserOptions {
113119
return sqlparser.ParserOptions{
114-
AnsiQuotes: s.AnsiQuotes(),
120+
AnsiQuotes: s.AnsiQuotes(),
121+
PipesAsConcat: s.PipesAsConcat(),
115122
}
116123
}
117124

sql/sql_mode_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ func TestSqlMode(t *testing.T) {
3030
assert.False(t, sqlMode.ModeEnabled("fake_mode"))
3131
assert.True(t, sqlMode.ParserOptions().AnsiQuotes)
3232
assert.Equal(t, "ANSI,ONLY_FULL_GROUP_BY", sqlMode.String())
33+
assert.False(t, sqlMode.PipesAsConcat())
34+
assert.False(t, sqlMode.ModeEnabled("pipes_as_concat"))
3335

3436
// Test a mixed case SQL_MODE string where only ANSI_QUOTES is enabled
3537
sqlMode = NewSqlModeFromString("AnSi_quotEs")
@@ -39,12 +41,16 @@ func TestSqlMode(t *testing.T) {
3941
assert.False(t, sqlMode.ModeEnabled("fake_mode"))
4042
assert.True(t, sqlMode.ParserOptions().AnsiQuotes)
4143
assert.Equal(t, "ANSI_QUOTES", sqlMode.String())
44+
assert.False(t, sqlMode.PipesAsConcat())
45+
assert.False(t, sqlMode.ModeEnabled("pipes_as_concat"))
4246

43-
// Test when SQL_MODE does not include ANSI_QUOTES
44-
sqlMode = NewSqlModeFromString("ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES")
47+
// Test when SQL_MODE does not include ANSI_QUOTES, includes PIPES_AS_CONCAT
48+
sqlMode = NewSqlModeFromString("ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,PIPES_AS_CONCAT")
4549
assert.False(t, sqlMode.AnsiQuotes())
4650
assert.True(t, sqlMode.ModeEnabled("STRICT_TRANS_TABLES"))
4751
assert.False(t, sqlMode.ModeEnabled("ansi_quotes"))
4852
assert.False(t, sqlMode.ParserOptions().AnsiQuotes)
49-
assert.Equal(t, "ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES", sqlMode.String())
53+
assert.True(t, sqlMode.PipesAsConcat())
54+
assert.True(t, sqlMode.ModeEnabled("pipes_as_concat"))
55+
assert.Equal(t, "ONLY_FULL_GROUP_BY,PIPES_AS_CONCAT,STRICT_TRANS_TABLES", sqlMode.String())
5056
}

0 commit comments

Comments
 (0)