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

Commit 38223c6

Browse files
authored
Merge pull request #634 from erizocosmico/fix/describe-prune-columns
fix prune columns for describe queries
2 parents 239b2af + 730813b commit 38223c6

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"
@@ -1112,14 +1113,14 @@ func TestDescribe(t *testing.T) {
11121113

11131114
query := `DESCRIBE FORMAT=TREE SELECT * FROM mytable`
11141115
expectedSeq := []sql.Row{
1115-
sql.NewRow("Table(mytable)"),
1116+
sql.NewRow("Table(mytable): Projected "),
11161117
sql.NewRow(" ├─ Column(i, INT64, nullable=false)"),
11171118
sql.NewRow(" └─ Column(s, TEXT, nullable=false)"),
11181119
}
11191120

11201121
expectedParallel := []sql.Row{
11211122
{"Exchange(parallelism=2)"},
1122-
{" └─ Table(mytable)"},
1123+
{" └─ Table(mytable): Projected "},
11231124
{" ├─ Column(i, INT64, nullable=false)"},
11241125
{" └─ Column(s, TEXT, nullable=false)"},
11251126
}
@@ -2007,6 +2008,28 @@ func TestLocks(t *testing.T) {
20072008
require.Equal(1, t2.unlocks)
20082009
}
20092010

2011+
func TestDescribeNoPruneColumns(t *testing.T) {
2012+
require := require.New(t)
2013+
ctx := newCtx()
2014+
e := newEngine(t)
2015+
query := `DESCRIBE FORMAT=TREE SELECT SUBSTRING(s, 1, 1) as foo, s, i FROM mytable WHERE foo = 'f'`
2016+
parsed, err := parse.Parse(ctx, query)
2017+
require.NoError(err)
2018+
result, err := e.Analyzer.Analyze(ctx, parsed)
2019+
require.NoError(err)
2020+
2021+
qp, ok := result.(*plan.QueryProcess)
2022+
require.True(ok)
2023+
2024+
d, ok := qp.Child.(*plan.DescribeQuery)
2025+
require.True(ok)
2026+
2027+
p, ok := d.Child.(*plan.Project)
2028+
require.True(ok)
2029+
2030+
require.Len(p.Schema(), 3)
2031+
}
2032+
20102033
func insertRows(t *testing.T, table sql.Inserter, rows ...sql.Row) {
20112034
t.Helper()
20122035

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)