From caf4198c6d6e2cf9fd5687e864fc9f3df093e70c Mon Sep 17 00:00:00 2001 From: Jason Fulghum Date: Thu, 17 Oct 2024 13:17:12 -0700 Subject: [PATCH 01/10] Add support for adding unique indexes through alter table --- server/ast/constraint_table_def.go | 25 ++++++++++++------------ testing/go/alter_table_test.go | 31 ++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/server/ast/constraint_table_def.go b/server/ast/constraint_table_def.go index 6c1693a5c7..d7509a1000 100644 --- a/server/ast/constraint_table_def.go +++ b/server/ast/constraint_table_def.go @@ -48,18 +48,19 @@ func nodeUniqueConstraintTableDef( return nil, err } + indexType := "unique" if node.PrimaryKey { - return &vitess.DDL{ - Action: "alter", - Table: tableName, - IfExists: ifExists, - IndexSpec: &vitess.IndexSpec{ - Action: "create", - Type: "primary", - Columns: columns, - }, - }, nil - } else { - return nil, fmt.Errorf("Only PRIMARY KEY constraints are supported currently") + indexType = "primary" } + + return &vitess.DDL{ + Action: "alter", + Table: tableName, + IfExists: ifExists, + IndexSpec: &vitess.IndexSpec{ + Action: "create", + Type: indexType, + Columns: columns, + }, + }, nil } diff --git a/testing/go/alter_table_test.go b/testing/go/alter_table_test.go index 154e681012..ba67f60272 100644 --- a/testing/go/alter_table_test.go +++ b/testing/go/alter_table_test.go @@ -57,6 +57,37 @@ func TestAlterTable(t *testing.T) { }, }, }, + { + Name: "Add Unique Constraint", + SetUpScript: []string{ + "create table t1 (pk int primary key, c1 int);", + "insert into t1 values (1,1);", + "create table t2 (pk int primary key, c1 int);", + "insert into t2 values (1,1);", + }, + Assertions: []ScriptTestAssertion{ + { + // Add a secondary unique index using create index + Query: "CREATE UNIQUE INDEX ON t1(c1);", + Expected: []sql.Row{}, + }, + { + // Test that the unique constraint is working + Query: "INSERT INTO t1 VALUES (2, 1);", + ExpectedErr: "unique", + }, + { + // Add a secondary unique index using alter table + Query: "ALTER TABLE t2 ADD CONSTRAINT uniq1 UNIQUE (c1);", + Expected: []sql.Row{}, + }, + { + // Test that the unique constraint is working + Query: "INSERT INTO t2 VALUES (2, 1);", + ExpectedErr: "unique", + }, + }, + }, { Name: "Add Primary Key", SetUpScript: []string{ From 6d2d79048f916870534c767e59ce21f9ed62bda0 Mon Sep 17 00:00:00 2001 From: Jason Fulghum Date: Thu, 17 Oct 2024 13:47:41 -0700 Subject: [PATCH 02/10] Add support for adding check constraints through alter table --- server/ast/alter_table.go | 2 ++ server/ast/constraint_table_def.go | 37 ++++++++++++++++++++++++++++++ testing/go/alter_table_test.go | 27 ++++++++++++++++++++++ 3 files changed, 66 insertions(+) diff --git a/server/ast/alter_table.go b/server/ast/alter_table.go index 9374c85f9b..12a9a10e77 100644 --- a/server/ast/alter_table.go +++ b/server/ast/alter_table.go @@ -116,6 +116,8 @@ func nodeAlterTableAddConstraint( } switch constraintDef := node.ConstraintDef.(type) { + case *tree.CheckConstraintTableDef: + return nodeCheckConstraintTableDef(constraintDef, tableName, ifExists) case *tree.UniqueConstraintTableDef: return nodeUniqueConstraintTableDef(constraintDef, tableName, ifExists) case *tree.ForeignKeyConstraintTableDef: diff --git a/server/ast/constraint_table_def.go b/server/ast/constraint_table_def.go index d7509a1000..3dec533962 100644 --- a/server/ast/constraint_table_def.go +++ b/server/ast/constraint_table_def.go @@ -22,6 +22,43 @@ import ( "github.com/dolthub/doltgresql/postgres/parser/sem/tree" ) +// nodeCheckConstraintTableDef converts a tree.CheckConstraintTableDef instance +// into a vitess.DDL instance that can be executed by GMS. |tableName| identifies +// the table being altered, and |ifExists| indicates whether the IF EXISTS clause +// was specified. +func nodeCheckConstraintTableDef( + node *tree.CheckConstraintTableDef, + tableName vitess.TableName, + ifExists bool) (*vitess.DDL, error) { + + if node.NoInherit { + return nil, fmt.Errorf("NO INHERIT is not yet supported for check constraints") + } + + expr, err := nodeExpr(node.Expr) + if err != nil { + return nil, err + } + + return &vitess.DDL{ + Action: "alter", + Table: tableName, + IfExists: ifExists, + ConstraintAction: "add", + TableSpec: &vitess.TableSpec{ + Constraints: []*vitess.ConstraintDefinition{ + { + Name: node.Name.String(), + Details: &vitess.CheckConstraintDefinition{ + Expr: expr, + Enforced: true, + }, + }, + }, + }, + }, nil +} + // nodeUniqueConstraintTableDef converts a tree.UniqueConstraintTableDef instance // into a vitess.DDL instance that can be executed by GMS. |tableName| identifies // the table being altered, and |ifExists| indicates whether the IF EXISTS clause diff --git a/testing/go/alter_table_test.go b/testing/go/alter_table_test.go index ba67f60272..17993a9b34 100644 --- a/testing/go/alter_table_test.go +++ b/testing/go/alter_table_test.go @@ -88,6 +88,33 @@ func TestAlterTable(t *testing.T) { }, }, }, + { + Name: "Add Check Constraint", + SetUpScript: []string{ + "create table t1 (pk int primary key, c1 int);", + "insert into t1 values (1,1);", + }, + Assertions: []ScriptTestAssertion{ + { + // Add a check constraint that is already violated by the existing data + Query: "ALTER TABLE t1 ADD CONSTRAINT constraint1 CHECK (c1 > 100);", + ExpectedErr: "violated", + }, + { + // Add a check constraint + Query: "ALTER TABLE t1 ADD CONSTRAINT constraint1 CHECK (c1 < 100);", + Expected: []sql.Row{}, + }, + { + Query: "INSERT INTO t1 VALUES (2, 2);", + Expected: []sql.Row{}, + }, + { + Query: "INSERT INTO t1 VALUES (3, 101);", + ExpectedErr: "violated", + }, + }, + }, { Name: "Add Primary Key", SetUpScript: []string{ From 8471c13e68629aa68ee87cfc12b25e56e39b9182 Mon Sep 17 00:00:00 2001 From: Jason Fulghum Date: Thu, 17 Oct 2024 14:06:57 -0700 Subject: [PATCH 03/10] Add support for dropping check constraints through alter table --- server/ast/alter_table.go | 2 ++ server/ast/constraint_table_def.go | 30 ++++++++++++++++++++++++++++++ testing/go/alter_table_test.go | 17 +++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/server/ast/alter_table.go b/server/ast/alter_table.go index 12a9a10e77..3013dd75fb 100644 --- a/server/ast/alter_table.go +++ b/server/ast/alter_table.go @@ -79,6 +79,8 @@ func nodeAlterTableCmds( statement, err = nodeAlterTableAddColumn(cmd, tableName, ifExists) case *tree.AlterTableDropColumn: statement, err = nodeAlterTableDropColumn(cmd, tableName, ifExists) + case *tree.AlterTableDropConstraint: + statement, err = nodeAlterTableDropConstraint(cmd, tableName, ifExists) case *tree.AlterTableRenameColumn: statement, err = nodeAlterTableRenameColumn(cmd, tableName, ifExists) case *tree.AlterTableSetDefault: diff --git a/server/ast/constraint_table_def.go b/server/ast/constraint_table_def.go index 3dec533962..67a740aced 100644 --- a/server/ast/constraint_table_def.go +++ b/server/ast/constraint_table_def.go @@ -59,6 +59,36 @@ func nodeCheckConstraintTableDef( }, nil } +// nodeAlterTableDropConstraint converts a tree.AlterTableDropConstraint instance +// into a vitess.DDL instance that can be executed by GMS. |tableName| identifies +// the table being altered, and |ifExists| indicates whether the IF EXISTS clause +// was specified. +func nodeAlterTableDropConstraint( + node *tree.AlterTableDropConstraint, + tableName vitess.TableName, + ifExists bool) (*vitess.DDL, error) { + + if node.DropBehavior == tree.DropCascade { + return nil, fmt.Errorf("CASCADE is not yet supported for drop constraint") + } + + if node.IfExists { + return nil, fmt.Errorf("IF EXISTS is not yet supported for drop constraint") + } + + return &vitess.DDL{ + Action: "alter", + Table: tableName, + IfExists: ifExists, + ConstraintAction: "drop", + TableSpec: &vitess.TableSpec{ + Constraints: []*vitess.ConstraintDefinition{ + {Name: node.Constraint.String()}, + }, + }, + }, nil +} + // nodeUniqueConstraintTableDef converts a tree.UniqueConstraintTableDef instance // into a vitess.DDL instance that can be executed by GMS. |tableName| identifies // the table being altered, and |ifExists| indicates whether the IF EXISTS clause diff --git a/testing/go/alter_table_test.go b/testing/go/alter_table_test.go index 17993a9b34..d662c10c9d 100644 --- a/testing/go/alter_table_test.go +++ b/testing/go/alter_table_test.go @@ -115,6 +115,23 @@ func TestAlterTable(t *testing.T) { }, }, }, + { + Name: "Drop Constraint", + SetUpScript: []string{ + "create table t1 (pk int primary key, c1 int);", + "ALTER TABLE t1 ADD CONSTRAINT constraint1 CHECK (c1 > 100);", + }, + Assertions: []ScriptTestAssertion{ + { + Query: "ALTER TABLE t1 DROP CONSTRAINT constraint1;", + Expected: []sql.Row{}, + }, + { + Query: "INSERT INTO t1 VALUES (1, 1);", + Expected: []sql.Row{}, + }, + }, + }, { Name: "Add Primary Key", SetUpScript: []string{ From e587df7547f4403160345b8f292ab23b46934aa3 Mon Sep 17 00:00:00 2001 From: Jason Fulghum Date: Fri, 18 Oct 2024 15:59:41 -0700 Subject: [PATCH 04/10] Changing Literal expressions to include quotes around output strings, to better match GMS implementation and fix problems with column defaults --- server/ast/expr.go | 3 +++ server/expression/literal.go | 9 ++++++++- server/functions/framework/compiled_function.go | 6 +----- server/types/utils.go | 12 ------------ 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/server/ast/expr.go b/server/ast/expr.go index f8abc66291..dcb4c208c5 100644 --- a/server/ast/expr.go +++ b/server/ast/expr.go @@ -710,6 +710,9 @@ func nodeExpr(node tree.Expr) (vitess.Expr, error) { return retExpr, nil case *tree.StrVal: // TODO: determine what to do when node.WasScannedAsBytes() is true + // For string literals, we mark the type as unknown, because Postgres has + // more permissive implicit casting rules for literals than it does for strongly + // typed values from a schema for example. unknownLiteral := pgexprs.NewUnknownLiteral(node.RawString()) return vitess.InjectedExpr{ Expression: unknownLiteral, diff --git a/server/expression/literal.go b/server/expression/literal.go index 7353a208da..226f33c4c4 100644 --- a/server/expression/literal.go +++ b/server/expression/literal.go @@ -251,7 +251,14 @@ func (l *Literal) Resolved() bool { // String implements the sql.Expression interface. func (l *Literal) String() string { - return fmt.Sprintf("%v", l.value) + switch litVal := l.value.(type) { + case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64: + return fmt.Sprintf("%d", litVal) + case string: + return fmt.Sprintf("'%s'", litVal) + default: + return fmt.Sprintf("%v", litVal) + } } // ToVitessLiteral returns the literal as a Vitess literal. This is strictly for situations where GMS is hardcoded to diff --git a/server/functions/framework/compiled_function.go b/server/functions/framework/compiled_function.go index 3d4f35bcc1..81c5aab969 100644 --- a/server/functions/framework/compiled_function.go +++ b/server/functions/framework/compiled_function.go @@ -155,11 +155,7 @@ func (c *CompiledFunction) String() string { if i > 0 { sb.WriteString(", ") } - if doltgresType, ok := param.Type().(pgtypes.DoltgresType); ok { - sb.WriteString(pgtypes.QuoteString(doltgresType.BaseID(), param.String())) - } else { - sb.WriteString(param.String()) - } + sb.WriteString(param.String()) } sb.WriteString(")") return sb.String() diff --git a/server/types/utils.go b/server/types/utils.go index f9fc2e281a..214c537b45 100644 --- a/server/types/utils.go +++ b/server/types/utils.go @@ -16,7 +16,6 @@ package types import ( "fmt" - "strings" "time" "unicode/utf8" @@ -25,17 +24,6 @@ import ( "github.com/dolthub/vitess/go/vt/proto/query" ) -// QuoteString will quote the string according to the type given. This means that some types will quote, and others will -// not, or they may quote in a special way that is unique to that type. -func QuoteString(baseID DoltgresTypeBaseID, str string) string { - switch baseID { - case DoltgresTypeBaseID_Char, DoltgresTypeBaseID_Name, DoltgresTypeBaseID_Text, DoltgresTypeBaseID_VarChar, DoltgresTypeBaseID_Unknown: - return `'` + strings.ReplaceAll(str, `'`, `''`) + `'` - default: - return str - } -} - // truncateString returns a string that has been truncated to the given length. Uses the rune count rather than the // byte count. Returns the input string if it's smaller than the length. Also returns the rune count of the string. func truncateString(val string, runeLimit uint32) (string, uint32) { From b052ace2d4f532352debc2cd2fa28a59e2e38a5f Mon Sep 17 00:00:00 2001 From: Jason Fulghum Date: Fri, 18 Oct 2024 16:00:01 -0700 Subject: [PATCH 05/10] Bumping to latest build from fulghum/doltgres-fixes dev branch --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 0cfb7e7b44..bebbd2df52 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20240827111219-e4bb9ca3442d github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2 github.com/dolthub/go-icu-regex v0.0.0-20240916130659-0118adc6b662 - github.com/dolthub/go-mysql-server v0.18.2-0.20241016193930-58d51b356103 + github.com/dolthub/go-mysql-server v0.18.2-0.20241018225641-706812a88f5c github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216 github.com/dolthub/vitess v0.0.0-20241016191424-d14e107a654e github.com/fatih/color v1.13.0 diff --git a/go.sum b/go.sum index ca8c6facf1..4b4a9e4ea1 100644 --- a/go.sum +++ b/go.sum @@ -226,6 +226,8 @@ github.com/dolthub/go-icu-regex v0.0.0-20240916130659-0118adc6b662 h1:aC17hZD6iw github.com/dolthub/go-icu-regex v0.0.0-20240916130659-0118adc6b662/go.mod h1:KPUcpx070QOfJK1gNe0zx4pA5sicIK1GMikIGLKC168= github.com/dolthub/go-mysql-server v0.18.2-0.20241016193930-58d51b356103 h1:AG0T2y5xORr384R9eALgPpdDVfilmlBjo4tSl+IY6G8= github.com/dolthub/go-mysql-server v0.18.2-0.20241016193930-58d51b356103/go.mod h1:z/GGuH2asedC+lkJA4sx+C3oyRH1HRx8ET6N9AGBVms= +github.com/dolthub/go-mysql-server v0.18.2-0.20241018225641-706812a88f5c h1:tRNOSEgjv9RGWeB5HYN0wUB69TuzBb8eFlbh/UBfLUY= +github.com/dolthub/go-mysql-server v0.18.2-0.20241018225641-706812a88f5c/go.mod h1:z/GGuH2asedC+lkJA4sx+C3oyRH1HRx8ET6N9AGBVms= github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63 h1:OAsXLAPL4du6tfbBgK0xXHZkOlos63RdKYS3Sgw/dfI= github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63/go.mod h1:lV7lUeuDhH5thVGDCKXbatwKy2KW80L4rMT46n+Y2/Q= github.com/dolthub/ishell v0.0.0-20240701202509-2b217167d718 h1:lT7hE5k+0nkBdj/1UOSFwjWpNxf+LCApbRHgnCA17XE= From 560a33daf4cf9dc64ea6d3351363d5c29819f8d7 Mon Sep 17 00:00:00 2001 From: Jason Fulghum Date: Mon, 21 Oct 2024 09:57:33 -0700 Subject: [PATCH 06/10] Bumping to latest build from fulghum/doltgres-fixes dev branch --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index b15c82f7e1..b26a1c81fa 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20240827111219-e4bb9ca3442d github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2 github.com/dolthub/go-icu-regex v0.0.0-20240916130659-0118adc6b662 - github.com/dolthub/go-mysql-server v0.18.2-0.20241018220726-63ed221b1772 + github.com/dolthub/go-mysql-server v0.18.2-0.20241018225641-706812a88f5c github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216 github.com/dolthub/vitess v0.0.0-20241016191424-d14e107a654e github.com/fatih/color v1.13.0 diff --git a/go.sum b/go.sum index 0dd1a7a3d5..c80926471c 100644 --- a/go.sum +++ b/go.sum @@ -226,6 +226,8 @@ github.com/dolthub/go-icu-regex v0.0.0-20240916130659-0118adc6b662 h1:aC17hZD6iw github.com/dolthub/go-icu-regex v0.0.0-20240916130659-0118adc6b662/go.mod h1:KPUcpx070QOfJK1gNe0zx4pA5sicIK1GMikIGLKC168= github.com/dolthub/go-mysql-server v0.18.2-0.20241018220726-63ed221b1772 h1:ckWYX5OXqrTVXe212Xori7VawOZaC552SJryjDiNrsc= github.com/dolthub/go-mysql-server v0.18.2-0.20241018220726-63ed221b1772/go.mod h1:z/GGuH2asedC+lkJA4sx+C3oyRH1HRx8ET6N9AGBVms= +github.com/dolthub/go-mysql-server v0.18.2-0.20241018225641-706812a88f5c h1:tRNOSEgjv9RGWeB5HYN0wUB69TuzBb8eFlbh/UBfLUY= +github.com/dolthub/go-mysql-server v0.18.2-0.20241018225641-706812a88f5c/go.mod h1:z/GGuH2asedC+lkJA4sx+C3oyRH1HRx8ET6N9AGBVms= github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63 h1:OAsXLAPL4du6tfbBgK0xXHZkOlos63RdKYS3Sgw/dfI= github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63/go.mod h1:lV7lUeuDhH5thVGDCKXbatwKy2KW80L4rMT46n+Y2/Q= github.com/dolthub/ishell v0.0.0-20240701202509-2b217167d718 h1:lT7hE5k+0nkBdj/1UOSFwjWpNxf+LCApbRHgnCA17XE= From 1e8b6e93c06abc4090d25c58ab6813f5f7d6e447 Mon Sep 17 00:00:00 2001 From: Jason Fulghum Date: Mon, 21 Oct 2024 11:03:25 -0700 Subject: [PATCH 07/10] Bumping to latest build from fulghum/doltgres-fixes dev branch --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index b26a1c81fa..5b1ae362c3 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20240827111219-e4bb9ca3442d github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2 github.com/dolthub/go-icu-regex v0.0.0-20240916130659-0118adc6b662 - github.com/dolthub/go-mysql-server v0.18.2-0.20241018225641-706812a88f5c + github.com/dolthub/go-mysql-server v0.18.2-0.20241021180142-5f71687e5ab9 github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216 github.com/dolthub/vitess v0.0.0-20241016191424-d14e107a654e github.com/fatih/color v1.13.0 diff --git a/go.sum b/go.sum index c80926471c..9735963b96 100644 --- a/go.sum +++ b/go.sum @@ -228,6 +228,8 @@ github.com/dolthub/go-mysql-server v0.18.2-0.20241018220726-63ed221b1772 h1:ckWY github.com/dolthub/go-mysql-server v0.18.2-0.20241018220726-63ed221b1772/go.mod h1:z/GGuH2asedC+lkJA4sx+C3oyRH1HRx8ET6N9AGBVms= github.com/dolthub/go-mysql-server v0.18.2-0.20241018225641-706812a88f5c h1:tRNOSEgjv9RGWeB5HYN0wUB69TuzBb8eFlbh/UBfLUY= github.com/dolthub/go-mysql-server v0.18.2-0.20241018225641-706812a88f5c/go.mod h1:z/GGuH2asedC+lkJA4sx+C3oyRH1HRx8ET6N9AGBVms= +github.com/dolthub/go-mysql-server v0.18.2-0.20241021180142-5f71687e5ab9 h1:aJHFkClqIh5xF651f6LjLEKmPuLOY6wSTTOJRRDbdHc= +github.com/dolthub/go-mysql-server v0.18.2-0.20241021180142-5f71687e5ab9/go.mod h1:z/GGuH2asedC+lkJA4sx+C3oyRH1HRx8ET6N9AGBVms= github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63 h1:OAsXLAPL4du6tfbBgK0xXHZkOlos63RdKYS3Sgw/dfI= github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63/go.mod h1:lV7lUeuDhH5thVGDCKXbatwKy2KW80L4rMT46n+Y2/Q= github.com/dolthub/ishell v0.0.0-20240701202509-2b217167d718 h1:lT7hE5k+0nkBdj/1UOSFwjWpNxf+LCApbRHgnCA17XE= From ad5717aac60528778d3c617e10cc0e73d5f08f6e Mon Sep 17 00:00:00 2001 From: Jason Fulghum Date: Mon, 21 Oct 2024 13:29:13 -0700 Subject: [PATCH 08/10] Trimming outer quotes when assigning InputExpression, to be consistent with vitess --- server/ast/select.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/server/ast/select.go b/server/ast/select.go index 7fea2caee4..f55768ee4a 100644 --- a/server/ast/select.go +++ b/server/ast/select.go @@ -16,6 +16,7 @@ package ast import ( "fmt" + "strings" vitess "github.com/dolthub/vitess/go/vt/sqlparser" @@ -157,10 +158,16 @@ func nodeSelectExpr(node tree.SelectExpr) (vitess.SelectExpr, error) { if ce, ok := expr.(*tree.CastExpr); ok && node.As == "" { node.As = tree.UnrestrictedName(tree.AsString(ce.Expr)) } + // To be consistent with vitess handling, InputExpression always gets its outer qoutes trimmed + inputExpression := tree.AsString(&node) + if strings.HasPrefix(inputExpression, "'") && strings.HasSuffix(inputExpression, "'") { + inputExpression = inputExpression[1 : len(inputExpression)-1] + } + return &vitess.AliasedExpr{ Expr: vitessExpr, As: vitess.NewColIdent(string(node.As)), - InputExpression: tree.AsString(&node), + InputExpression: inputExpression, }, nil } } From 710805828258a01e4ff9bece827b46dff0937c8e Mon Sep 17 00:00:00 2001 From: Jason Fulghum Date: Mon, 21 Oct 2024 13:29:47 -0700 Subject: [PATCH 09/10] Bumping to latest build from fulghum/doltgres-fixes dev branch --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 5b1ae362c3..2d1cf0b8f4 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20240827111219-e4bb9ca3442d github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2 github.com/dolthub/go-icu-regex v0.0.0-20240916130659-0118adc6b662 - github.com/dolthub/go-mysql-server v0.18.2-0.20241021180142-5f71687e5ab9 + github.com/dolthub/go-mysql-server v0.18.2-0.20241021202742-64ebafee5225 github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216 github.com/dolthub/vitess v0.0.0-20241016191424-d14e107a654e github.com/fatih/color v1.13.0 diff --git a/go.sum b/go.sum index 9735963b96..df6a04ec47 100644 --- a/go.sum +++ b/go.sum @@ -230,6 +230,8 @@ github.com/dolthub/go-mysql-server v0.18.2-0.20241018225641-706812a88f5c h1:tRNO github.com/dolthub/go-mysql-server v0.18.2-0.20241018225641-706812a88f5c/go.mod h1:z/GGuH2asedC+lkJA4sx+C3oyRH1HRx8ET6N9AGBVms= github.com/dolthub/go-mysql-server v0.18.2-0.20241021180142-5f71687e5ab9 h1:aJHFkClqIh5xF651f6LjLEKmPuLOY6wSTTOJRRDbdHc= github.com/dolthub/go-mysql-server v0.18.2-0.20241021180142-5f71687e5ab9/go.mod h1:z/GGuH2asedC+lkJA4sx+C3oyRH1HRx8ET6N9AGBVms= +github.com/dolthub/go-mysql-server v0.18.2-0.20241021202742-64ebafee5225 h1:n03pfpHGJaF2COzHj8SHiGC8mJhapnRt9MTzRiX5TZA= +github.com/dolthub/go-mysql-server v0.18.2-0.20241021202742-64ebafee5225/go.mod h1:z/GGuH2asedC+lkJA4sx+C3oyRH1HRx8ET6N9AGBVms= github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63 h1:OAsXLAPL4du6tfbBgK0xXHZkOlos63RdKYS3Sgw/dfI= github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63/go.mod h1:lV7lUeuDhH5thVGDCKXbatwKy2KW80L4rMT46n+Y2/Q= github.com/dolthub/ishell v0.0.0-20240701202509-2b217167d718 h1:lT7hE5k+0nkBdj/1UOSFwjWpNxf+LCApbRHgnCA17XE= From 6aaf629527a77b8b4dee56048adf1c5caf328e61 Mon Sep 17 00:00:00 2001 From: Jason Fulghum Date: Mon, 21 Oct 2024 18:09:21 -0700 Subject: [PATCH 10/10] Adding back the QuoteString util --- server/types/utils.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/server/types/utils.go b/server/types/utils.go index 214c537b45..f9fc2e281a 100644 --- a/server/types/utils.go +++ b/server/types/utils.go @@ -16,6 +16,7 @@ package types import ( "fmt" + "strings" "time" "unicode/utf8" @@ -24,6 +25,17 @@ import ( "github.com/dolthub/vitess/go/vt/proto/query" ) +// QuoteString will quote the string according to the type given. This means that some types will quote, and others will +// not, or they may quote in a special way that is unique to that type. +func QuoteString(baseID DoltgresTypeBaseID, str string) string { + switch baseID { + case DoltgresTypeBaseID_Char, DoltgresTypeBaseID_Name, DoltgresTypeBaseID_Text, DoltgresTypeBaseID_VarChar, DoltgresTypeBaseID_Unknown: + return `'` + strings.ReplaceAll(str, `'`, `''`) + `'` + default: + return str + } +} + // truncateString returns a string that has been truncated to the given length. Uses the rune count rather than the // byte count. Returns the input string if it's smaller than the length. Also returns the rune count of the string. func truncateString(val string, runeLimit uint32) (string, uint32) {