Skip to content

Commit

Permalink
CySQL Fixes and Updates (#1049)
Browse files Browse the repository at this point in the history
* chore: BED-5201 - PG cleanup and type checking tests

* fix: BED-5185

* fix: BED-5193, BED-5171

* fix: BED-5192

* chore: prepare for codereview

* chore: BED-5192 - fixup additional edge cases
  • Loading branch information
zinic authored Jan 7, 2025
1 parent 440c338 commit df1a43c
Show file tree
Hide file tree
Showing 12 changed files with 735 additions and 238 deletions.
12 changes: 11 additions & 1 deletion packages/go/cypher/models/pgsql/format/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,17 @@ func formatNode(builder *OutputBuilder, rootExpr pgsql.SyntaxNode) error {
exprStack = append(exprStack, *typedNextExpr)

case pgsql.TypeCast:
switch typedNextExpr.Expression.(type) {
switch typedCastedExpr := typedNextExpr.Expression.(type) {
case *pgsql.BinaryExpression:
if typedCastedExpr.Operator == pgsql.OperatorJSONTextField && typedNextExpr.CastType == pgsql.Text {
// Avoid formatting property lookups wrapped in text type casts
exprStack = append(exprStack, typedNextExpr.Expression)
} else {
exprStack = append(exprStack, pgsql.FormattingLiteral(typedNextExpr.CastType), pgsql.FormattingLiteral(")::"))
exprStack = append(exprStack, typedNextExpr.Expression)
exprStack = append(exprStack, pgsql.FormattingLiteral("("))
}

case pgsql.Parenthetical:
// Avoid formatting type-casted parenthetical statements as (('test'))::text - this should instead look like ('test')::text
exprStack = append(exprStack, pgsql.FormattingLiteral(typedNextExpr.CastType), pgsql.FormattingLiteral("::"))
Expand Down
8 changes: 8 additions & 0 deletions packages/go/cypher/models/pgsql/operators.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ func OperatorIsPropertyLookup(operator Expression) bool {
)
}

func OperatorIsComparator(operator Expression) bool {
return OperatorIsIn(operator,
OperatorEquals, OperatorNotEquals, OperatorGreaterThan, OperatorGreaterThanOrEqualTo, OperatorLessThan,
OperatorLessThanOrEqualTo, OperatorArrayOverlap, OperatorLike, OperatorILike, OperatorPGArrayOverlap,
OperatorRegexMatch, OperatorSimilarTo)
}

const (
UnsetOperator Operator = ""
OperatorUnion Operator = "union"
Expand Down Expand Up @@ -107,6 +114,7 @@ const (
OperatorCypherStartsWith Operator = "starts with"
OperatorCypherContains Operator = "contains"
OperatorCypherEndsWith Operator = "ends with"
OperatorCypherAdd Operator = "+"

OperatorPropertyLookup Operator = "property_lookup"
OperatorKindAssignment Operator = "kind_assignment"
Expand Down
Loading

0 comments on commit df1a43c

Please sign in to comment.