Unverified 提交 c734f793 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov 提交者: GitHub

Merge pull request #1434 from katzyn/misc

Add support for ENUM in CAST and other changes
...@@ -135,9 +135,9 @@ public class ScriptCommand extends ScriptBase { ...@@ -135,9 +135,9 @@ public class ScriptCommand extends ScriptBase {
} }
private LocalResult createResult() { private LocalResult createResult() {
Expression[] expressions = { new ExpressionColumn( Database db = session.getDatabase();
session.getDatabase(), new Column("SCRIPT", Value.STRING)) }; return db.getResultFactory().create(session,
return session.getDatabase().getResultFactory().create(session, expressions, 1); new Expression[] { new ExpressionColumn(db, new Column("SCRIPT", Value.STRING)) }, 1);
} }
@Override @Override
......
...@@ -9,6 +9,7 @@ import java.util.ArrayList; ...@@ -9,6 +9,7 @@ import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import org.h2.api.ErrorCode; import org.h2.api.ErrorCode;
import org.h2.engine.Database;
import org.h2.engine.Mode; import org.h2.engine.Mode;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.engine.SysProperties; import org.h2.engine.SysProperties;
...@@ -159,7 +160,8 @@ public class SelectUnion extends Query { ...@@ -159,7 +160,8 @@ public class SelectUnion extends Query {
} }
limitExpr = ValueExpression.get(ValueInt.get(l)); limitExpr = ValueExpression.get(ValueInt.get(l));
} }
if (session.getDatabase().getSettings().optimizeInsertFromSelect) { Database db = session.getDatabase();
if (db.getSettings().optimizeInsertFromSelect) {
if (unionType == UnionType.UNION_ALL && target != null) { if (unionType == UnionType.UNION_ALL && target != null) {
if (sort == null && !distinct && maxRows == 0 && if (sort == null && !distinct && maxRows == 0 &&
offsetExpr == null && limitExpr == null) { offsetExpr == null && limitExpr == null) {
...@@ -189,7 +191,7 @@ public class SelectUnion extends Query { ...@@ -189,7 +191,7 @@ public class SelectUnion extends Query {
return lazyResult; return lazyResult;
} }
} }
LocalResult result = session.getDatabase().getResultFactory().create(session, expressionArray, columnCount); LocalResult result = db.getResultFactory().create(session, expressionArray, columnCount);
if (sort != null) { if (sort != null) {
result.setSortOrder(sort); result.setSortOrder(sort);
} }
...@@ -239,7 +241,7 @@ public class SelectUnion extends Query { ...@@ -239,7 +241,7 @@ public class SelectUnion extends Query {
break; break;
} }
case INTERSECT: { case INTERSECT: {
LocalResult temp = session.getDatabase().getResultFactory().create(session, expressionArray, columnCount); LocalResult temp = db.getResultFactory().create(session, expressionArray, columnCount);
temp.setDistinct(); temp.setDistinct();
while (l.next()) { while (l.next()) {
temp.addRow(convert(l.currentRow(), columnCount)); temp.addRow(convert(l.currentRow(), columnCount));
......
...@@ -162,6 +162,8 @@ public class Function extends Expression implements FunctionCall { ...@@ -162,6 +162,8 @@ public class Function extends Expression implements FunctionCall {
protected int scale; protected int scale;
protected long precision = PRECISION_UNKNOWN; protected long precision = PRECISION_UNKNOWN;
protected int displaySize; protected int displaySize;
protected String[] enumerators;
private final Database database; private final Database database;
static { static {
...@@ -892,7 +894,7 @@ public class Function extends Expression implements FunctionCall { ...@@ -892,7 +894,7 @@ public class Function extends Expression implements FunctionCall {
case CAST: case CAST:
case CONVERT: { case CONVERT: {
Mode mode = database.getMode(); Mode mode = database.getMode();
v0 = v0.convertTo(dataType, mode); v0 = v0.convertTo(dataType, MathUtils.convertLongToInt(precision), mode, null, enumerators);
v0 = v0.convertScale(mode.convertOnlyToSmallerScale, scale); v0 = v0.convertScale(mode.convertOnlyToSmallerScale, scale);
v0 = v0.convertPrecision(getPrecision(), false); v0 = v0.convertPrecision(getPrecision(), false);
result = v0; result = v0;
...@@ -2198,6 +2200,7 @@ public class Function extends Expression implements FunctionCall { ...@@ -2198,6 +2200,7 @@ public class Function extends Expression implements FunctionCall {
precision = col.getPrecision(); precision = col.getPrecision();
displaySize = col.getDisplaySize(); displaySize = col.getDisplaySize();
scale = col.getScale(); scale = col.getScale();
enumerators = col.getEnumerators();
} }
@Override @Override
...@@ -2598,7 +2601,7 @@ public class Function extends Expression implements FunctionCall { ...@@ -2598,7 +2601,7 @@ public class Function extends Expression implements FunctionCall {
case CAST: { case CAST: {
buff.append(args[0].getSQL()).append(" AS "). buff.append(args[0].getSQL()).append(" AS ").
append(new Column(null, dataType, precision, append(new Column(null, dataType, precision,
scale, displaySize).getCreateSQL()); scale, displaySize, enumerators).getCreateSQL());
break; break;
} }
case CONVERT: { case CONVERT: {
......
...@@ -307,6 +307,11 @@ public class Aggregate extends Expression { ...@@ -307,6 +307,11 @@ public class Aggregate extends Expression {
} }
lastGroupRowId = groupRowId; lastGroupRowId = groupRowId;
if (filterCondition != null) {
if (!filterCondition.getBooleanValue(session)) {
return;
}
}
AggregateData data = (AggregateData) select.getCurrentGroupExprData(this); AggregateData data = (AggregateData) select.getCurrentGroupExprData(this);
if (data == null) { if (data == null) {
data = AggregateData.create(type); data = AggregateData.create(type);
...@@ -315,39 +320,28 @@ public class Aggregate extends Expression { ...@@ -315,39 +320,28 @@ public class Aggregate extends Expression {
Value v = on == null ? null : on.getValue(session); Value v = on == null ? null : on.getValue(session);
if (type == AggregateType.GROUP_CONCAT) { if (type == AggregateType.GROUP_CONCAT) {
if (v != ValueNull.INSTANCE) { if (v != ValueNull.INSTANCE) {
v = v.convertTo(Value.STRING); v = updateCollecting(session, v.convertTo(Value.STRING));
if (orderByList != null) {
int size = orderByList.size();
Value[] array = new Value[1 + size];
array[0] = v;
for (int i = 0; i < size; i++) {
SelectOrderBy o = orderByList.get(i);
array[i + 1] = o.expression.getValue(session);
}
v = ValueArray.get(array);
}
} }
} } else if (type == AggregateType.ARRAY_AGG) {
if (type == AggregateType.ARRAY_AGG) {
if (v != ValueNull.INSTANCE) { if (v != ValueNull.INSTANCE) {
if (orderByList != null) { v = updateCollecting(session, v);
int size = orderByList.size();
Value[] array = new Value[1 + size];
array[0] = v;
for (int i = 0; i < size; i++) {
SelectOrderBy o = orderByList.get(i);
array[i + 1] = o.expression.getValue(session);
}
v = ValueArray.get(array);
}
} }
} }
if (filterCondition != null) { data.add(session.getDatabase(), dataType, distinct, v);
if (!filterCondition.getBooleanValue(session)) { }
return;
private Value updateCollecting(Session session, Value v) {
if (orderByList != null) {
int size = orderByList.size();
Value[] array = new Value[1 + size];
array[0] = v;
for (int i = 0; i < size; i++) {
SelectOrderBy o = orderByList.get(i);
array[i + 1] = o.expression.getValue(session);
} }
v = ValueArray.get(array);
} }
data.add(session.getDatabase(), dataType, distinct, v); return v;
} }
@Override @Override
......
...@@ -265,3 +265,6 @@ DROP VIEW V3; ...@@ -265,3 +265,6 @@ DROP VIEW V3;
DROP TABLE TEST; DROP TABLE TEST;
> ok > ok
SELECT CAST (2 AS ENUM('a', 'b', 'c', 'd'));
>> c
...@@ -794,4 +794,4 @@ minxf maxxf minyf maxyf bminxf bmaxxf bminyf bmaxyf ...@@ -794,4 +794,4 @@ minxf maxxf minyf maxyf bminxf bmaxxf bminyf bmaxyf
minxd maxxd minyd maxyd bminxd bmaxxd bminyd bmaxyd minxd maxxd minyd maxyd bminxd bmaxxd bminyd bmaxyd
interior envelopes multilinestring multipoint packed exterior normalization awkward determination subgeometries interior envelopes multilinestring multipoint packed exterior normalization awkward determination subgeometries
xym normalizes coord setz xyzm geometrycollection multipolygon mixup rings polygons rejection finite xym normalizes coord setz xyzm geometrycollection multipolygon mixup rings polygons rejection finite
pointzm pointz pointm dimensionality pointzm pointz pointm dimensionality redefine forum measures
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论