提交 2daa26ba authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Remove unused display size parameters

上级 584b1c8d
......@@ -169,7 +169,7 @@ public class BinaryOperation extends Expression {
if (DataType.isStringType(l.getValueType()) && DataType.isStringType(r.getValueType())) {
long precision = l.getPrecision() + r.getPrecision();
if (precision >= 0 && precision < Integer.MAX_VALUE) {
type = TypeInfo.getTypeInfo(Value.STRING, precision, 0, (int) precision, null);
type = TypeInfo.getTypeInfo(Value.STRING, precision, 0, null);
break;
}
}
......
......@@ -2317,20 +2317,20 @@ public class Function extends Expression implements FunctionCall {
allConst = false;
}
}
int t, s, d;
int t, s;
long p;
Expression p0 = args.length < 1 ? null : args[0];
switch (info.type) {
case DATE_ADD: {
t = Value.TIMESTAMP;
p = d = ValueTimestamp.DEFAULT_PRECISION;
p = ValueTimestamp.DEFAULT_PRECISION;
s = ValueTimestamp.MAXIMUM_SCALE;
if (p0.isConstant()) {
Expression p2 = args[2];
switch (p2.getType().getValueType()) {
case Value.TIME:
t = Value.TIME;
p = d = ValueTime.DEFAULT_PRECISION;
p = ValueTime.DEFAULT_PRECISION;
break;
case Value.DATE: {
int field = DateTimeFunctions.getDatePart(p0.getValue(session).getString());
......@@ -2346,14 +2346,14 @@ public class Function extends Expression implements FunctionCall {
break;
default:
t = Value.DATE;
p = d = ValueDate.PRECISION;
p = ValueDate.PRECISION;
s = 0;
}
break;
}
case Value.TIMESTAMP_TZ:
t = Value.TIMESTAMP_TZ;
p = d = ValueTimestampTimeZone.DEFAULT_PRECISION;
p = ValueTimestampTimeZone.DEFAULT_PRECISION;
}
}
break;
......@@ -2363,12 +2363,10 @@ public class Function extends Expression implements FunctionCall {
t = Value.DECIMAL;
p = ValueLong.PRECISION + ValueTimestamp.MAXIMUM_SCALE;
s = ValueTimestamp.MAXIMUM_SCALE;
d = ValueLong.PRECISION + ValueTimestamp.MAXIMUM_SCALE + 1;
} else {
t = Value.INT;
p = ValueInt.PRECISION;
s = 0;
d = ValueInt.DISPLAY_SIZE;
}
break;
}
......@@ -2376,10 +2374,10 @@ public class Function extends Expression implements FunctionCall {
Expression p1 = args[1];
t = p1.getType().getValueType();
if (t == Value.TIMESTAMP_TZ) {
p = d = ValueTimestampTimeZone.DEFAULT_PRECISION;
p = ValueTimestampTimeZone.DEFAULT_PRECISION;
} else {
t = Value.TIMESTAMP;
p = d = ValueTimestamp.DEFAULT_PRECISION;
p = ValueTimestamp.DEFAULT_PRECISION;
}
s = ValueTimestamp.MAXIMUM_SCALE;
break;
......@@ -2392,7 +2390,6 @@ public class Function extends Expression implements FunctionCall {
t = Value.UNKNOWN;
s = 0;
p = 0;
d = 0;
for (Expression e : args) {
if (e != ValueExpression.getNull()) {
TypeInfo type = e.getType();
......@@ -2401,7 +2398,6 @@ public class Function extends Expression implements FunctionCall {
t = Value.getHigherOrder(t, valueType);
s = Math.max(s, type.getScale());
p = Math.max(p, type.getPrecision());
d = Math.max(d, type.getDisplaySize());
}
}
}
......@@ -2409,7 +2405,6 @@ public class Function extends Expression implements FunctionCall {
t = Value.STRING;
s = 0;
p = Integer.MAX_VALUE;
d = Integer.MAX_VALUE;
}
break;
}
......@@ -2418,7 +2413,6 @@ public class Function extends Expression implements FunctionCall {
t = Value.UNKNOWN;
s = 0;
p = 0;
d = 0;
// (expr, when, then)
// (expr, when, then, else)
// (expr, when, then, when, then)
......@@ -2432,7 +2426,6 @@ public class Function extends Expression implements FunctionCall {
t = Value.getHigherOrder(t, valueType);
s = Math.max(s, type.getScale());
p = Math.max(p, type.getPrecision());
d = Math.max(d, type.getDisplaySize());
}
}
}
......@@ -2445,7 +2438,6 @@ public class Function extends Expression implements FunctionCall {
t = Value.getHigherOrder(t, valueType);
s = Math.max(s, type.getScale());
p = Math.max(p, type.getPrecision());
d = Math.max(d, type.getDisplaySize());
}
}
}
......@@ -2453,7 +2445,6 @@ public class Function extends Expression implements FunctionCall {
t = Value.STRING;
s = 0;
p = Integer.MAX_VALUE;
d = Integer.MAX_VALUE;
}
break;
}
......@@ -2461,7 +2452,6 @@ public class Function extends Expression implements FunctionCall {
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;
}
......@@ -2479,7 +2469,6 @@ public class Function extends Expression implements FunctionCall {
break;
}
p = Math.max(t1.getPrecision(), t2.getPrecision());
d = Math.max(t1.getDisplaySize(), t2.getDisplaySize());
s = Math.max(t1.getScale(), t2.getScale());
break;
}
......@@ -2491,10 +2480,9 @@ public class Function extends Expression implements FunctionCall {
t = dataType;
p = type.getPrecision();
s = type.getScale();
d = type.getDisplaySize();
} else {
t = Value.UNKNOWN;
p = s = d = 0;
p = s = 0;
}
break;
case TRUNCATE:
......@@ -2503,19 +2491,18 @@ public class Function extends Expression implements FunctionCall {
case Value.DATE:
case Value.TIMESTAMP:
t = Value.TIMESTAMP;
p = d = ValueTimestamp.DEFAULT_PRECISION;
p = ValueTimestamp.DEFAULT_PRECISION;
s = 0;
break;
case Value.TIMESTAMP_TZ:
t = Value.TIMESTAMP;
p = d = ValueTimestampTimeZone.DEFAULT_PRECISION;
p = ValueTimestampTimeZone.DEFAULT_PRECISION;
s = 0;
break;
default:
t = Value.DOUBLE;
s = 0;
p = ValueDouble.PRECISION;
d = ValueDouble.DISPLAY_SIZE;
}
break;
case ABS:
......@@ -2525,11 +2512,9 @@ public class Function extends Expression implements FunctionCall {
t = type.getValueType();
s = type.getScale();
p = type.getPrecision();
d = type.getDisplaySize();
if (t == Value.NULL) {
t = Value.INT;
p = ValueInt.PRECISION;
d = ValueInt.DISPLAY_SIZE;
s = 0;
}
break;
......@@ -2539,7 +2524,6 @@ public class Function extends Expression implements FunctionCall {
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());
......@@ -2554,7 +2538,6 @@ public class Function extends Expression implements FunctionCall {
}
p = Integer.MAX_VALUE;
s = 0;
d = Integer.MAX_VALUE;
break;
}
case SUBSTRING:
......@@ -2572,7 +2555,6 @@ public class Function extends Expression implements FunctionCall {
p = Math.min(p, args[2].getValue(session).getLong());
}
p = Math.max(0, p);
d = MathUtils.convertLongToInt(p);
break;
}
case ENCRYPT:
......@@ -2580,7 +2562,6 @@ public class Function extends Expression implements FunctionCall {
t = info.returnDataType;
TypeInfo type = args[2].getType();
p = type.getPrecision();
d = type.getDisplaySize();
s = 0;
break;
}
......@@ -2588,25 +2569,21 @@ public class Function extends Expression implements FunctionCall {
t = info.returnDataType;
TypeInfo type = args[0].getType();
p = type.getPrecision();
d = type.getDisplaySize();
s = 0;
break;
}
case CHAR:
t = info.returnDataType;
p = 1;
d = 1;
s = 0;
break;
case CONCAT:
t = info.returnDataType;
p = 0;
d = 0;
s = 0;
for (Expression e : args) {
TypeInfo type = e.getType();
p += type.getPrecision();
d = MathUtils.convertLongToInt((long) d + type.getDisplaySize());
if (p < 0) {
p = Long.MAX_VALUE;
}
......@@ -2615,7 +2592,6 @@ public class Function extends Expression implements FunctionCall {
case HEXTORAW:
t = info.returnDataType;
p = (args[0].getType().getPrecision() + 3) / 4;
d = MathUtils.convertLongToInt(p);
s = 0;
break;
case LCASE:
......@@ -2631,36 +2607,33 @@ public class Function extends Expression implements FunctionCall {
t = info.returnDataType;
TypeInfo type = args[0].getType();
p = type.getPrecision();
d = type.getDisplaySize();
s = 0;
break;
}
case RAWTOHEX:
t = info.returnDataType;
p = args[0].getType().getPrecision() * 4;
d = MathUtils.convertLongToInt(p);
s = 0;
break;
case SOUNDEX:
t = info.returnDataType;
p = d = 4;
p = 4;
s = 0;
break;
case DAY_NAME:
case MONTH_NAME:
t = info.returnDataType;
// day and month names may be long in some languages
p = d = 20;
p = 20;
s = 0;
break;
default:
t = info.returnDataType;
DataType type = DataType.getDataType(t);
p = type.maxPrecision;
d = type.defaultDisplaySize;
s = type.defaultScale;
}
type = TypeInfo.getTypeInfo(t, p, s, d, extTypeInfo);
type = TypeInfo.getTypeInfo(t, p, s, extTypeInfo);
dataType = t;
if (allConst) {
Value v = getValue(session);
......
......@@ -421,8 +421,7 @@ public class ValueDataType implements DataType {
TypeInfo columnType = result.getColumnType(i);
buff.putVarInt(columnType.getValueType()).
putVarLong(columnType.getPrecision()).
putVarInt(columnType.getScale()).
putVarInt(columnType.getDisplaySize());
putVarInt(columnType.getScale());
}
while (result.next()) {
buff.put((byte) 1);
......@@ -634,7 +633,7 @@ public class ValueDataType implements DataType {
SimpleResult rs = new SimpleResult();
int columns = readVarInt(buff);
for (int i = 0; i < columns; i++) {
rs.addColumn(readString(buff), readString(buff), readVarInt(buff), readVarLong(buff), readVarInt(buff),
rs.addColumn(readString(buff), readString(buff), readVarInt(buff), readVarLong(buff),
readVarInt(buff));
}
while (buff.get() != 0) {
......
......@@ -31,14 +31,13 @@ public class SimpleResult implements ResultInterface {
/** Column type. */
final TypeInfo columnType;
Column(String alias, String columnName, int columnType, long columnPrecision, int columnScale,
int displaySize) {
Column(String alias, String columnName, int columnType, long columnPrecision, int columnScale) {
if (alias == null || columnName == null) {
throw new NullPointerException();
}
this.alias = alias;
this.columnName = columnName;
this.columnType = TypeInfo.getTypeInfo(columnType, columnPrecision, columnScale, displaySize, null);
this.columnType = TypeInfo.getTypeInfo(columnType, columnPrecision, columnScale, null);
}
Column(String alias, String columnName, TypeInfo columnType) {
......@@ -108,11 +107,9 @@ public class SimpleResult implements ResultInterface {
* @param columnType Column's value type.
* @param columnPrecision Column's precision.
* @param columnScale Column's scale.
* @param displaySize Column's display data size.
*/
public void addColumn(String alias, String columnName, int columnType, long columnPrecision, int columnScale,
int displaySize) {
addColumn(new Column(alias, columnName, columnType, columnPrecision, columnScale, displaySize));
public void addColumn(String alias, String columnName, int columnType, long columnPrecision, int columnScale) {
addColumn(new Column(alias, columnName, columnType, columnPrecision, columnScale));
}
/**
......
......@@ -684,7 +684,6 @@ public class Data {
writeVarInt(columnType.getValueType());
writeVarLong(columnType.getPrecision());
writeVarInt(columnType.getScale());
writeVarInt(columnType.getDisplaySize());
}
while (result.next()) {
writeByte((byte) 1);
......@@ -908,7 +907,7 @@ public class Data {
SimpleResult rs = new SimpleResult();
int columns = readVarInt();
for (int i = 0; i < columns; i++) {
rs.addColumn(readString(), readString(), readVarInt(), readVarLong(), readVarInt(), readVarInt());
rs.addColumn(readString(), readString(), readVarInt(), readVarLong(), readVarInt());
}
while (readByte() != 0) {
Value[] o = new Value[columns];
......@@ -1172,7 +1171,6 @@ public class Data {
len += getVarIntLen(columnType.getValueType());
len += getVarLongLen(columnType.getPrecision());
len += getVarIntLen(columnType.getScale());
len += getVarIntLen(columnType.getDisplaySize());
}
while (result.next()) {
len++;
......
......@@ -518,14 +518,12 @@ public class Transfer {
writeString(result.getColumnName(i));
writeInt(columnType.getValueType());
writeLong(columnType.getPrecision());
writeInt(columnType.getScale());
writeInt(columnType.getDisplaySize());
} else {
writeString(result.getColumnName(i));
writeInt(DataType.getDataType(columnType.getValueType()).sqlType);
writeInt(MathUtils.convertLongToInt(columnType.getPrecision()));
writeInt(columnType.getScale());
}
writeInt(columnType.getScale());
}
while (result.next()) {
writeBoolean(true);
......@@ -739,11 +737,10 @@ public class Transfer {
int columns = readInt();
for (int i = 0; i < columns; i++) {
if (version >= Constants.TCP_PROTOCOL_VERSION_18) {
rs.addColumn(readString(), readString(), readInt(), readLong(), readInt(), readInt());
rs.addColumn(readString(), readString(), readInt(), readLong(), readInt());
} else {
String name = readString();
rs.addColumn(name, name, DataType.convertSQLTypeToValueType(readInt()), readInt(), readInt(),
Integer.MAX_VALUE);
rs.addColumn(name, name, DataType.convertSQLTypeToValueType(readInt()), readInt(), readInt());
}
}
while (readBoolean()) {
......
......@@ -227,13 +227,11 @@ public class TypeInfo {
* the precision
* @param scale
* the scale
* @param displaySize
* the display size in characters
* @param extTypeInfo
* the extended type information, or null
* @return the data type with parameters object
*/
public static TypeInfo getTypeInfo(int type, long precision, int scale, int displaySize, ExtTypeInfo extTypeInfo) {
public static TypeInfo getTypeInfo(int type, long precision, int scale, ExtTypeInfo extTypeInfo) {
switch (type) {
case Value.NULL:
case Value.BOOLEAN:
......
......@@ -58,8 +58,7 @@ public class ValueResultSet extends Value {
meta.getColumnTypeName(i + 1));
int precision = meta.getPrecision(i + 1);
int scale = meta.getScale(i + 1);
int displaySize = meta.getColumnDisplaySize(i + 1);
simple.addColumn(alias, name, columnType, precision, scale, displaySize);
simple.addColumn(alias, name, columnType, precision, scale);
}
for (int i = 0; i < maxrows && rs.next(); i++) {
Value[] list = new Value[columnCount];
......
......@@ -208,8 +208,8 @@ public class TestDataPage extends TestBase implements DataHandler {
ValueInt.get(10) }));
SimpleResult rs = new SimpleResult();
rs.addColumn("ID", "ID", Value.INT, 0, 0, ValueInt.DISPLAY_SIZE);
rs.addColumn("NAME", "NAME", Value.STRING, 255, 0, 255);
rs.addColumn("ID", "ID", Value.INT, 0, 0);
rs.addColumn("NAME", "NAME", Value.STRING, 255, 0);
rs.addRow(ValueInt.get(1), ValueString.get("Hello"));
rs.addRow(ValueInt.get(2), ValueString.get("World"));
rs.addRow(ValueInt.get(3), ValueString.get("Peace"));
......
......@@ -205,7 +205,7 @@ public class TestValue extends TestDb {
assertEquals(10, v.convertPrecision(10, true).getType().getPrecision());
SimpleResult rs = new SimpleResult();
rs.addColumn("X", "X", Value.INT, 0, 0, ValueInt.DISPLAY_SIZE);
rs.addColumn("X", "X", Value.INT, 0, 0);
rs.addRow(ValueInt.get(1));
v = ValueResultSet.get(rs);
assertEquals(Integer.MAX_VALUE, v.getType().getPrecision());
......@@ -236,8 +236,8 @@ public class TestValue extends TestDb {
testValueResultSetTest(ValueResultSet.get(null, rs, 2), 2, true);
SimpleResult result = new SimpleResult();
result.addColumn("ID", "ID", Value.INT, 0, 0, ValueInt.DISPLAY_SIZE);
result.addColumn("NAME", "NAME", Value.STRING, 255, 0, 255);
result.addColumn("ID", "ID", Value.INT, 0, 0);
result.addColumn("NAME", "NAME", Value.STRING, 255, 0);
result.addRow(ValueInt.get(1), ValueString.get("Hello"));
result.addRow(ValueInt.get(2), ValueString.get("World"));
result.addRow(ValueInt.get(3), ValueString.get("Peace"));
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论