Skip to content

Commit

Permalink
used type switching and added error for unhandled case
Browse files Browse the repository at this point in the history
  • Loading branch information
richardwu committed Aug 31, 2017
1 parent 67f967a commit 637af2c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions pkg/sql/parser/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -2722,15 +2722,15 @@ func (expr *ComparisonExpr) Eval(ctx *EvalContext) (Datum, error) {

op := expr.Operator
if op.hasSubOperator() {
// Branch to different helper comparison functions
// depending on whether a subquery or an array follows
var datums Datums
// Right is either a tuple or an array of Datums.
if tuple, ok := AsDTuple(right); ok {
datums = tuple.D
} else if array, ok := AsDArray(right); ok {
datums = array.Array
} else {
return nil, pgerror.NewErrorf(pgerror.CodeInternalError, "unhandled right expression %s", right)
}
// Type checking in parser ensures rightType is either TypeTuple or TypeArray
return evalDatumsCmp(ctx, op, expr.SubOperator, expr.fn, left, datums)
}

Expand Down
12 changes: 6 additions & 6 deletions pkg/sql/parser/type_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@ func typeCheckComparisonOpWithSubOperator(
cmpTypeLeft = leftTyped.ResolvedType()

// Try to type the right expression as an Array of the left's type.
// If right is an sql.subquery Expr, it should already be typed
// If right is an sql.subquery Expr, it should already be typed.
rightTyped, err = right.TypeCheck(ctx, TArray{cmpTypeLeft})
if err != nil {
return nil, nil, CmpOp{}, err
Expand All @@ -1007,14 +1007,14 @@ func typeCheckComparisonOpWithSubOperator(
return leftTyped, rightTyped, CmpOp{}, nil
}

rightUnwrapped := UnwrapType(rightReturn)
switch rightUnwrapped.(type) {
UnwrapType(rightReturn)
switch rightUnwrapped := UnwrapType(rightReturn).(type) {
case TArray:
cmpTypeRight = rightUnwrapped.(TArray).Typ
cmpTypeRight = rightUnwrapped.Typ
case TTuple:
// Subqueries are expected to return 1 column of values
// (see planner.analyzeExpr in analyze.go)
cmpTypeRight = rightUnwrapped.(TTuple)[0]
// (see planner.analyzeExpr in analyze.go).
cmpTypeRight = rightUnwrapped[0]
default:
sigWithErr := fmt.Sprintf(compExprsWithSubOpFmt, left, subOp, op, right,
fmt.Sprintf("op %s <right> requires array or subquery on right side", op))
Expand Down

0 comments on commit 637af2c

Please sign in to comment.