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

Remove getPrecision(), getScale(), and getDisplaySize() from Expression

上级 2d71c43f
......@@ -5841,37 +5841,37 @@ public class Parser {
do {
Expression expr = readExpression();
expr = expr.optimize(session);
int type = expr.getValueType();
TypeInfo type = expr.getType();
int valueType = type.getValueType();
long prec;
int scale, displaySize;
Column column;
String columnName = "C" + (i + 1);
if (rows.isEmpty()) {
if (type == Value.UNKNOWN) {
type = Value.STRING;
if (valueType == Value.UNKNOWN) {
valueType = Value.STRING;
}
DataType dt = DataType.getDataType(type);
DataType dt = DataType.getDataType(valueType);
prec = dt.defaultPrecision;
scale = dt.defaultScale;
displaySize = dt.defaultDisplaySize;
column = new Column(columnName, type, prec, scale,
displaySize);
column = new Column(columnName, valueType, prec, scale, displaySize);
columns.add(column);
}
prec = expr.getPrecision();
scale = expr.getScale();
displaySize = expr.getDisplaySize();
prec = type.getPrecision();
scale = type.getScale();
displaySize = type.getDisplaySize();
if (i >= columns.size()) {
throw DbException
.get(ErrorCode.COLUMN_COUNT_DOES_NOT_MATCH);
}
Column c = columns.get(i);
TypeInfo t = c.getType();
type = Value.getHigherOrder(t.getValueType(), type);
valueType = Value.getHigherOrder(t.getValueType(), valueType);
prec = Math.max(t.getPrecision(), prec);
scale = Math.max(t.getScale(), scale);
displaySize = Math.max(t.getDisplaySize(), displaySize);
column = new Column(columnName, type, prec, scale, displaySize);
column = new Column(columnName, valueType, prec, scale, displaySize);
columns.set(i, column);
row.add(expr);
i++;
......
......@@ -24,6 +24,7 @@ import org.h2.table.Table;
import org.h2.util.ColumnNamer;
import org.h2.value.DataType;
import org.h2.value.ExtTypeInfo;
import org.h2.value.TypeInfo;
import org.h2.value.Value;
/**
......@@ -180,17 +181,18 @@ public class CreateTable extends CommandWithColumns {
ColumnNamer columnNamer= new ColumnNamer(session);
for (int i = 0; i < columnCount; i++) {
Expression expr = expressions.get(i);
int type = expr.getValueType();
TypeInfo type = expr.getType();
int valueType = type.getValueType();
String name = columnNamer.getColumnName(expr,i,expr.getAlias());
long precision = expr.getPrecision();
int displaySize = expr.getDisplaySize();
DataType dt = DataType.getDataType(type);
long precision = type.getPrecision();
int displaySize = type.getDisplaySize();
DataType dt = DataType.getDataType(valueType);
if (precision > 0 && (dt.defaultPrecision == 0 ||
(dt.defaultPrecision > precision && dt.defaultPrecision < Byte.MAX_VALUE))) {
// dont' set precision to MAX_VALUE if this is the default
precision = dt.defaultPrecision;
}
int scale = expr.getScale();
int scale = type.getScale();
if (scale > 0 && (dt.defaultScale == 0 ||
(dt.defaultScale > scale && dt.defaultScale < precision))) {
scale = dt.defaultScale;
......@@ -211,7 +213,7 @@ public class CreateTable extends CommandWithColumns {
"Unable to resolve enumerators of expression");
}
}
Column col = new Column(name, type, precision, scale, displaySize, extTypeInfo);
Column col = new Column(name, valueType, precision, scale, displaySize, extTypeInfo);
addColumn(col);
}
}
......
......@@ -27,6 +27,7 @@ import org.h2.table.ColumnResolver;
import org.h2.table.Table;
import org.h2.table.TableFilter;
import org.h2.util.ColumnNamer;
import org.h2.value.TypeInfo;
import org.h2.value.Value;
import org.h2.value.ValueInt;
import org.h2.value.ValueNull;
......@@ -328,10 +329,11 @@ public class SelectUnion extends Query {
for (int i = 0; i < len; i++) {
Expression l = le.get(i);
Expression r = re.get(i);
int type = Value.getHigherOrder(l.getValueType(), r.getValueType());
long prec = Math.max(l.getPrecision(), r.getPrecision());
int scale = Math.max(l.getScale(), r.getScale());
int displaySize = Math.max(l.getDisplaySize(), r.getDisplaySize());
TypeInfo lType = l.getType(), rType = r.getType();
int type = Value.getHigherOrder(lType.getValueType(), rType.getValueType());
long prec = Math.max(lType.getPrecision(), rType.getPrecision());
int scale = Math.max(lType.getScale(), rType.getScale());
int displaySize = Math.max(lType.getDisplaySize(), rType.getDisplaySize());
String columnName = columnNamer.getColumnName(l,i,l.getAlias());
Column col = new Column(columnName, type, prec, scale, displaySize);
Expression e = new ExpressionColumn(session.getDatabase(), col);
......
......@@ -63,21 +63,6 @@ public class Alias extends Expression {
expr.setEvaluatable(tableFilter, b);
}
@Override
public int getScale() {
return expr.getScale();
}
@Override
public long getPrecision() {
return expr.getPrecision();
}
@Override
public int getDisplaySize() {
return expr.getDisplaySize();
}
@Override
public boolean isAutoIncrement() {
return expr.isAutoIncrement();
......
......@@ -12,7 +12,6 @@ import org.h2.expression.function.Function;
import org.h2.message.DbException;
import org.h2.table.ColumnResolver;
import org.h2.table.TableFilter;
import org.h2.util.MathUtils;
import org.h2.value.DataType;
import org.h2.value.TypeInfo;
import org.h2.value.Value;
......@@ -431,32 +430,6 @@ public class BinaryOperation extends Expression {
return dataType;
}
@Override
public long getPrecision() {
switch (opType) {
case CONCAT:
return left.getPrecision() + right.getPrecision();
default:
return Math.max(left.getPrecision(), right.getPrecision());
}
}
@Override
public int getDisplaySize() {
switch (opType) {
case CONCAT:
return MathUtils.convertLongToInt((long) left.getDisplaySize() +
(long) right.getDisplaySize());
default:
return Math.max(left.getDisplaySize(), right.getDisplaySize());
}
}
@Override
public int getScale() {
return Math.max(left.getScale(), right.getScale());
}
@Override
public void updateAggregate(Session session, int stage) {
left.updateAggregate(session, stage);
......
......@@ -127,27 +127,6 @@ public abstract class Expression {
*/
public abstract void setEvaluatable(TableFilter tableFilter, boolean value);
/**
* Get the scale of this expression.
*
* @return the scale
*/
public abstract int getScale();
/**
* Get the precision of this expression.
*
* @return the precision
*/
public abstract long getPrecision();
/**
* Get the display size of this expression.
*
* @return the display size
*/
public abstract int getDisplaySize();
/**
* Get the SQL statement of this expression.
* This may not always be the original SQL statement,
......
......@@ -243,21 +243,6 @@ public class ExpressionColumn extends Expression {
return column;
}
@Override
public int getScale() {
return column.getType().getScale();
}
@Override
public long getPrecision() {
return column.getType().getPrecision();
}
@Override
public int getDisplaySize() {
return column.getType().getDisplaySize();
}
public String getOriginalColumnName() {
return columnName;
}
......
......@@ -77,21 +77,6 @@ public class ExpressionList extends Expression {
}
}
@Override
public int getScale() {
return 0;
}
@Override
public long getPrecision() {
return Integer.MAX_VALUE;
}
@Override
public int getDisplaySize() {
return Integer.MAX_VALUE;
}
@Override
public StringBuilder getSQL(StringBuilder builder) {
builder.append(isArray ? "ARRAY [" : "ROW (");
......@@ -130,9 +115,7 @@ public class ExpressionList extends Expression {
ExpressionColumn[] expr = new ExpressionColumn[list.length];
for (int i = 0; i < list.length; i++) {
Expression e = list[i];
Column col = new Column("C" + (i + 1),
e.getValueType(), e.getPrecision(), e.getScale(),
e.getDisplaySize());
Column col = new Column("C" + (i + 1), e.getType());
expr[i] = new ExpressionColumn(session.getDatabase(), col);
}
return expr;
......
......@@ -293,21 +293,6 @@ public class IntervalOperation extends Expression {
return dataType;
}
@Override
public long getPrecision() {
return Math.max(left.getPrecision(), right.getPrecision());
}
@Override
public int getDisplaySize() {
return Math.max(left.getDisplaySize(), right.getDisplaySize());
}
@Override
public int getScale() {
return Math.max(left.getScale(), right.getScale());
}
@Override
public void updateAggregate(Session session, int stage) {
left.updateAggregate(session, stage);
......
......@@ -142,17 +142,6 @@ public class Parameter extends Expression implements ParameterInterface {
return 0;
}
@Override
public int getDisplaySize() {
if (value != null) {
return value.getType().getDisplaySize();
}
if (column != null) {
return column.getType().getDisplaySize();
}
return 0;
}
@Override
public void updateAggregate(Session session, int stage) {
// nothing to do
......
......@@ -58,21 +58,6 @@ public class Rownum extends Expression {
// nothing to do
}
@Override
public int getScale() {
return 0;
}
@Override
public long getPrecision() {
return ValueLong.PRECISION;
}
@Override
public int getDisplaySize() {
return ValueLong.DISPLAY_SIZE;
}
@Override
public String getSQL() {
return "ROWNUM()";
......
......@@ -57,21 +57,6 @@ public class SequenceValue extends Expression {
// nothing to do
}
@Override
public int getScale() {
return 0;
}
@Override
public long getPrecision() {
return ValueLong.PRECISION;
}
@Override
public int getDisplaySize() {
return ValueLong.DISPLAY_SIZE;
}
@Override
public StringBuilder getSQL(StringBuilder builder) {
builder.append("(NEXT VALUE FOR ");
......
......@@ -79,21 +79,6 @@ public class Subquery extends Expression {
query.setEvaluatable(tableFilter, b);
}
@Override
public int getScale() {
return getExpression().getScale();
}
@Override
public long getPrecision() {
return getExpression().getPrecision();
}
@Override
public int getDisplaySize() {
return getExpression().getDisplaySize();
}
@Override
public StringBuilder getSQL(StringBuilder builder) {
return builder.append('(').append(query.getPlanSQL()).append(')');
......
......@@ -73,21 +73,6 @@ public class UnaryOperation extends Expression {
return type.getValueType();
}
@Override
public long getPrecision() {
return arg.getPrecision();
}
@Override
public int getDisplaySize() {
return arg.getDisplaySize();
}
@Override
public int getScale() {
return arg.getScale();
}
@Override
public void updateAggregate(Session session, int stage) {
arg.updateAggregate(session, stage);
......
......@@ -126,21 +126,6 @@ public class ValueExpression extends Expression {
// nothing to do
}
@Override
public int getScale() {
return value.getType().getScale();
}
@Override
public long getPrecision() {
return value.getType().getPrecision();
}
@Override
public int getDisplaySize() {
return value.getType().getDisplaySize();
}
@Override
public StringBuilder getSQL(StringBuilder builder) {
if (this == DEFAULT) {
......
......@@ -31,27 +31,12 @@ public class Variable extends Expression {
return 0;
}
@Override
public int getDisplaySize() {
return lastValue.getType().getDisplaySize();
}
@Override
public long getPrecision() {
return lastValue.getType().getPrecision();
}
@Override
public StringBuilder getSQL(StringBuilder builder) {
builder.append('@');
return Parser.quoteIdentifier(builder, name);
}
@Override
public int getScale() {
return lastValue.getType().getScale();
}
@Override
public TypeInfo getType() {
return lastValue.getType();
......
......@@ -96,21 +96,6 @@ public class Wildcard extends Expression {
DbException.throwInternalError(toString());
}
@Override
public int getScale() {
throw DbException.throwInternalError(toString());
}
@Override
public long getPrecision() {
throw DbException.throwInternalError(toString());
}
@Override
public int getDisplaySize() {
throw DbException.throwInternalError(toString());
}
@Override
public String getTableAlias() {
return table;
......
......@@ -39,8 +39,6 @@ import org.h2.value.TypeInfo;
import org.h2.value.Value;
import org.h2.value.ValueArray;
import org.h2.value.ValueBoolean;
import org.h2.value.ValueDouble;
import org.h2.value.ValueInt;
import org.h2.value.ValueLong;
import org.h2.value.ValueNull;
import org.h2.value.ValueString;
......@@ -166,9 +164,7 @@ public class Aggregate extends AbstractAggregate {
private ArrayList<SelectOrderBy> orderByList;
private SortOrder orderBySort;
private TypeInfo type;
private int dataType, scale;
private long precision;
private int displaySize;
private int dataType;
/**
* Create a new aggregate object.
......@@ -613,9 +609,6 @@ public class Aggregate extends AbstractAggregate {
on = on.optimize(session);
type = on.getType();
dataType = on.getValueType();
scale = on.getScale();
precision = on.getPrecision();
displaySize = on.getDisplaySize();
}
if (orderByList != null) {
for (SelectOrderBy o : orderByList) {
......@@ -630,29 +623,19 @@ public class Aggregate extends AbstractAggregate {
case GROUP_CONCAT:
type = TypeInfo.TYPE_STRING_DEFAULT;
dataType = Value.STRING;
scale = 0;
precision = displaySize = Integer.MAX_VALUE;
break;
case COUNT_ALL:
case COUNT:
type = TypeInfo.TYPE_LONG;
dataType = Value.LONG;
scale = 0;
precision = ValueLong.PRECISION;
displaySize = ValueLong.DISPLAY_SIZE;
break;
case SELECTIVITY:
type = TypeInfo.TYPE_INT;
dataType = Value.INT;
scale = 0;
precision = ValueInt.PRECISION;
displaySize = ValueInt.DISPLAY_SIZE;
break;
case HISTOGRAM:
type = TypeInfo.TYPE_ARRAY;
dataType = Value.ARRAY;
scale = 0;
precision = displaySize = Integer.MAX_VALUE;
break;
case SUM:
if (dataType == Value.BOOLEAN) {
......@@ -682,17 +665,11 @@ public class Aggregate extends AbstractAggregate {
case VAR_SAMP:
type = TypeInfo.TYPE_DOUBLE;
dataType = Value.DOUBLE;
precision = ValueDouble.PRECISION;
displaySize = ValueDouble.DISPLAY_SIZE;
scale = 0;
break;
case EVERY:
case ANY:
type = TypeInfo.TYPE_BOOLEAN;
dataType = Value.BOOLEAN;
precision = ValueBoolean.PRECISION;
displaySize = ValueBoolean.DISPLAY_SIZE;
scale = 0;
break;
case BIT_AND:
case BIT_OR:
......@@ -703,14 +680,10 @@ public class Aggregate extends AbstractAggregate {
case ARRAY_AGG:
type = TypeInfo.TYPE_ARRAY;
dataType = Value.ARRAY;
scale = 0;
precision = displaySize = Integer.MAX_VALUE;
break;
case ENVELOPE:
type = TypeInfo.TYPE_GEOMETRY;
dataType = Value.GEOMETRY;
scale = 0;
precision = displaySize = Integer.MAX_VALUE;
break;
default:
DbException.throwInternalError("type=" + aggregateType);
......@@ -734,21 +707,6 @@ public class Aggregate extends AbstractAggregate {
super.setEvaluatable(tableFilter, b);
}
@Override
public int getScale() {
return scale;
}
@Override
public long getPrecision() {
return precision;
}
@Override
public int getDisplaySize() {
return displaySize;
}
private StringBuilder getSQLGroupConcat(StringBuilder builder) {
builder.append("GROUP_CONCAT(");
if (distinct) {
......
......@@ -54,21 +54,6 @@ public class JavaAggregate extends AbstractAggregate {
return cost;
}
@Override
public long getPrecision() {
return Integer.MAX_VALUE;
}
@Override
public int getDisplaySize() {
return Integer.MAX_VALUE;
}
@Override
public int getScale() {
return DataType.getDataType(dataType).defaultScale;
}
@Override
public StringBuilder getSQL(StringBuilder builder) {
Parser.quoteIdentifier(builder, userAggregate.getName()).append('(');
......
......@@ -521,66 +521,6 @@ public class WindowFunction extends DataAnalysisOperation {
}
}
@Override
public int getScale() {
switch (type) {
case LEAD:
case LAG:
case FIRST_VALUE:
case LAST_VALUE:
case NTH_VALUE:
return args[0].getScale();
default:
return 0;
}
}
@Override
public long getPrecision() {
switch (type) {
case ROW_NUMBER:
case RANK:
case DENSE_RANK:
case NTILE:
return ValueLong.PRECISION;
case PERCENT_RANK:
case CUME_DIST:
case RATIO_TO_REPORT:
return ValueDouble.PRECISION;
case LEAD:
case LAG:
case FIRST_VALUE:
case LAST_VALUE:
case NTH_VALUE:
return args[0].getPrecision();
default:
throw DbException.throwInternalError("type=" + type);
}
}
@Override
public int getDisplaySize() {
switch (type) {
case ROW_NUMBER:
case RANK:
case DENSE_RANK:
case NTILE:
return ValueLong.DISPLAY_SIZE;
case PERCENT_RANK:
case CUME_DIST:
case RATIO_TO_REPORT:
return ValueDouble.DISPLAY_SIZE;
case LEAD:
case LAG:
case FIRST_VALUE:
case LAST_VALUE:
case NTH_VALUE:
return args[0].getDisplaySize();
default:
throw DbException.throwInternalError("type=" + type);
}
}
@Override
public StringBuilder getSQL(StringBuilder builder) {
String name = type.getSQL();
......
......@@ -234,7 +234,7 @@ public class Comparison extends Condition {
if (constType != resType) {
Column column = ((ExpressionColumn) left).getColumn();
right = ValueExpression.get(r.convertTo(resType,
MathUtils.convertLongToInt(left.getPrecision()),
MathUtils.convertLongToInt(left.getType().getPrecision()),
session.getDatabase().getMode(), column, column.getType().getExtTypeInfo()));
}
} else if (right instanceof Parameter) {
......
......@@ -8,7 +8,6 @@ package org.h2.expression.condition;
import org.h2.expression.Expression;
import org.h2.value.TypeInfo;
import org.h2.value.Value;
import org.h2.value.ValueBoolean;
/**
* Represents a condition returning a boolean value, or NULL.
......@@ -25,19 +24,4 @@ abstract class Condition extends Expression {
return Value.BOOLEAN;
}
@Override
public int getScale() {
return 0;
}
@Override
public long getPrecision() {
return ValueBoolean.PRECISION;
}
@Override
public int getDisplaySize() {
return ValueBoolean.DISPLAY_SIZE;
}
}
......@@ -901,9 +901,10 @@ public class Function extends Expression implements FunctionCall {
case CAST:
case CONVERT: {
Mode mode = database.getMode();
v0 = v0.convertTo(dataType, MathUtils.convertLongToInt(getPrecision()), mode, null, extTypeInfo);
v0 = v0.convertScale(mode.convertOnlyToSmallerScale, getScale());
v0 = v0.convertPrecision(getPrecision(), false);
TypeInfo type = this.type;
v0 = v0.convertTo(dataType, MathUtils.convertLongToInt(type.getPrecision()), mode, null, extTypeInfo);
v0 = v0.convertScale(mode.convertOnlyToSmallerScale, type.getScale());
v0 = v0.convertPrecision(type.getPrecision(), false);
result = v0;
break;
}
......@@ -2394,12 +2395,13 @@ public class Function extends Expression implements FunctionCall {
d = 0;
for (Expression e : args) {
if (e != ValueExpression.getNull()) {
int type = e.getValueType();
if (type != Value.UNKNOWN && type != Value.NULL) {
t = Value.getHigherOrder(t, type);
s = Math.max(s, e.getScale());
p = Math.max(p, e.getPrecision());
d = Math.max(d, e.getDisplaySize());
TypeInfo type = e.getType();
int valueType = type.getValueType();
if (valueType != Value.UNKNOWN && valueType != Value.NULL) {
t = Value.getHigherOrder(t, valueType);
s = Math.max(s, type.getScale());
p = Math.max(p, type.getPrecision());
d = Math.max(d, type.getDisplaySize());
}
}
}
......@@ -2424,24 +2426,26 @@ public class Function extends Expression implements FunctionCall {
for (int i = 2, len = args.length; i < len; i += 2) {
Expression then = args[i];
if (then != ValueExpression.getNull()) {
int type = then.getValueType();
if (type != Value.UNKNOWN && type != Value.NULL) {
t = Value.getHigherOrder(t, type);
s = Math.max(s, then.getScale());
p = Math.max(p, then.getPrecision());
d = Math.max(d, then.getDisplaySize());
TypeInfo type = then.getType();
int valueType = type.getValueType();
if (valueType != Value.UNKNOWN && valueType != Value.NULL) {
t = Value.getHigherOrder(t, valueType);
s = Math.max(s, type.getScale());
p = Math.max(p, type.getPrecision());
d = Math.max(d, type.getDisplaySize());
}
}
}
if (args.length % 2 == 0) {
Expression elsePart = args[args.length - 1];
if (elsePart != ValueExpression.getNull()) {
int type = elsePart.getValueType();
if (type != Value.UNKNOWN && type != Value.NULL) {
t = Value.getHigherOrder(t, type);
s = Math.max(s, elsePart.getScale());
p = Math.max(p, elsePart.getPrecision());
d = Math.max(d, elsePart.getDisplaySize());
TypeInfo type = elsePart.getType();
int valueType = type.getValueType();
if (valueType != Value.UNKNOWN && valueType != Value.NULL) {
t = Value.getHigherOrder(t, valueType);
s = Math.max(s, type.getScale());
p = Math.max(p, type.getPrecision());
d = Math.max(d, type.getDisplaySize());
}
}
}
......@@ -2453,13 +2457,15 @@ public class Function extends Expression implements FunctionCall {
}
break;
}
case CASEWHEN:
t = Value.getHigherOrder(args[1].getValueType(), args[2].getValueType());
p = Math.max(args[1].getPrecision(), args[2].getPrecision());
d = Math.max(args[1].getDisplaySize(), args[2].getDisplaySize());
s = Math.max(args[1].getScale(), args[2].getScale());
case CASEWHEN: {
TypeInfo t1 = args[1].getType(), t2 = args[2].getType();
t = Value.getHigherOrder(t1.getValueType(), t2.getValueType());
p = Math.max(t1.getPrecision(), t2.getPrecision());
d = Math.max(t1.getDisplaySize(), t2.getDisplaySize());
s = Math.max(t1.getScale(), t2.getScale());
break;
case NVL2:
}
case NVL2: {
switch (args[1].getValueType()) {
case Value.STRING:
case Value.CLOB:
......@@ -2471,10 +2477,12 @@ public class Function extends Expression implements FunctionCall {
t = Value.getHigherOrder(args[1].getValueType(), args[2].getValueType());
break;
}
p = Math.max(args[1].getPrecision(), args[2].getPrecision());
d = Math.max(args[1].getDisplaySize(), args[2].getDisplaySize());
s = Math.max(args[1].getScale(), args[2].getScale());
TypeInfo t1 = args[1].getType(), t2 = args[2].getType();
p = Math.max(t1.getPrecision(), t2.getPrecision());
d = Math.max(t1.getDisplaySize(), t2.getDisplaySize());
s = Math.max(t1.getScale(), t2.getScale());
break;
}
case CAST:
case CONVERT:
case TRUNCATE_VALUE:
......@@ -2512,11 +2520,12 @@ public class Function extends Expression implements FunctionCall {
break;
case ABS:
case FLOOR:
case ROUND:
t = p0.getValueType();
s = p0.getScale();
p = p0.getPrecision();
d = p0.getDisplaySize();
case ROUND: {
TypeInfo type = p0.getType();
t = type.getValueType();
s = type.getScale();
p = type.getPrecision();
d = type.getDisplaySize();
if (t == Value.NULL) {
t = Value.INT;
p = ValueInt.PRECISION;
......@@ -2524,12 +2533,13 @@ public class Function extends Expression implements FunctionCall {
s = 0;
}
break;
}
case SET: {
Expression p1 = args[1];
t = p1.getValueType();
p = p1.getPrecision();
s = p1.getScale();
d = p1.getDisplaySize();
TypeInfo type = args[1].getType();
t = type.getValueType();
p = type.getPrecision();
s = type.getScale();
d = type.getDisplaySize();
if (!(p0 instanceof Variable)) {
throw DbException.get(
ErrorCode.CAN_ONLY_ASSIGN_TO_VARIABLE_1, p0.getSQL());
......@@ -2550,7 +2560,7 @@ public class Function extends Expression implements FunctionCall {
case SUBSTRING:
case SUBSTR: {
t = info.returnDataType;
p = args[0].getPrecision();
p = args[0].getType().getPrecision();
s = 0;
if (args[1].isConstant()) {
// if only two arguments are used,
......@@ -2566,18 +2576,22 @@ public class Function extends Expression implements FunctionCall {
break;
}
case ENCRYPT:
case DECRYPT:
case DECRYPT: {
t = info.returnDataType;
p = args[2].getPrecision();
d = args[2].getDisplaySize();
TypeInfo type = args[2].getType();
p = type.getPrecision();
d = type.getDisplaySize();
s = 0;
break;
case COMPRESS:
}
case COMPRESS: {
t = info.returnDataType;
p = args[0].getPrecision();
d = args[0].getDisplaySize();
TypeInfo type = args[0].getType();
p = type.getPrecision();
d = type.getDisplaySize();
s = 0;
break;
}
case CHAR:
t = info.returnDataType;
p = 1;
......@@ -2590,8 +2604,9 @@ public class Function extends Expression implements FunctionCall {
d = 0;
s = 0;
for (Expression e : args) {
p += e.getPrecision();
d = MathUtils.convertLongToInt((long) d + e.getDisplaySize());
TypeInfo type = e.getType();
p += type.getPrecision();
d = MathUtils.convertLongToInt((long) d + type.getDisplaySize());
if (p < 0) {
p = Long.MAX_VALUE;
}
......@@ -2599,7 +2614,7 @@ public class Function extends Expression implements FunctionCall {
break;
case HEXTORAW:
t = info.returnDataType;
p = (args[0].getPrecision() + 3) / 4;
p = (args[0].getType().getPrecision() + 3) / 4;
d = MathUtils.convertLongToInt(p);
s = 0;
break;
......@@ -2612,15 +2627,17 @@ public class Function extends Expression implements FunctionCall {
case UPPER:
case TRIM:
case STRINGDECODE:
case UTF8TOSTRING:
case UTF8TOSTRING: {
t = info.returnDataType;
p = args[0].getPrecision();
d = args[0].getDisplaySize();
TypeInfo type = args[0].getType();
p = type.getPrecision();
d = type.getDisplaySize();
s = 0;
break;
}
case RAWTOHEX:
t = info.returnDataType;
p = args[0].getPrecision() * 4;
p = args[0].getType().getPrecision() * 4;
d = MathUtils.convertLongToInt(p);
s = 0;
break;
......@@ -2666,21 +2683,6 @@ public class Function extends Expression implements FunctionCall {
}
}
@Override
public int getScale() {
return type.getScale();
}
@Override
public long getPrecision() {
return type.getPrecision();
}
@Override
public int getDisplaySize() {
return type.getDisplaySize();
}
@Override
public StringBuilder getSQL(StringBuilder builder) {
builder.append(info.name);
......
......@@ -14,7 +14,6 @@ import org.h2.expression.ExpressionVisitor;
import org.h2.expression.ValueExpression;
import org.h2.table.ColumnResolver;
import org.h2.table.TableFilter;
import org.h2.value.DataType;
import org.h2.value.TypeInfo;
import org.h2.value.Value;
import org.h2.value.ValueArray;
......@@ -81,21 +80,6 @@ public class JavaFunction extends Expression implements FunctionCall {
}
}
@Override
public int getScale() {
return DataType.getDataType(getValueType()).defaultScale;
}
@Override
public long getPrecision() {
return Integer.MAX_VALUE;
}
@Override
public int getDisplaySize() {
return Integer.MAX_VALUE;
}
@Override
public StringBuilder getSQL(StringBuilder builder) {
// TODO always append the schema once FUNCTIONS_IN_SCHEMA is enabled
......
......@@ -145,17 +145,17 @@ public abstract class LazyResult implements ResultInterface {
@Override
public long getColumnPrecision(int i) {
return expressions[i].getPrecision();
return expressions[i].getType().getPrecision();
}
@Override
public int getColumnScale(int i) {
return expressions[i].getScale();
return expressions[i].getType().getScale();
}
@Override
public int getDisplaySize(int i) {
return expressions[i].getDisplaySize();
return expressions[i].getType().getDisplaySize();
}
@Override
......
......@@ -529,7 +529,7 @@ public class LocalResultImpl implements LocalResult {
@Override
public int getDisplaySize(int i) {
return expressions[i].getDisplaySize();
return expressions[i].getType().getDisplaySize();
}
@Override
......@@ -544,7 +544,7 @@ public class LocalResultImpl implements LocalResult {
@Override
public long getColumnPrecision(int i) {
return expressions[i].getPrecision();
return expressions[i].getType().getPrecision();
}
@Override
......@@ -559,7 +559,7 @@ public class LocalResultImpl implements LocalResult {
@Override
public int getColumnScale(int i) {
return expressions[i].getScale();
return expressions[i].getType().getScale();
}
/**
......
......@@ -40,6 +40,7 @@ import org.h2.util.StringUtils;
import org.h2.util.Utils;
import org.h2.value.DataType;
import org.h2.value.ExtTypeInfo;
import org.h2.value.TypeInfo;
import org.h2.value.Value;
/**
......@@ -181,28 +182,29 @@ public class TableView extends Table {
for (int i = 0; i < count; i++) {
Expression expr = expressions.get(i);
String name = null;
int type = Value.UNKNOWN;
int valueType = Value.UNKNOWN;
if (columnTemplates != null && columnTemplates.length > i) {
name = columnTemplates[i].getName();
type = columnTemplates[i].getType().getValueType();
valueType = columnTemplates[i].getType().getValueType();
}
if (name == null) {
name = expr.getAlias();
}
name = columnNamer.getColumnName(expr, i, name);
if (type == Value.UNKNOWN) {
type = expr.getValueType();
if (valueType == Value.UNKNOWN) {
valueType = expr.getValueType();
}
long precision = expr.getPrecision();
int scale = expr.getScale();
int displaySize = expr.getDisplaySize();
TypeInfo type = expr.getType();
long precision = type.getPrecision();
int scale = type.getScale();
int displaySize = type.getDisplaySize();
ExtTypeInfo extTypeInfo = null;
if (DataType.isExtInfoType(type)) {
if (DataType.isExtInfoType(valueType)) {
if (expr instanceof ExpressionColumn) {
extTypeInfo = ((ExpressionColumn) expr).getColumn().getType().getExtTypeInfo();
}
}
Column col = new Column(name, type, precision, scale, displaySize, extTypeInfo);
Column col = new Column(name, valueType, precision, scale, displaySize, extTypeInfo);
col.setTable(this, i);
// Fetch check constraint from view column source
ExpressionColumn fromColumn = null;
......
......@@ -18,6 +18,8 @@ public final class ExtTypeInfoEnum extends ExtTypeInfo {
private final String[] enumerators, cleaned;
private TypeInfo type;
/**
* Returns enumerators for the two specified values for a binary operation.
*
......@@ -92,6 +94,21 @@ public final class ExtTypeInfoEnum extends ExtTypeInfo {
this.cleaned = Arrays.equals(cleaned, enumerators) ? enumerators : cleaned;
}
TypeInfo getType() {
TypeInfo type = this.type;
if (type == null) {
int p = 0;
for (String s : enumerators) {
int l = s.length();
if (l > p) {
p = l;
}
}
this.type = type = new TypeInfo(Value.ENUM, p, 0, p, this);
}
return type;
}
@Override
public Value cast(Value value) {
switch (value.getValueType()) {
......
......@@ -19,7 +19,7 @@ public class ValueEnum extends ValueEnumBase {
@Override
public TypeInfo getType() {
return new TypeInfo(ENUM, PRECISION, 0, DISPLAY_SIZE, enumerators);
return enumerators.getType();
}
public ExtTypeInfoEnum getEnumerators() {
......
......@@ -255,9 +255,9 @@ SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME = 'E' ORDER BY TABLE_
> ------------- ------------ ---------- ----------- ---------------- -------------- ------------- ----------- -------------- ----------- --------- ------------------------ ---------------------- ----------------- ----------------------- ------------- ------------------ ------------- ------------------ ------------------ -------------- --------- -------- ----------- ----------- ---------------- ------------- ------- ---------------- -------------- ---------------- ----------
> SCRIPT PUBLIC TEST E 1 null null null null YES 1111 2147483647 2147483647 2147483647 10 0 null null null Unicode OFF ENUM 1 FALSE 50 null null ENUM('A', 'B') null TRUE
> SCRIPT PUBLIC V E 1 null null null null YES 1111 2147483647 2147483647 2147483647 10 0 null null null Unicode OFF ENUM 1 FALSE 50 null null ENUM('A', 'B') null TRUE
> SCRIPT PUBLIC V1 E 1 null null null null YES 4 2147483647 2147483647 2147483647 10 0 null null null Unicode OFF INTEGER 1 FALSE 50 null null INTEGER null TRUE
> SCRIPT PUBLIC V2 E 1 null null null null YES 4 2147483647 2147483647 2147483647 10 0 null null null Unicode OFF INTEGER 1 FALSE 50 null null INTEGER null TRUE
> SCRIPT PUBLIC V3 E 1 null null null null YES 4 2147483647 2147483647 2147483647 10 0 null null null Unicode OFF INTEGER 1 FALSE 50 null null INTEGER null TRUE
> SCRIPT PUBLIC V1 E 1 null null null null YES 4 10 10 10 10 0 null null null Unicode OFF INTEGER 1 FALSE 50 null null INTEGER null TRUE
> SCRIPT PUBLIC V2 E 1 null null null null YES 4 10 10 10 10 0 null null null Unicode OFF INTEGER 1 FALSE 50 null null INTEGER null TRUE
> SCRIPT PUBLIC V3 E 1 null null null null YES 4 10 10 10 10 0 null null null Unicode OFF INTEGER 1 FALSE 50 null null INTEGER null TRUE
> rows (ordered): 5
DROP VIEW V;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论