Skip to content

Commit 5e5077b

Browse files
committed
Fix df.Show() issue
1 parent e9edd66 commit 5e5077b

4 files changed

Lines changed: 28 additions & 2 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import (
2828
func TestParquetFile(t *testing.T) {
2929
ctx := engine.NewContext()
3030
df, err := ctx.Parquet("../../test/data/c1_c2_c3_int64.parquet", nil)
31+
32+
_ = df.Show()
3133
/*
3234
+-----+-----+-----+
3335
| C1 | C2 | C3 |

cmd/simple/engine_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ func TestParquetFile(t *testing.T) {
1515
t.Error(err)
1616
}
1717

18+
_ = df.Show()
19+
1820
df = df.
1921
Filter(logicalplan.Eq(
2022
logicalplan.ColumnExpr{Name: "c1"},

pkg/b_dataframe/dataframe.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,26 @@ func (df *DataFrame) Aggregate(groupBy []logicalplan.Expr, aggExpr []logicalplan
6363
}
6464

6565
func (df *DataFrame) collect(ctx context.Context, callback datasource.Callback) error {
66-
df.planBuilder.Output(callback)
66+
// create a copy of the plan builder and add the output operator
67+
// NOTE: This is a hack to add Output operator to the PhysicalPlan.
68+
builder := df.planBuilder.Clone().Output(callback)
6769

68-
physicalPlan, err := df.PhysicalPlan()
70+
// build the logical plan
71+
plan, err := builder.Build()
6972
if err != nil {
7073
return err
7174
}
75+
76+
// optimize the logical plan
77+
plan = df.ruleBasedOptimizer.Optimize(plan)
78+
79+
// create the physical plan
80+
physicalPlan, err := df.sessionState.CreatePhysicalPlan(plan)
81+
if err != nil {
82+
return err
83+
}
84+
85+
// execute the physical plan
7286
return physicalPlan.Execute(df.TaskContext(), callback)
7387
}
7488

pkg/c_logical_plan/f_logical_plan_builder.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ func (b *Builder) Build() (LogicalPlan, error) {
4444
return b.plan, nil
4545
}
4646

47+
func (b *Builder) Clone() *Builder {
48+
var copiedPlan LogicalPlan
49+
if b.plan != nil {
50+
copiedPlan = b.plan
51+
}
52+
return &Builder{plan: copiedPlan}
53+
}
54+
4755
func Validate(plan LogicalPlan) error {
4856
return nil
4957
}

0 commit comments

Comments
 (0)