diff --git a/query/logicalplan/builder.go b/query/logicalplan/builder.go index 7aa0f9777..52e8cfd74 100644 --- a/query/logicalplan/builder.go +++ b/query/logicalplan/builder.go @@ -1,6 +1,8 @@ package logicalplan import ( + "fmt" + "github.com/apache/arrow/go/v14/arrow" "github.com/parquet-go/parquet-go" ) @@ -60,6 +62,7 @@ type Expr interface { DataType(*parquet.Schema) (arrow.DataType, error) Accept(Visitor) bool Name() string + fmt.Stringer // ColumnsUsedExprs extracts all the expressions that are used that cause // physical data to be read from a column. diff --git a/query/logicalplan/expr.go b/query/logicalplan/expr.go index 18cd486e1..5b1887f1f 100644 --- a/query/logicalplan/expr.go +++ b/query/logicalplan/expr.go @@ -102,6 +102,8 @@ func (e *BinaryExpr) Name() string { return e.Left.Name() + " " + e.Op.String() + " " + e.Right.Name() } +func (e *BinaryExpr) String() string { return e.Name() } + func (e *BinaryExpr) ColumnsUsedExprs() []Expr { return append(e.Left.ColumnsUsedExprs(), e.Right.ColumnsUsedExprs()...) } @@ -147,6 +149,8 @@ func (c *Column) Name() string { return c.ColumnName } +func (c *Column) String() string { return c.Name() } + func (c *Column) DataType(s *parquet.Schema) (arrow.DataType, error) { for _, field := range s.Fields() { af, err := c.findField("", field) @@ -368,6 +372,8 @@ func (c *DynamicColumn) Name() string { return c.ColumnName } +func (c *DynamicColumn) String() string { return c.Name() } + func (c *DynamicColumn) Accept(visitor Visitor) bool { return visitor.PreVisit(c) && visitor.PostVisit(c) } @@ -408,6 +414,8 @@ func (e *LiteralExpr) Name() string { return e.Value.String() } +func (e *LiteralExpr) String() string { return e.Name() } + func (e *LiteralExpr) Accept(visitor Visitor) bool { continu := visitor.PreVisit(e) if !continu { @@ -465,6 +473,8 @@ func (f *AggregationFunction) Name() string { return f.Func.String() + "(" + f.Expr.Name() + ")" } +func (f *AggregationFunction) String() string { return f.Name() } + func (f *AggregationFunction) ColumnsUsedExprs() []Expr { return f.Expr.ColumnsUsedExprs() } @@ -560,6 +570,8 @@ func (e *AliasExpr) Name() string { return e.Alias } +func (e *AliasExpr) String() string { return e.Name() } + func (e *AliasExpr) Computed() bool { return e.Expr.Computed() } @@ -632,6 +644,8 @@ func (d *DurationExpr) Name() string { return "" } +func (d *DurationExpr) String() string { return d.Name() } + func (d *DurationExpr) ColumnsUsedExprs() []Expr { // DurationExpr expect to work on a timestamp column return []Expr{Col("timestamp")} @@ -667,6 +681,8 @@ func (a *AverageExpr) Name() string { return a.Expr.Name() } +func (a *AverageExpr) String() string { return a.Name() } + func (a *AverageExpr) ColumnsUsedExprs() []Expr { return a.Expr.ColumnsUsedExprs() } @@ -724,6 +740,8 @@ func (a *RegexpColumnMatch) Name() string { return a.match.String() } +func (a *RegexpColumnMatch) String() string { return a.Name() } + func (a *RegexpColumnMatch) ColumnsUsedExprs() []Expr { return []Expr{a} } @@ -764,7 +782,8 @@ func (a *AllExpr) Accept(visitor Visitor) bool { return visitor.PostVisit(a) } -func (a *AllExpr) Name() string { return "all" } +func (a *AllExpr) Name() string { return "all" } +func (a *AllExpr) String() string { return a.Name() } func (a *AllExpr) ColumnsUsedExprs() []Expr { return []Expr{&AllExpr{}} } @@ -792,7 +811,8 @@ func (n *NotExpr) Accept(visitor Visitor) bool { return visitor.PostVisit(n) } -func (n *NotExpr) Name() string { return "not " + n.Expr.Name() } +func (n *NotExpr) Name() string { return "not " + n.Expr.Name() } +func (n *NotExpr) String() string { return n.Name() } func (n *NotExpr) ColumnsUsedExprs() []Expr { return []Expr{&NotExpr{Expr: n.Expr}} } diff --git a/query/logicalplan/validate.go b/query/logicalplan/validate.go index a647f529e..2bc4b32f6 100644 --- a/query/logicalplan/validate.go +++ b/query/logicalplan/validate.go @@ -52,7 +52,7 @@ func (e *ExprValidationError) Error() string { message := make([]string, 0) message = append(message, e.message) message = append(message, ": ") - message = append(message, fmt.Sprintf("%s", e.expr)) + message = append(message, e.expr.String()) for _, child := range e.children { message = append(message, "\n -> invalid sub-expression: ") message = append(message, child.Error())