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

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

上级 2d71c43f
...@@ -5841,37 +5841,37 @@ public class Parser { ...@@ -5841,37 +5841,37 @@ public class Parser {
do { do {
Expression expr = readExpression(); Expression expr = readExpression();
expr = expr.optimize(session); expr = expr.optimize(session);
int type = expr.getValueType(); TypeInfo type = expr.getType();
int valueType = type.getValueType();
long prec; long prec;
int scale, displaySize; int scale, displaySize;
Column column; Column column;
String columnName = "C" + (i + 1); String columnName = "C" + (i + 1);
if (rows.isEmpty()) { if (rows.isEmpty()) {
if (type == Value.UNKNOWN) { if (valueType == Value.UNKNOWN) {
type = Value.STRING; valueType = Value.STRING;
} }
DataType dt = DataType.getDataType(type); DataType dt = DataType.getDataType(valueType);
prec = dt.defaultPrecision; prec = dt.defaultPrecision;
scale = dt.defaultScale; scale = dt.defaultScale;
displaySize = dt.defaultDisplaySize; displaySize = dt.defaultDisplaySize;
column = new Column(columnName, type, prec, scale, column = new Column(columnName, valueType, prec, scale, displaySize);
displaySize);
columns.add(column); columns.add(column);
} }
prec = expr.getPrecision(); prec = type.getPrecision();
scale = expr.getScale(); scale = type.getScale();
displaySize = expr.getDisplaySize(); displaySize = type.getDisplaySize();
if (i >= columns.size()) { if (i >= columns.size()) {
throw DbException throw DbException
.get(ErrorCode.COLUMN_COUNT_DOES_NOT_MATCH); .get(ErrorCode.COLUMN_COUNT_DOES_NOT_MATCH);
} }
Column c = columns.get(i); Column c = columns.get(i);
TypeInfo t = c.getType(); TypeInfo t = c.getType();
type = Value.getHigherOrder(t.getValueType(), type); valueType = Value.getHigherOrder(t.getValueType(), valueType);
prec = Math.max(t.getPrecision(), prec); prec = Math.max(t.getPrecision(), prec);
scale = Math.max(t.getScale(), scale); scale = Math.max(t.getScale(), scale);
displaySize = Math.max(t.getDisplaySize(), displaySize); 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); columns.set(i, column);
row.add(expr); row.add(expr);
i++; i++;
......
...@@ -24,6 +24,7 @@ import org.h2.table.Table; ...@@ -24,6 +24,7 @@ import org.h2.table.Table;
import org.h2.util.ColumnNamer; import org.h2.util.ColumnNamer;
import org.h2.value.DataType; import org.h2.value.DataType;
import org.h2.value.ExtTypeInfo; import org.h2.value.ExtTypeInfo;
import org.h2.value.TypeInfo;
import org.h2.value.Value; import org.h2.value.Value;
/** /**
...@@ -180,17 +181,18 @@ public class CreateTable extends CommandWithColumns { ...@@ -180,17 +181,18 @@ public class CreateTable extends CommandWithColumns {
ColumnNamer columnNamer= new ColumnNamer(session); ColumnNamer columnNamer= new ColumnNamer(session);
for (int i = 0; i < columnCount; i++) { for (int i = 0; i < columnCount; i++) {
Expression expr = expressions.get(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()); String name = columnNamer.getColumnName(expr,i,expr.getAlias());
long precision = expr.getPrecision(); long precision = type.getPrecision();
int displaySize = expr.getDisplaySize(); int displaySize = type.getDisplaySize();
DataType dt = DataType.getDataType(type); DataType dt = DataType.getDataType(valueType);
if (precision > 0 && (dt.defaultPrecision == 0 || if (precision > 0 && (dt.defaultPrecision == 0 ||
(dt.defaultPrecision > precision && dt.defaultPrecision < Byte.MAX_VALUE))) { (dt.defaultPrecision > precision && dt.defaultPrecision < Byte.MAX_VALUE))) {
// dont' set precision to MAX_VALUE if this is the default // dont' set precision to MAX_VALUE if this is the default
precision = dt.defaultPrecision; precision = dt.defaultPrecision;
} }
int scale = expr.getScale(); int scale = type.getScale();
if (scale > 0 && (dt.defaultScale == 0 || if (scale > 0 && (dt.defaultScale == 0 ||
(dt.defaultScale > scale && dt.defaultScale < precision))) { (dt.defaultScale > scale && dt.defaultScale < precision))) {
scale = dt.defaultScale; scale = dt.defaultScale;
...@@ -211,7 +213,7 @@ public class CreateTable extends CommandWithColumns { ...@@ -211,7 +213,7 @@ public class CreateTable extends CommandWithColumns {
"Unable to resolve enumerators of expression"); "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); addColumn(col);
} }
} }
......
...@@ -27,6 +27,7 @@ import org.h2.table.ColumnResolver; ...@@ -27,6 +27,7 @@ import org.h2.table.ColumnResolver;
import org.h2.table.Table; import org.h2.table.Table;
import org.h2.table.TableFilter; import org.h2.table.TableFilter;
import org.h2.util.ColumnNamer; import org.h2.util.ColumnNamer;
import org.h2.value.TypeInfo;
import org.h2.value.Value; import org.h2.value.Value;
import org.h2.value.ValueInt; import org.h2.value.ValueInt;
import org.h2.value.ValueNull; import org.h2.value.ValueNull;
...@@ -328,10 +329,11 @@ public class SelectUnion extends Query { ...@@ -328,10 +329,11 @@ public class SelectUnion extends Query {
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
Expression l = le.get(i); Expression l = le.get(i);
Expression r = re.get(i); Expression r = re.get(i);
int type = Value.getHigherOrder(l.getValueType(), r.getValueType()); TypeInfo lType = l.getType(), rType = r.getType();
long prec = Math.max(l.getPrecision(), r.getPrecision()); int type = Value.getHigherOrder(lType.getValueType(), rType.getValueType());
int scale = Math.max(l.getScale(), r.getScale()); long prec = Math.max(lType.getPrecision(), rType.getPrecision());
int displaySize = Math.max(l.getDisplaySize(), r.getDisplaySize()); int scale = Math.max(lType.getScale(), rType.getScale());
int displaySize = Math.max(lType.getDisplaySize(), rType.getDisplaySize());
String columnName = columnNamer.getColumnName(l,i,l.getAlias()); String columnName = columnNamer.getColumnName(l,i,l.getAlias());
Column col = new Column(columnName, type, prec, scale, displaySize); Column col = new Column(columnName, type, prec, scale, displaySize);
Expression e = new ExpressionColumn(session.getDatabase(), col); Expression e = new ExpressionColumn(session.getDatabase(), col);
......
...@@ -63,21 +63,6 @@ public class Alias extends Expression { ...@@ -63,21 +63,6 @@ public class Alias extends Expression {
expr.setEvaluatable(tableFilter, b); 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 @Override
public boolean isAutoIncrement() { public boolean isAutoIncrement() {
return expr.isAutoIncrement(); return expr.isAutoIncrement();
......
...@@ -12,7 +12,6 @@ import org.h2.expression.function.Function; ...@@ -12,7 +12,6 @@ import org.h2.expression.function.Function;
import org.h2.message.DbException; import org.h2.message.DbException;
import org.h2.table.ColumnResolver; import org.h2.table.ColumnResolver;
import org.h2.table.TableFilter; import org.h2.table.TableFilter;
import org.h2.util.MathUtils;
import org.h2.value.DataType; import org.h2.value.DataType;
import org.h2.value.TypeInfo; import org.h2.value.TypeInfo;
import org.h2.value.Value; import org.h2.value.Value;
...@@ -431,32 +430,6 @@ public class BinaryOperation extends Expression { ...@@ -431,32 +430,6 @@ public class BinaryOperation extends Expression {
return dataType; 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 @Override
public void updateAggregate(Session session, int stage) { public void updateAggregate(Session session, int stage) {
left.updateAggregate(session, stage); left.updateAggregate(session, stage);
......
...@@ -127,27 +127,6 @@ public abstract class Expression { ...@@ -127,27 +127,6 @@ public abstract class Expression {
*/ */
public abstract void setEvaluatable(TableFilter tableFilter, boolean value); 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. * Get the SQL statement of this expression.
* This may not always be the original SQL statement, * This may not always be the original SQL statement,
......
...@@ -243,21 +243,6 @@ public class ExpressionColumn extends Expression { ...@@ -243,21 +243,6 @@ public class ExpressionColumn extends Expression {
return column; 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() { public String getOriginalColumnName() {
return columnName; return columnName;
} }
......
...@@ -77,21 +77,6 @@ public class ExpressionList extends Expression { ...@@ -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 @Override
public StringBuilder getSQL(StringBuilder builder) { public StringBuilder getSQL(StringBuilder builder) {
builder.append(isArray ? "ARRAY [" : "ROW ("); builder.append(isArray ? "ARRAY [" : "ROW (");
...@@ -130,9 +115,7 @@ public class ExpressionList extends Expression { ...@@ -130,9 +115,7 @@ public class ExpressionList extends Expression {
ExpressionColumn[] expr = new ExpressionColumn[list.length]; ExpressionColumn[] expr = new ExpressionColumn[list.length];
for (int i = 0; i < list.length; i++) { for (int i = 0; i < list.length; i++) {
Expression e = list[i]; Expression e = list[i];
Column col = new Column("C" + (i + 1), Column col = new Column("C" + (i + 1), e.getType());
e.getValueType(), e.getPrecision(), e.getScale(),
e.getDisplaySize());
expr[i] = new ExpressionColumn(session.getDatabase(), col); expr[i] = new ExpressionColumn(session.getDatabase(), col);
} }
return expr; return expr;
......
...@@ -293,21 +293,6 @@ public class IntervalOperation extends Expression { ...@@ -293,21 +293,6 @@ public class IntervalOperation extends Expression {
return dataType; 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 @Override
public void updateAggregate(Session session, int stage) { public void updateAggregate(Session session, int stage) {
left.updateAggregate(session, stage); left.updateAggregate(session, stage);
......
...@@ -142,17 +142,6 @@ public class Parameter extends Expression implements ParameterInterface { ...@@ -142,17 +142,6 @@ public class Parameter extends Expression implements ParameterInterface {
return 0; return 0;
} }
@Override
public int getDisplaySize() {
if (value != null) {
return value.getType().getDisplaySize();
}
if (column != null) {
return column.getType().getDisplaySize();
}
return 0;
}
@Override @Override
public void updateAggregate(Session session, int stage) { public void updateAggregate(Session session, int stage) {
// nothing to do // nothing to do
......
...@@ -58,21 +58,6 @@ public class Rownum extends Expression { ...@@ -58,21 +58,6 @@ public class Rownum extends Expression {
// nothing to do // 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 @Override
public String getSQL() { public String getSQL() {
return "ROWNUM()"; return "ROWNUM()";
......
...@@ -57,21 +57,6 @@ public class SequenceValue extends Expression { ...@@ -57,21 +57,6 @@ public class SequenceValue extends Expression {
// nothing to do // 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 @Override
public StringBuilder getSQL(StringBuilder builder) { public StringBuilder getSQL(StringBuilder builder) {
builder.append("(NEXT VALUE FOR "); builder.append("(NEXT VALUE FOR ");
......
...@@ -79,21 +79,6 @@ public class Subquery extends Expression { ...@@ -79,21 +79,6 @@ public class Subquery extends Expression {
query.setEvaluatable(tableFilter, b); 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 @Override
public StringBuilder getSQL(StringBuilder builder) { public StringBuilder getSQL(StringBuilder builder) {
return builder.append('(').append(query.getPlanSQL()).append(')'); return builder.append('(').append(query.getPlanSQL()).append(')');
......
...@@ -73,21 +73,6 @@ public class UnaryOperation extends Expression { ...@@ -73,21 +73,6 @@ public class UnaryOperation extends Expression {
return type.getValueType(); 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 @Override
public void updateAggregate(Session session, int stage) { public void updateAggregate(Session session, int stage) {
arg.updateAggregate(session, stage); arg.updateAggregate(session, stage);
......
...@@ -126,21 +126,6 @@ public class ValueExpression extends Expression { ...@@ -126,21 +126,6 @@ public class ValueExpression extends Expression {
// nothing to do // 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 @Override
public StringBuilder getSQL(StringBuilder builder) { public StringBuilder getSQL(StringBuilder builder) {
if (this == DEFAULT) { if (this == DEFAULT) {
......
...@@ -31,27 +31,12 @@ public class Variable extends Expression { ...@@ -31,27 +31,12 @@ public class Variable extends Expression {
return 0; return 0;
} }
@Override
public int getDisplaySize() {
return lastValue.getType().getDisplaySize();
}
@Override
public long getPrecision() {
return lastValue.getType().getPrecision();
}
@Override @Override
public StringBuilder getSQL(StringBuilder builder) { public StringBuilder getSQL(StringBuilder builder) {
builder.append('@'); builder.append('@');
return Parser.quoteIdentifier(builder, name); return Parser.quoteIdentifier(builder, name);
} }
@Override
public int getScale() {
return lastValue.getType().getScale();
}
@Override @Override
public TypeInfo getType() { public TypeInfo getType() {
return lastValue.getType(); return lastValue.getType();
......
...@@ -96,21 +96,6 @@ public class Wildcard extends Expression { ...@@ -96,21 +96,6 @@ public class Wildcard extends Expression {
DbException.throwInternalError(toString()); 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 @Override
public String getTableAlias() { public String getTableAlias() {
return table; return table;
......
...@@ -39,8 +39,6 @@ import org.h2.value.TypeInfo; ...@@ -39,8 +39,6 @@ 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;
import org.h2.value.ValueBoolean; import org.h2.value.ValueBoolean;
import org.h2.value.ValueDouble;
import org.h2.value.ValueInt;
import org.h2.value.ValueLong; import org.h2.value.ValueLong;
import org.h2.value.ValueNull; import org.h2.value.ValueNull;
import org.h2.value.ValueString; import org.h2.value.ValueString;
...@@ -166,9 +164,7 @@ public class Aggregate extends AbstractAggregate { ...@@ -166,9 +164,7 @@ public class Aggregate extends AbstractAggregate {
private ArrayList<SelectOrderBy> orderByList; private ArrayList<SelectOrderBy> orderByList;
private SortOrder orderBySort; private SortOrder orderBySort;
private TypeInfo type; private TypeInfo type;
private int dataType, scale; private int dataType;
private long precision;
private int displaySize;
/** /**
* Create a new aggregate object. * Create a new aggregate object.
...@@ -613,9 +609,6 @@ public class Aggregate extends AbstractAggregate { ...@@ -613,9 +609,6 @@ public class Aggregate extends AbstractAggregate {
on = on.optimize(session); on = on.optimize(session);
type = on.getType(); type = on.getType();
dataType = on.getValueType(); dataType = on.getValueType();
scale = on.getScale();
precision = on.getPrecision();
displaySize = on.getDisplaySize();
} }
if (orderByList != null) { if (orderByList != null) {
for (SelectOrderBy o : orderByList) { for (SelectOrderBy o : orderByList) {
...@@ -630,29 +623,19 @@ public class Aggregate extends AbstractAggregate { ...@@ -630,29 +623,19 @@ public class Aggregate extends AbstractAggregate {
case GROUP_CONCAT: case GROUP_CONCAT:
type = TypeInfo.TYPE_STRING_DEFAULT; type = TypeInfo.TYPE_STRING_DEFAULT;
dataType = Value.STRING; dataType = Value.STRING;
scale = 0;
precision = displaySize = Integer.MAX_VALUE;
break; break;
case COUNT_ALL: case COUNT_ALL:
case COUNT: case COUNT:
type = TypeInfo.TYPE_LONG; type = TypeInfo.TYPE_LONG;
dataType = Value.LONG; dataType = Value.LONG;
scale = 0;
precision = ValueLong.PRECISION;
displaySize = ValueLong.DISPLAY_SIZE;
break; break;
case SELECTIVITY: case SELECTIVITY:
type = TypeInfo.TYPE_INT; type = TypeInfo.TYPE_INT;
dataType = Value.INT; dataType = Value.INT;
scale = 0;
precision = ValueInt.PRECISION;
displaySize = ValueInt.DISPLAY_SIZE;
break; break;
case HISTOGRAM: case HISTOGRAM:
type = TypeInfo.TYPE_ARRAY; type = TypeInfo.TYPE_ARRAY;
dataType = Value.ARRAY; dataType = Value.ARRAY;
scale = 0;
precision = displaySize = Integer.MAX_VALUE;
break; break;
case SUM: case SUM:
if (dataType == Value.BOOLEAN) { if (dataType == Value.BOOLEAN) {
...@@ -682,17 +665,11 @@ public class Aggregate extends AbstractAggregate { ...@@ -682,17 +665,11 @@ public class Aggregate extends AbstractAggregate {
case VAR_SAMP: case VAR_SAMP:
type = TypeInfo.TYPE_DOUBLE; type = TypeInfo.TYPE_DOUBLE;
dataType = Value.DOUBLE; dataType = Value.DOUBLE;
precision = ValueDouble.PRECISION;
displaySize = ValueDouble.DISPLAY_SIZE;
scale = 0;
break; break;
case EVERY: case EVERY:
case ANY: case ANY:
type = TypeInfo.TYPE_BOOLEAN; type = TypeInfo.TYPE_BOOLEAN;
dataType = Value.BOOLEAN; dataType = Value.BOOLEAN;
precision = ValueBoolean.PRECISION;
displaySize = ValueBoolean.DISPLAY_SIZE;
scale = 0;
break; break;
case BIT_AND: case BIT_AND:
case BIT_OR: case BIT_OR:
...@@ -703,14 +680,10 @@ public class Aggregate extends AbstractAggregate { ...@@ -703,14 +680,10 @@ public class Aggregate extends AbstractAggregate {
case ARRAY_AGG: case ARRAY_AGG:
type = TypeInfo.TYPE_ARRAY; type = TypeInfo.TYPE_ARRAY;
dataType = Value.ARRAY; dataType = Value.ARRAY;
scale = 0;
precision = displaySize = Integer.MAX_VALUE;
break; break;
case ENVELOPE: case ENVELOPE:
type = TypeInfo.TYPE_GEOMETRY; type = TypeInfo.TYPE_GEOMETRY;
dataType = Value.GEOMETRY; dataType = Value.GEOMETRY;
scale = 0;
precision = displaySize = Integer.MAX_VALUE;
break; break;
default: default:
DbException.throwInternalError("type=" + aggregateType); DbException.throwInternalError("type=" + aggregateType);
...@@ -734,21 +707,6 @@ public class Aggregate extends AbstractAggregate { ...@@ -734,21 +707,6 @@ public class Aggregate extends AbstractAggregate {
super.setEvaluatable(tableFilter, b); 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) { private StringBuilder getSQLGroupConcat(StringBuilder builder) {
builder.append("GROUP_CONCAT("); builder.append("GROUP_CONCAT(");
if (distinct) { if (distinct) {
......
...@@ -54,21 +54,6 @@ public class JavaAggregate extends AbstractAggregate { ...@@ -54,21 +54,6 @@ public class JavaAggregate extends AbstractAggregate {
return cost; 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 @Override
public StringBuilder getSQL(StringBuilder builder) { public StringBuilder getSQL(StringBuilder builder) {
Parser.quoteIdentifier(builder, userAggregate.getName()).append('('); Parser.quoteIdentifier(builder, userAggregate.getName()).append('(');
......
...@@ -521,66 +521,6 @@ public class WindowFunction extends DataAnalysisOperation { ...@@ -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 @Override
public StringBuilder getSQL(StringBuilder builder) { public StringBuilder getSQL(StringBuilder builder) {
String name = type.getSQL(); String name = type.getSQL();
......
...@@ -234,7 +234,7 @@ public class Comparison extends Condition { ...@@ -234,7 +234,7 @@ public class Comparison extends Condition {
if (constType != resType) { if (constType != resType) {
Column column = ((ExpressionColumn) left).getColumn(); Column column = ((ExpressionColumn) left).getColumn();
right = ValueExpression.get(r.convertTo(resType, right = ValueExpression.get(r.convertTo(resType,
MathUtils.convertLongToInt(left.getPrecision()), MathUtils.convertLongToInt(left.getType().getPrecision()),
session.getDatabase().getMode(), column, column.getType().getExtTypeInfo())); session.getDatabase().getMode(), column, column.getType().getExtTypeInfo()));
} }
} else if (right instanceof Parameter) { } else if (right instanceof Parameter) {
......
...@@ -8,7 +8,6 @@ package org.h2.expression.condition; ...@@ -8,7 +8,6 @@ package org.h2.expression.condition;
import org.h2.expression.Expression; import org.h2.expression.Expression;
import org.h2.value.TypeInfo; import org.h2.value.TypeInfo;
import org.h2.value.Value; import org.h2.value.Value;
import org.h2.value.ValueBoolean;
/** /**
* Represents a condition returning a boolean value, or NULL. * Represents a condition returning a boolean value, or NULL.
...@@ -25,19 +24,4 @@ abstract class Condition extends Expression { ...@@ -25,19 +24,4 @@ abstract class Condition extends Expression {
return Value.BOOLEAN; return Value.BOOLEAN;
} }
@Override
public int getScale() {
return 0;
}
@Override
public long getPrecision() {
return ValueBoolean.PRECISION;
}
@Override
public int getDisplaySize() {
return ValueBoolean.DISPLAY_SIZE;
}
} }
...@@ -14,7 +14,6 @@ import org.h2.expression.ExpressionVisitor; ...@@ -14,7 +14,6 @@ import org.h2.expression.ExpressionVisitor;
import org.h2.expression.ValueExpression; import org.h2.expression.ValueExpression;
import org.h2.table.ColumnResolver; import org.h2.table.ColumnResolver;
import org.h2.table.TableFilter; import org.h2.table.TableFilter;
import org.h2.value.DataType;
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;
...@@ -81,21 +80,6 @@ public class JavaFunction extends Expression implements FunctionCall { ...@@ -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 @Override
public StringBuilder getSQL(StringBuilder builder) { public StringBuilder getSQL(StringBuilder builder) {
// TODO always append the schema once FUNCTIONS_IN_SCHEMA is enabled // TODO always append the schema once FUNCTIONS_IN_SCHEMA is enabled
......
...@@ -145,17 +145,17 @@ public abstract class LazyResult implements ResultInterface { ...@@ -145,17 +145,17 @@ public abstract class LazyResult implements ResultInterface {
@Override @Override
public long getColumnPrecision(int i) { public long getColumnPrecision(int i) {
return expressions[i].getPrecision(); return expressions[i].getType().getPrecision();
} }
@Override @Override
public int getColumnScale(int i) { public int getColumnScale(int i) {
return expressions[i].getScale(); return expressions[i].getType().getScale();
} }
@Override @Override
public int getDisplaySize(int i) { public int getDisplaySize(int i) {
return expressions[i].getDisplaySize(); return expressions[i].getType().getDisplaySize();
} }
@Override @Override
......
...@@ -529,7 +529,7 @@ public class LocalResultImpl implements LocalResult { ...@@ -529,7 +529,7 @@ public class LocalResultImpl implements LocalResult {
@Override @Override
public int getDisplaySize(int i) { public int getDisplaySize(int i) {
return expressions[i].getDisplaySize(); return expressions[i].getType().getDisplaySize();
} }
@Override @Override
...@@ -544,7 +544,7 @@ public class LocalResultImpl implements LocalResult { ...@@ -544,7 +544,7 @@ public class LocalResultImpl implements LocalResult {
@Override @Override
public long getColumnPrecision(int i) { public long getColumnPrecision(int i) {
return expressions[i].getPrecision(); return expressions[i].getType().getPrecision();
} }
@Override @Override
...@@ -559,7 +559,7 @@ public class LocalResultImpl implements LocalResult { ...@@ -559,7 +559,7 @@ public class LocalResultImpl implements LocalResult {
@Override @Override
public int getColumnScale(int i) { public int getColumnScale(int i) {
return expressions[i].getScale(); return expressions[i].getType().getScale();
} }
/** /**
......
...@@ -40,6 +40,7 @@ import org.h2.util.StringUtils; ...@@ -40,6 +40,7 @@ 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.ExtTypeInfo;
import org.h2.value.TypeInfo;
import org.h2.value.Value; import org.h2.value.Value;
/** /**
...@@ -181,28 +182,29 @@ public class TableView extends Table { ...@@ -181,28 +182,29 @@ public class TableView extends Table {
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
Expression expr = expressions.get(i); Expression expr = expressions.get(i);
String name = null; String name = null;
int type = Value.UNKNOWN; int valueType = Value.UNKNOWN;
if (columnTemplates != null && columnTemplates.length > i) { if (columnTemplates != null && columnTemplates.length > i) {
name = columnTemplates[i].getName(); name = columnTemplates[i].getName();
type = columnTemplates[i].getType().getValueType(); valueType = columnTemplates[i].getType().getValueType();
} }
if (name == null) { if (name == null) {
name = expr.getAlias(); name = expr.getAlias();
} }
name = columnNamer.getColumnName(expr, i, name); name = columnNamer.getColumnName(expr, i, name);
if (type == Value.UNKNOWN) { if (valueType == Value.UNKNOWN) {
type = expr.getValueType(); valueType = expr.getValueType();
} }
long precision = expr.getPrecision(); TypeInfo type = expr.getType();
int scale = expr.getScale(); long precision = type.getPrecision();
int displaySize = expr.getDisplaySize(); int scale = type.getScale();
int displaySize = type.getDisplaySize();
ExtTypeInfo extTypeInfo = null; ExtTypeInfo extTypeInfo = null;
if (DataType.isExtInfoType(type)) { if (DataType.isExtInfoType(valueType)) {
if (expr instanceof ExpressionColumn) { if (expr instanceof ExpressionColumn) {
extTypeInfo = ((ExpressionColumn) expr).getColumn().getType().getExtTypeInfo(); 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); col.setTable(this, i);
// Fetch check constraint from view column source // Fetch check constraint from view column source
ExpressionColumn fromColumn = null; ExpressionColumn fromColumn = null;
......
...@@ -18,6 +18,8 @@ public final class ExtTypeInfoEnum extends ExtTypeInfo { ...@@ -18,6 +18,8 @@ public final class ExtTypeInfoEnum extends ExtTypeInfo {
private final String[] enumerators, cleaned; private final String[] enumerators, cleaned;
private TypeInfo type;
/** /**
* Returns enumerators for the two specified values for a binary operation. * Returns enumerators for the two specified values for a binary operation.
* *
...@@ -92,6 +94,21 @@ public final class ExtTypeInfoEnum extends ExtTypeInfo { ...@@ -92,6 +94,21 @@ public final class ExtTypeInfoEnum extends ExtTypeInfo {
this.cleaned = Arrays.equals(cleaned, enumerators) ? enumerators : cleaned; 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 @Override
public Value cast(Value value) { public Value cast(Value value) {
switch (value.getValueType()) { switch (value.getValueType()) {
......
...@@ -19,7 +19,7 @@ public class ValueEnum extends ValueEnumBase { ...@@ -19,7 +19,7 @@ public class ValueEnum extends ValueEnumBase {
@Override @Override
public TypeInfo getType() { public TypeInfo getType() {
return new TypeInfo(ENUM, PRECISION, 0, DISPLAY_SIZE, enumerators); return enumerators.getType();
} }
public ExtTypeInfoEnum getEnumerators() { public ExtTypeInfoEnum getEnumerators() {
......
...@@ -255,9 +255,9 @@ SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME = 'E' ORDER BY TABLE_ ...@@ -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 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 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 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 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 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 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 10 10 10 10 0 null null null Unicode OFF INTEGER 1 FALSE 50 null null INTEGER null TRUE
> rows (ordered): 5 > rows (ordered): 5
DROP VIEW V; DROP VIEW V;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论