Skip to content

Commit 434f6ef

Browse files
authored
Merge pull request #474 from mcarmonaa/fix/files-blob-content
*: pushdown projections properly in the files table
2 parents 1bb9a66 + ed800a9 commit 434f6ef

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

files.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ func (r *filesTable) WithFilters(filters []sql.Expression) sql.Table {
4646
}
4747

4848
func (r *filesTable) WithProjection(colNames []string) sql.Table {
49-
return r
49+
nt := *r
50+
nt.projection = colNames
51+
return &nt
5052
}
5153

5254
func (r *filesTable) WithIndexLookup(idx sql.IndexLookup) sql.Table {

files_test.go

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func TestFilesRowIter(t *testing.T) {
7373
require.ElementsMatch(expected, rows)
7474
}
7575

76-
func TestFilesTablePushdown(t *testing.T) {
76+
func TestFilesTablePushdownFilters(t *testing.T) {
7777
ctx, _, cleanup := setup(t)
7878
defer cleanup()
7979

@@ -153,6 +153,56 @@ func TestFilesTablePushdown(t *testing.T) {
153153
}
154154
}
155155

156+
func TestFilesTablePushdownProjection(t *testing.T) {
157+
ctx, _, cleanup := setup(t)
158+
defer cleanup()
159+
160+
filters := []sql.Expression{
161+
expression.NewEquals(
162+
expression.NewGetFieldWithTable(1, sql.Text, FilesTableName, "file_path", false),
163+
expression.NewLiteral("LICENSE", sql.Text),
164+
),
165+
}
166+
table := new(filesTable).WithFilters(filters).(*filesTable)
167+
168+
testCases := []struct {
169+
name string
170+
projections []string
171+
expected func(content []byte, size int64) bool
172+
}{
173+
{
174+
"with blob_content projected",
175+
[]string{"blob_content"},
176+
func(content []byte, size int64) bool { return int64(len(content)) == size },
177+
},
178+
{
179+
"without blob_content projected",
180+
nil,
181+
func(content []byte, size int64) bool { return len(content) == 0 },
182+
},
183+
}
184+
185+
for _, test := range testCases {
186+
t.Run(test.name, func(t *testing.T) {
187+
require := require.New(t)
188+
tbl := table.WithProjection(test.projections)
189+
190+
rows, err := tableToRows(ctx, tbl)
191+
require.NoError(err)
192+
193+
for _, row := range rows {
194+
content, ok := row[5].([]byte)
195+
require.True(ok)
196+
197+
size, ok := row[6].(int64)
198+
require.True(ok)
199+
200+
require.True(test.expected(content, size))
201+
}
202+
})
203+
}
204+
}
205+
156206
func TestFilesIndexKeyValueIter(t *testing.T) {
157207
require := require.New(t)
158208
ctx, path, cleanup := setup(t)

0 commit comments

Comments
 (0)