Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing Point method to actually print string #956

Merged
merged 3 commits into from
Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions enginetest/enginetests.go
Original file line number Diff line number Diff line change
Expand Up @@ -1250,6 +1250,12 @@ func TestScripts(t *testing.T, harness Harness) {
}
}

func TestSpatialScripts(t *testing.T, harness Harness) {
for _, script := range SpatialScriptTests {
TestScript(t, harness, script)
}
}

func TestLoadDataPrepared(t *testing.T, harness Harness) {
for _, script := range LoadDataScripts {
TestScriptPrepared(t, harness, script)
Expand Down
4 changes: 4 additions & 0 deletions enginetest/memory_engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,10 @@ func TestScripts(t *testing.T) {
enginetest.TestScripts(t, enginetest.NewMemoryHarness("default", 1, testNumPartitions, true, mergableIndexDriver))
}

func TestSpatialScripts(t *testing.T) {
enginetest.TestSpatialScripts(t, enginetest.NewMemoryHarness("default", 1, testNumPartitions, true, mergableIndexDriver))
}

func TestLoadDataPrepared(t *testing.T) {
enginetest.TestLoadDataPrepared(t, enginetest.NewMemoryHarness("default", 1, testNumPartitions, true, mergableIndexDriver))
}
Expand Down
129 changes: 129 additions & 0 deletions enginetest/script_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -1964,6 +1964,135 @@ var ScriptTests = []ScriptTest{
},
}

var SpatialScriptTests = []ScriptTest{
{
Name: "create table using default point value",
SetUpScript: []string{
"CREATE TABLE test (i int primary key, p point default point(123.456, 7.89));",
"insert into test (i) values (0);",
},
Assertions: []ScriptTestAssertion{
{
Query: "select st_aswkt(p) from test",
Expected: []sql.Row{{"POINT(123.456 7.89)"}},
},
{
Query: "show create table test",
Expected: []sql.Row{{"test", "CREATE TABLE `test` (\n `i` int NOT NULL,\n `p` point DEFAULT (POINT(123.456, 7.89)),\n PRIMARY KEY (`i`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"}},
},
{
Query: "describe test",
Expected: []sql.Row{{"i", "int", "NO", "PRI", "", ""}, {"p", "point", "YES", "", "(POINT(123.456, 7.89))", ""}},
},
},
},
{
Name: "create table using default linestring value",
SetUpScript: []string{
"CREATE TABLE test (i int primary key, l linestring default linestring(point(1,2), point(3,4)));",
"insert into test (i) values (0);",
},
Assertions: []ScriptTestAssertion{
{
Query: "select st_aswkt(l) from test",
Expected: []sql.Row{{"LINESTRING(1 2,3 4)"}},
},
{
Query: "show create table test",
Expected: []sql.Row{{"test", "CREATE TABLE `test` (\n `i` int NOT NULL,\n `l` linestring DEFAULT (LINESTRING(POINT(1, 2),POINT(3, 4))),\n PRIMARY KEY (`i`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"}},
},
{
Query: "describe test",
Expected: []sql.Row{{"i", "int", "NO", "PRI", "", ""}, {"l", "linestring", "YES", "", "(LINESTRING(POINT(1, 2),POINT(3, 4)))", ""}},
},
},
},
{
Name: "create table using default polygon value",
SetUpScript: []string{
"CREATE TABLE test (i int primary key, p polygon default polygon(linestring(point(0,0), point(1,1), point(2,2), point(0,0))));",
"insert into test (i) values (0);",
},
Assertions: []ScriptTestAssertion{
{
Query: "select st_aswkt(p) from test",
Expected: []sql.Row{{"POLYGON((0 0,1 1,2 2,0 0))"}},
},
{
Query: "show create table test",
Expected: []sql.Row{{"test", "CREATE TABLE `test` (\n `i` int NOT NULL,\n `p` polygon DEFAULT (POLYGON(LINESTRING(POINT(0, 0),POINT(1, 1),POINT(2, 2),POINT(0, 0)))),\n PRIMARY KEY (`i`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"}},
},
{
Query: "describe test",
Expected: []sql.Row{{"i", "int", "NO", "PRI", "", ""}, {"p", "polygon", "YES", "", "(POLYGON(LINESTRING(POINT(0, 0),POINT(1, 1),POINT(2, 2),POINT(0, 0))))", ""}},
},
},
},
{
Name: "create geometry table using default point value",
SetUpScript: []string{
"CREATE TABLE test (i int primary key, g geometry default point(123.456, 7.89));",
"insert into test (i) values (0);",
},
Assertions: []ScriptTestAssertion{
{
Query: "select st_aswkt(g) from test",
Expected: []sql.Row{{"POINT(123.456 7.89)"}},
},
{
Query: "show create table test",
Expected: []sql.Row{{"test", "CREATE TABLE `test` (\n `i` int NOT NULL,\n `g` geometry DEFAULT (POINT(123.456, 7.89)),\n PRIMARY KEY (`i`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"}},
},
{
Query: "describe test",
Expected: []sql.Row{{"i", "int", "NO", "PRI", "", ""}, {"g", "geometry", "YES", "", "(POINT(123.456, 7.89))", ""}},
},
},
},
{
Name: "create geometry table using default linestring value",
SetUpScript: []string{
"CREATE TABLE test (i int primary key, g geometry default linestring(point(1,2), point(3,4)));",
"insert into test (i) values (0);",
},
Assertions: []ScriptTestAssertion{
{
Query: "select st_aswkt(g) from test",
Expected: []sql.Row{{"LINESTRING(1 2,3 4)"}},
},
{
Query: "show create table test",
Expected: []sql.Row{{"test", "CREATE TABLE `test` (\n `i` int NOT NULL,\n `g` geometry DEFAULT (LINESTRING(POINT(1, 2),POINT(3, 4))),\n PRIMARY KEY (`i`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"}},
},
{
Query: "describe test",
Expected: []sql.Row{{"i", "int", "NO", "PRI", "", ""}, {"g", "geometry", "YES", "", "(LINESTRING(POINT(1, 2),POINT(3, 4)))", ""}},
},
},
},
{
Name: "create geometry table using default polygon value",
SetUpScript: []string{
"CREATE TABLE test (i int primary key, g geometry default polygon(linestring(point(0,0), point(1,1), point(2,2), point(0,0))));",
"insert into test (i) values (0);",
},
Assertions: []ScriptTestAssertion{
{
Query: "select st_aswkt(g) from test",
Expected: []sql.Row{{"POLYGON((0 0,1 1,2 2,0 0))"}},
},
{
Query: "show create table test",
Expected: []sql.Row{{"test", "CREATE TABLE `test` (\n `i` int NOT NULL,\n `g` geometry DEFAULT (POLYGON(LINESTRING(POINT(0, 0),POINT(1, 1),POINT(2, 2),POINT(0, 0)))),\n PRIMARY KEY (`i`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"}},
},
{
Query: "describe test",
Expected: []sql.Row{{"i", "int", "NO", "PRI", "", ""}, {"g", "geometry", "YES", "", "(POLYGON(LINESTRING(POINT(0, 0),POINT(1, 1),POINT(2, 2),POINT(0, 0))))", ""}},
},
},
},
}

var CreateCheckConstraintsScripts = []ScriptTest{
{
Name: "Run SHOW CREATE TABLE with different types of check constraints",
Expand Down
2 changes: 1 addition & 1 deletion sql/expression/function/point.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (p *Point) Type() sql.Type {
}

func (p *Point) String() string {
return fmt.Sprintf("POINT(%f, %f)", p.X, p.Y)
return fmt.Sprintf("POINT(%s, %s)", p.X.String(), p.Y.String())
}

// WithChildren implements the Expression interface.
Expand Down