提交 41a502e3 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Use single type info field in Function

上级 a03cc5e6
...@@ -61,7 +61,6 @@ import org.h2.util.MathUtils; ...@@ -61,7 +61,6 @@ import org.h2.util.MathUtils;
import org.h2.util.StringUtils; import org.h2.util.StringUtils;
import org.h2.util.Utils; import org.h2.util.Utils;
import org.h2.value.DataType; import org.h2.value.DataType;
import org.h2.value.ExtTypeInfo;
import org.h2.value.TypeInfo; import org.h2.value.TypeInfo;
import org.h2.value.Value; import org.h2.value.Value;
import org.h2.value.ValueArray; import org.h2.value.ValueArray;
...@@ -164,9 +163,6 @@ public class Function extends Expression implements FunctionCall { ...@@ -164,9 +163,6 @@ public class Function extends Expression implements FunctionCall {
protected final FunctionInfo info; protected final FunctionInfo info;
private ArrayList<Expression> varArgs; private ArrayList<Expression> varArgs;
protected TypeInfo type; protected TypeInfo type;
protected int dataType;
protected ExtTypeInfo extTypeInfo;
private final Database database; private final Database database;
...@@ -931,7 +927,7 @@ public class Function extends Expression implements FunctionCall { ...@@ -931,7 +927,7 @@ public class Function extends Expression implements FunctionCall {
if (v0 == ValueNull.INSTANCE) { if (v0 == ValueNull.INSTANCE) {
result = getNullOrValue(session, args, values, 1); result = getNullOrValue(session, args, values, 1);
} }
result = result.convertTo(dataType, database.getMode()); result = result.convertTo(type, database.getMode(), null);
break; break;
} }
case CASEWHEN: { case CASEWHEN: {
...@@ -941,7 +937,7 @@ public class Function extends Expression implements FunctionCall { ...@@ -941,7 +937,7 @@ public class Function extends Expression implements FunctionCall {
} else { } else {
v = getNullOrValue(session, args, values, 1); v = getNullOrValue(session, args, values, 1);
} }
result = v.convertTo(dataType); result = v.convertTo(type, database.getMode(), null);
break; break;
} }
case DECODE: { case DECODE: {
...@@ -958,7 +954,7 @@ public class Function extends Expression implements FunctionCall { ...@@ -958,7 +954,7 @@ public class Function extends Expression implements FunctionCall {
} }
Value v = index < 0 ? ValueNull.INSTANCE : Value v = index < 0 ? ValueNull.INSTANCE :
getNullOrValue(session, args, values, index); getNullOrValue(session, args, values, index);
result = v.convertTo(dataType); result = v.convertTo(type, database.getMode(), null);
break; break;
} }
case NVL2: { case NVL2: {
...@@ -968,7 +964,7 @@ public class Function extends Expression implements FunctionCall { ...@@ -968,7 +964,7 @@ public class Function extends Expression implements FunctionCall {
} else { } else {
v = getNullOrValue(session, args, values, 1); v = getNullOrValue(session, args, values, 1);
} }
result = v.convertTo(dataType); result = v.convertTo(type, database.getMode(), null);
break; break;
} }
case COALESCE: { case COALESCE: {
...@@ -976,7 +972,7 @@ public class Function extends Expression implements FunctionCall { ...@@ -976,7 +972,7 @@ public class Function extends Expression implements FunctionCall {
for (int i = 0; i < args.length; i++) { for (int i = 0; i < args.length; i++) {
Value v = getNullOrValue(session, args, values, i); Value v = getNullOrValue(session, args, values, i);
if (v != ValueNull.INSTANCE) { if (v != ValueNull.INSTANCE) {
result = v.convertTo(dataType); result = v.convertTo(type, database.getMode(), null);
break; break;
} }
} }
...@@ -988,7 +984,7 @@ public class Function extends Expression implements FunctionCall { ...@@ -988,7 +984,7 @@ public class Function extends Expression implements FunctionCall {
for (int i = 0; i < args.length; i++) { for (int i = 0; i < args.length; i++) {
Value v = getNullOrValue(session, args, values, i); Value v = getNullOrValue(session, args, values, i);
if (v != ValueNull.INSTANCE) { if (v != ValueNull.INSTANCE) {
v = v.convertTo(dataType); v = v.convertTo(type, database.getMode(), null);
if (result == ValueNull.INSTANCE) { if (result == ValueNull.INSTANCE) {
result = v; result = v;
} else { } else {
...@@ -1039,7 +1035,7 @@ public class Function extends Expression implements FunctionCall { ...@@ -1039,7 +1035,7 @@ public class Function extends Expression implements FunctionCall {
then = args[args.length - 1]; then = args[args.length - 1];
} }
Value v = then == null ? ValueNull.INSTANCE : then.getValue(session); Value v = then == null ? ValueNull.INSTANCE : then.getValue(session);
result = v.convertTo(dataType); result = v.convertTo(type, database.getMode(), null);
break; break;
} }
case ARRAY_GET: { case ARRAY_GET: {
...@@ -2159,7 +2155,7 @@ public class Function extends Expression implements FunctionCall { ...@@ -2159,7 +2155,7 @@ public class Function extends Expression implements FunctionCall {
@Override @Override
public int getValueType() { public int getValueType() {
return dataType; return type.getValueType();
} }
@Override @Override
...@@ -2296,8 +2292,6 @@ public class Function extends Expression implements FunctionCall { ...@@ -2296,8 +2292,6 @@ public class Function extends Expression implements FunctionCall {
public void setDataType(Column col) { public void setDataType(Column col) {
TypeInfo type = col.getType(); TypeInfo type = col.getType();
this.type = type; this.type = type;
dataType = type.getValueType();
extTypeInfo = type.getExtTypeInfo();
} }
@Override @Override
...@@ -2474,7 +2468,7 @@ public class Function extends Expression implements FunctionCall { ...@@ -2474,7 +2468,7 @@ public class Function extends Expression implements FunctionCall {
case TRUNCATE_VALUE: case TRUNCATE_VALUE:
if (type != null) { if (type != null) {
// data type, precision and scale is already set // data type, precision and scale is already set
t = dataType; t = type.getValueType();
p = type.getPrecision(); p = type.getPrecision();
s = type.getScale(); s = type.getScale();
} else { } else {
...@@ -2630,8 +2624,7 @@ public class Function extends Expression implements FunctionCall { ...@@ -2630,8 +2624,7 @@ public class Function extends Expression implements FunctionCall {
p = type.maxPrecision; p = type.maxPrecision;
s = type.defaultScale; s = type.defaultScale;
} }
type = TypeInfo.getTypeInfo(t, p, s, extTypeInfo); type = TypeInfo.getTypeInfo(t, p, s, type != null ? type.getExtTypeInfo() : null);
dataType = t;
if (allConst) { if (allConst) {
Value v = getValue(session); Value v = getValue(session);
if (v == ValueNull.INSTANCE) { if (v == ValueNull.INSTANCE) {
......
...@@ -202,8 +202,7 @@ public class FunctionsMySQL extends FunctionsBase { ...@@ -202,8 +202,7 @@ public class FunctionsMySQL extends FunctionsBase {
if (allConst) { if (allConst) {
return ValueExpression.get(getValue(session)); return ValueExpression.get(getValue(session));
} }
dataType = info.returnDataType; type = TypeInfo.getTypeInfo(info.returnDataType);
type = TypeInfo.getTypeInfo(dataType);
return this; return this;
} }
......
...@@ -291,15 +291,17 @@ public class TypeInfo { ...@@ -291,15 +291,17 @@ public class TypeInfo {
case Value.CLOB: case Value.CLOB:
return new TypeInfo(type, precision, 0, MathUtils.convertLongToInt(precision), null); return new TypeInfo(type, precision, 0, MathUtils.convertLongToInt(precision), null);
case Value.GEOMETRY: case Value.GEOMETRY:
if (extTypeInfo == null) { if (extTypeInfo instanceof ExtTypeInfoGeometry) {
return new TypeInfo(Value.GEOMETRY, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, extTypeInfo);
} else {
return TYPE_GEOMETRY; return TYPE_GEOMETRY;
} }
return new TypeInfo(Value.GEOMETRY, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, extTypeInfo);
case Value.ENUM: case Value.ENUM:
if (extTypeInfo == null) { if (extTypeInfo instanceof ExtTypeInfoEnum) {
return new TypeInfo(Value.ENUM, ValueEnum.PRECISION, 0, ValueEnum.DISPLAY_SIZE, extTypeInfo);
} else {
return TYPE_ENUM_UNDEFINED; return TYPE_ENUM_UNDEFINED;
} }
return new TypeInfo(Value.ENUM, ValueEnum.PRECISION, 0, ValueEnum.DISPLAY_SIZE, extTypeInfo);
case Value.INTERVAL_YEAR: case Value.INTERVAL_YEAR:
case Value.INTERVAL_MONTH: case Value.INTERVAL_MONTH:
case Value.INTERVAL_DAY: case Value.INTERVAL_DAY:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论