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

Fix ConditionInConstantSet for ENUM data type

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