Skip to content
This repository was archived by the owner on Jan 28, 2021. It is now read-only.

Commit 730813b

Browse files
committed
fix prune columns for describe queries
Signed-off-by: Miguel Molina <[email protected]>
1 parent 08e98ce commit 730813b

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

engine_test.go

+25-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"gopkg.in/src-d/go-mysql-server.v0/sql/analyzer"
1919
"gopkg.in/src-d/go-mysql-server.v0/sql/index/pilosa"
2020
"gopkg.in/src-d/go-mysql-server.v0/sql/parse"
21+
"gopkg.in/src-d/go-mysql-server.v0/sql/plan"
2122
"gopkg.in/src-d/go-mysql-server.v0/test"
2223

2324
"github.com/stretchr/testify/require"
@@ -1104,14 +1105,14 @@ func TestDescribe(t *testing.T) {
11041105

11051106
query := `DESCRIBE FORMAT=TREE SELECT * FROM mytable`
11061107
expectedSeq := []sql.Row{
1107-
sql.NewRow("Table(mytable)"),
1108+
sql.NewRow("Table(mytable): Projected "),
11081109
sql.NewRow(" ├─ Column(i, INT64, nullable=false)"),
11091110
sql.NewRow(" └─ Column(s, TEXT, nullable=false)"),
11101111
}
11111112

11121113
expectedParallel := []sql.Row{
11131114
{"Exchange(parallelism=2)"},
1114-
{" └─ Table(mytable)"},
1115+
{" └─ Table(mytable): Projected "},
11151116
{" ├─ Column(i, INT64, nullable=false)"},
11161117
{" └─ Column(s, TEXT, nullable=false)"},
11171118
}
@@ -1999,6 +2000,28 @@ func TestLocks(t *testing.T) {
19992000
require.Equal(1, t2.unlocks)
20002001
}
20012002

2003+
func TestDescribeNoPruneColumns(t *testing.T) {
2004+
require := require.New(t)
2005+
ctx := newCtx()
2006+
e := newEngine(t)
2007+
query := `DESCRIBE FORMAT=TREE SELECT SUBSTRING(s, 1, 1) as foo, s, i FROM mytable WHERE foo = 'f'`
2008+
parsed, err := parse.Parse(ctx, query)
2009+
require.NoError(err)
2010+
result, err := e.Analyzer.Analyze(ctx, parsed)
2011+
require.NoError(err)
2012+
2013+
qp, ok := result.(*plan.QueryProcess)
2014+
require.True(ok)
2015+
2016+
d, ok := qp.Child.(*plan.DescribeQuery)
2017+
require.True(ok)
2018+
2019+
p, ok := d.Child.(*plan.Project)
2020+
require.True(ok)
2021+
2022+
require.Len(p.Schema(), 3)
2023+
}
2024+
20022025
func insertRows(t *testing.T, table sql.Inserter, rows ...sql.Row) {
20032026
t.Helper()
20042027

sql/analyzer/prune_columns.go

+9
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ func pruneColumns(ctx *sql.Context, a *Analyzer, n sql.Node) (sql.Node, error) {
1616
return n, nil
1717
}
1818

19+
if describe, ok := n.(*plan.DescribeQuery); ok {
20+
n, err := pruneColumns(ctx, a, describe.Child)
21+
if err != nil {
22+
return nil, err
23+
}
24+
25+
return plan.NewDescribeQuery(describe.Format, n), nil
26+
}
27+
1928
columns := make(usedColumns)
2029

2130
// All the columns required for the output of the query must be mark as

0 commit comments

Comments
 (0)