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

case statement types should be same #63

Closed
wants to merge 1 commit into from
Closed
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
11 changes: 8 additions & 3 deletions src/ExprCompiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
LegacyComparisonExpr,
LegacyLogicalExpr,
LiteralExpr,
LiteralType,
OpExpr,
ScalarExpr,
ScoreExpr,
Expand Down Expand Up @@ -89,8 +90,8 @@ export default class ExprCompiler {
}

/** Compile an expression. Pass expr and tableAlias. */
compileExpr(options: { expr: Expr; tableAlias: string }): JsonQLExpr {
const { expr, tableAlias } = options
compileExpr(options: { expr: Expr; tableAlias: string, literalType?: LiteralType|null }): JsonQLExpr {
const { expr, tableAlias, literalType } = options

// Handle null
if (!expr) {
Expand All @@ -106,6 +107,9 @@ export default class ExprCompiler {
return this.compileScalarExpr({ expr, tableAlias })
case "literal":
if (expr.value != null) {
if(!!literalType && literalType === "enumset" && expr.valueType === "enumset") {
return convertToJsonB({ type: "literal", value: expr.value })
}
return { type: "literal", value: expr.value }
} else {
return null
Expand Down Expand Up @@ -2393,13 +2397,14 @@ export default class ExprCompiler {

compileCaseExpr(options: { expr: CaseExpr; tableAlias: string }): JsonQLExpr {
const { expr } = options
const exprUtils = new ExprUtils(this.schema)

const compiled: JsonQLCase = {
type: "case",
cases: _.map(expr.cases, (c) => {
return {
when: this.compileExpr({ expr: c.when, tableAlias: options.tableAlias }),
then: this.compileExpr({ expr: c.then, tableAlias: options.tableAlias })
then: this.compileExpr({ expr: c.then, tableAlias: options.tableAlias, literalType: exprUtils.getExprType(expr.else) })
}
}),
else: this.compileExpr({ expr: expr.else, tableAlias: options.tableAlias })
Expand Down