Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CySQL Fixes and Updates #1049

Merged
merged 6 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading