MCPcopy Create free account
hub / github.com/apache/impala / castTo

Method castTo

fe/src/main/java/org/apache/impala/analysis/Expr.java:1612–1626  ·  view source on GitHub ↗

Casts this expr to a specific target type. It checks the validity of the cast according to 'compatibility' and calls uncheckedCastTo(). @param targetType type to be cast to @param compatibility compatibility level that defines the relation between 'targetType' and the type

(Type targetType, TypeCompatibility compatibility)

Source from the content-addressed store, hash-verified

1610 * failure to convert a string literal to a date literal
1611 */
1612 public final Expr castTo(Type targetType, TypeCompatibility compatibility)
1613 throws AnalysisException {
1614 Type type = Type.getAssignmentCompatibleType(this.type_, targetType, compatibility);
1615 Preconditions.checkState(type.isValid(), "cast %s to %s", this.type_, targetType);
1616 // If the targetType is NULL_TYPE then ignore the cast because NULL_TYPE
1617 // is compatible with all types and no cast is necessary.
1618 if (targetType.isNull()) return this;
1619 // If decimal, cast to the target type.
1620 if (targetType.isDecimal()) return uncheckedCastTo(targetType, compatibility);
1621 // If they match, cast to the type both values can be assigned to (the definition of
1622 // getAssignmentCompatibleType), which implies no loss of precision. Note that
1623 // getAssignmentCompatibleType always returns a "real" (not wildcard) type.
1624 if (type.matchesType(targetType)) return uncheckedCastTo(type, compatibility);
1625 throw new SqlCastException("targetType=" + targetType + " type=" + type);
1626 }
1627
1628 public final Expr castTo(Type targetType) throws AnalysisException {
1629 return castTo(targetType, TypeCompatibility.DEFAULT);

Callers 15

applyMethod · 0.95
computeTargetExprMethod · 0.95
trySubstituteMethod · 0.95
castChildMethod · 0.95
testBasicsMethod · 0.45
initMethod · 0.45
analyzeImplMethod · 0.45
analyzeImplMethod · 0.45
castCharToStringMethod · 0.45

Calls 6

isValidMethod · 0.95
uncheckedCastToMethod · 0.95
matchesTypeMethod · 0.95
isNullMethod · 0.80
isDecimalMethod · 0.80

Tested by 1

testBasicsMethod · 0.36