Skip to content

Commit

Permalink
Fix type of nested properties (#1067)
Browse files Browse the repository at this point in the history
Fix two bugs:
- double quotes of some fields
- nested properties did not work with array or function, this fixes this
problem

Co-authored-by: Rafał Strzaliński <[email protected]>
  • Loading branch information
jakozaur and nablaone authored Dec 6, 2024
1 parent 80380ff commit bbf9f3b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions quesma/model/base_visitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ func (v *BaseExprVisitor) VisitNestedProperty(e NestedProperty) interface{} {
if v.OverrideVisitNestedProperty != nil {
return v.OverrideVisitNestedProperty(v, e)
}
ColumnRef := e.ColumnRef.Accept(v).(ColumnRef)
expr := e.ObjectExpr.Accept(v).(Expr)
Property := e.PropertyName.Accept(v).(LiteralExpr)
return NewNestedProperty(ColumnRef, Property)
return NewNestedProperty(expr, Property)
}

func (v *BaseExprVisitor) VisitArrayAccess(e ArrayAccess) interface{} {
Expand Down
6 changes: 3 additions & 3 deletions quesma/model/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ func (e PrefixExpr) Accept(v ExprVisitor) interface{} {

// NestedProperty represents a call to nested property e.g. `columnName.propertyName`
type NestedProperty struct {
ColumnRef ColumnRef
ObjectExpr Expr
PropertyName LiteralExpr
}

func NewNestedProperty(columnRef ColumnRef, propertyName LiteralExpr) NestedProperty {
return NestedProperty{ColumnRef: columnRef, PropertyName: propertyName}
func NewNestedProperty(columnRef Expr, propertyName LiteralExpr) NestedProperty {
return NestedProperty{ObjectExpr: columnRef, PropertyName: propertyName}
}

func (e NestedProperty) Accept(v ExprVisitor) interface{} { return v.VisitNestedProperty(e) }
Expand Down
2 changes: 1 addition & 1 deletion quesma/model/expr_string_renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (v *renderer) VisitPrefixExpr(e PrefixExpr) interface{} {
}

func (v *renderer) VisitNestedProperty(e NestedProperty) interface{} {
return fmt.Sprintf("%v.%v", e.ColumnRef.Accept(v), e.PropertyName.Accept(v))
return fmt.Sprintf("%v.%v", e.ObjectExpr.Accept(v), e.PropertyName.Accept(v))
}

func (v *renderer) VisitArrayAccess(e ArrayAccess) interface{} {
Expand Down
2 changes: 1 addition & 1 deletion quesma/queryparser/query_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ func (cw *ClickhouseQueryTranslator) parseExists(queryMap QueryMap) model.Simple
sql = model.NewInfixExpr(model.NewColumnRef(fieldName), "IS", model.NewLiteral("NOT NULL"))
case clickhouse.ExistsAndIsArray:
sql = model.NewInfixExpr(model.NewNestedProperty(
model.NewColumnRef(fieldNameQuoted),
model.NewColumnRef(fieldName),
model.NewLiteral("size0"),
), "=", model.NewLiteral("0"))
case clickhouse.NotExists:
Expand Down

0 comments on commit bbf9f3b

Please sign in to comment.