提交 ec9efaa4 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Fix ConditionInConstantSet for ENUM data type

上级 491bc343
......@@ -114,6 +114,9 @@ public class ConditionIn extends Condition {
if (leftType == Value.UNKNOWN) {
return this;
}
if (leftType == Value.ENUM && !(left instanceof ExpressionColumn)) {
return this;
}
Expression expr = new ConditionInConstantSet(session, left, valueList);
expr = expr.optimize(session);
return expr;
......
......@@ -33,26 +33,37 @@ public class ConditionInConstantSet extends Condition {
private int queryLevel;
private final ArrayList<Expression> valueList;
private final TreeSet<Value> valueSet;
private final int type;
private String[] enumerators;
/**
* Create a new IN(..) condition.
*
* @param session the session
* @param left the expression before IN
* @param left
* the expression before IN. Cannot have {@link Value#UNKNOWN}
* data type and {@link Value#ENUM} type is also supported only
* for {@link ExpressionColumn}.
* @param valueList the value list (at least two elements)
*/
public ConditionInConstantSet(final Session session, Expression left,
ArrayList<Expression> valueList) {
public ConditionInConstantSet(Session session, Expression left, ArrayList<Expression> valueList) {
this.left = left;
this.valueList = valueList;
Database database = session.getDatabase();
this.valueSet = new TreeSet<>(database.getCompareMode());
int type = left.getType();
type = left.getType();
Mode mode = database.getMode();
if (type == Value.ENUM) {
enumerators = ((ExpressionColumn) left).getColumn().getEnumerators();
for (Expression expression : valueList) {
valueSet.add(expression.getValue(session).convertToEnum(enumerators));
}
} else {
for (Expression expression : valueList) {
valueSet.add(expression.getValue(session).convertTo(type, -1, mode));
}
}
}
@Override
public Value getValue(Session session) {
......@@ -158,7 +169,11 @@ public class ConditionInConstantSet extends Condition {
if (add != null) {
if (add.isConstant()) {
valueList.add(add);
valueSet.add(add.getValue(session).convertTo(left.getType(), -1, session.getDatabase().getMode()));
if (type == Value.ENUM) {
valueSet.add(add.getValue(session).convertToEnum(enumerators));
} else {
valueSet.add(add.getValue(session).convertTo(type, -1, session.getDatabase().getMode()));
}
return this;
}
}
......
......@@ -161,6 +161,26 @@ select rank from card where suit in ('clubs');
> 1
> rows: 2
insert into card values (2, 'diamonds');
> update count: 1
select rank from card where suit in ('clubs', 'hearts');
> RANK
> ----
> 0
> 1
> 3
> rows: 3
select rank from card where suit in ('clubs', 'hearts') or suit = 'diamonds';
> RANK
> ----
> 0
> 1
> 2
> 3
> rows: 4
drop table card;
> ok
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论