TInstance dinst = overload.resultStrategy().fixed(false);
TPreparedExpression defExpr = new TPreparedFunction(overload,
dinst,
Collections.<TPreparedExpression>emptyList());
if (!dinst.equals(type)) {
TCast tcast = typesService.getCastsResolver().cast(dinst.typeClass(), type.typeClass());
defExpr = new TCastExpression(defExpr, tcast, type);
}
expression = defExpr;
}
else {
final String defaultValue = column.getDefaultValue();
final Value defaultValueSource;
if(defaultValue == null) {
defaultValueSource = new Value(type);
defaultValueSource.putNull();
} else {
TCast cast = type.typeClass().castFromVarchar();
if (cast != null) {
defaultValueSource = new Value(type);
TInstance valInst = typesTranslator.typeForString(defaultValue);
TExecutionContext executionContext = new TExecutionContext(Collections.singletonList(valInst),
type,
queryContext);
cast.evaluate(executionContext,
new Value(valInst, defaultValue),
defaultValueSource);
} else {
defaultValueSource = new Value(type, defaultValue);
}