15 package com.cloudera.impala.catalog;
18 import com.cloudera.impala.thrift.TColumnType;
19 import com.cloudera.impala.thrift.TScalarType;
20 import com.cloudera.impala.thrift.TTypeNode;
21 import com.cloudera.impala.thrift.TTypeNodeType;
22 import com.google.common.base.Preconditions;
72 case NULL_TYPE:
return NULL;
88 Preconditions.checkState(
false);
106 Preconditions.checkState(precision >= 0);
107 Preconditions.checkState(scale >= 0);
109 type.precision_ = precision;
120 type.scale_ = Math.min(type.precision_, scale);
139 return "CHAR(" +
len_ +
")";
145 return "VARCHAR(" +
len_ +
")";
147 return type_.toString();
153 case BINARY:
return type_.toString();
156 return type_.toString() +
"(" +
len_ +
")";
159 default:
return type_.toString();
165 TTypeNode node =
new TTypeNode();
166 container.types.add(node);
170 node.setType(TTypeNodeType.SCALAR);
171 TScalarType scalarType =
new TScalarType();
172 scalarType.setType(type_.toThrift());
173 scalarType.setLen(
len_);
174 node.setScalar_type(scalarType);
178 node.setType(TTypeNodeType.SCALAR);
179 TScalarType scalarType =
new TScalarType();
180 scalarType.setType(type_.toThrift());
181 scalarType.setScale(
scale_);
183 node.setScalar_type(scalarType);
187 node.setType(TTypeNodeType.SCALAR);
188 TScalarType scalarType =
new TScalarType();
189 scalarType.setType(type_.toThrift());
190 node.setScalar_type(scalarType);
197 Type result[] =
new Type[types.length];
198 for (
int i = 0; i < types.length; ++i) {
216 public int ordinal() {
return type_.ordinal(); }
226 return type_ == PrimitiveType.VARCHAR &&
len_ == -1;
231 return type_ == PrimitiveType.CHAR &&
len_ == -1;
241 if (precision_ <= 0 || precision_ >
MAX_PRECISION)
return false;
242 if (scale_ < 0 || scale_ >
precision_)
return false;
248 return type_ == PrimitiveType.BOOLEAN ||
type_ == PrimitiveType.TINYINT
249 ||
type_ == PrimitiveType.SMALLINT ||
type_ == PrimitiveType.INT
250 ||
type_ == PrimitiveType.BIGINT ||
type_ == PrimitiveType.FLOAT
251 ||
type_ == PrimitiveType.DOUBLE ||
type_ == PrimitiveType.DATE
252 ||
type_ == PrimitiveType.DATETIME ||
type_ == PrimitiveType.TIMESTAMP
282 case DECIMAL:
return TypesUtil.getDecimalSlotSize(
this);
284 return type_.getSlotSize();
295 if (
equals(t))
return true;
306 if (
isDecimal() && scalarType.isWildcardDecimal()) {
377 Preconditions.checkState(o.isDecimal());
390 if (t1.
equals(t2))
return t1;
393 if (t1.
isNull())
return t2;
394 if (t2.
isNull())
return t1;
411 if (t1.
isNull())
return t2;
412 if (t2.
isNull())
return t1;
419 if (t1.
isNull())
return t2;
420 if (t2.
isNull())
return t1;
435 ScalarType t1Decimal = t1.getMinResolutionDecimal();
436 ScalarType t2Decimal = t2.getMinResolutionDecimal();
438 Preconditions.checkState(t1Decimal.isDecimal());
439 Preconditions.checkState(t2Decimal.isDecimal());
441 if (t1Decimal.
equals(t2Decimal)) {
442 Preconditions.checkState(!(t1.isDecimal() && t2.
isDecimal()));
451 if (t2Decimal.isSupertypeOf(t1Decimal))
return t2;
452 return TypesUtil.getDecimalAssignmentCompatibleType(t1Decimal, t2Decimal);
456 (t1.type_.ordinal() < t2.
type_.ordinal() ? t1.type_ : t2.type_);
458 (t1.type_.ordinal() > t2.
type_.ordinal() ? t1.type_ : t2.type_);
461 Preconditions.checkNotNull(result);
boolean isWildcardDecimal()
static boolean isImplicitlyCastable(ScalarType t1, ScalarType t2)
static final ScalarType NULL
static final ScalarType BIGINT
static final ScalarType DATE
static final ScalarType CHAR
static final int MAX_PRECISION
ScalarType(PrimitiveType type)
static final ScalarType VARCHAR
boolean supportsTablePartitioning()
static final ScalarType STRING
static ScalarType createDecimalTypeInternal(int precision, int scale)
boolean isSupertypeOf(ScalarType o)
boolean matchesType(Type t)
static final ScalarType BOOLEAN
static final ScalarType DEFAULT_DECIMAL
static final int MAX_VARCHAR_LENGTH
static ScalarType createVarcharType(int len)
static final int MAX_SCALE
static final int DEFAULT_PRECISION
boolean isFullySpecifiedDecimal()
static final ScalarType SMALLINT
static ScalarType createCharType(int len)
static final ScalarType FLOAT
Type getMaxResolutionType()
boolean isWildcardVarchar()
static ScalarType createVarcharType()
static PrimitiveType[][] compatibilityMatrix
boolean isFloatingPointType()
static final ScalarType DOUBLE
static Type[] toColumnType(PrimitiveType[] types)
static final int DEFAULT_SCALE
PrimitiveType getPrimitiveType()
static final int MAX_CHAR_LENGTH
static final ScalarType TINYINT
static final ScalarType INT
static ScalarType createDecimalType(int precision, int scale)
static ScalarType createType(PrimitiveType type)
static final ScalarType DECIMAL
void toThrift(TColumnType container)
static ScalarType createDecimalType()
static ScalarType createDecimalType(int precision)
static final ScalarType DEFAULT_VARCHAR
static final int CHAR_INLINE_LENGTH
boolean isFixedLengthType()
static final ScalarType DATETIME
static final ScalarType INVALID
static final ScalarType BINARY
final PrimitiveType type_
static final ScalarType TIMESTAMP
static ScalarType getAssignmentCompatibleType(ScalarType t1, ScalarType t2)
ScalarType getNextResolutionType()
ScalarType getMinResolutionDecimal()