@@ -0,0 +1,2523 @@
+/**%0A * Copyright (C) 2011 Akiban Technologies Inc.%0A * This program is free software: you can redistribute it and/or modify%0A * it under the terms of the GNU Affero General Public License, version 3,%0A * as published by the Free Software Foundation.%0A *%0A * This program is distributed in the hope that it will be useful,%0A * but WITHOUT ANY WARRANTY; without even the implied warranty of%0A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the%0A * GNU Affero General Public License for more details.%0A *%0A * You should have received a copy of the GNU Affero General Public License%0A * along with this program.  If not, see http://www.gnu.org/licenses.%0A */%0A%0Apackage com.akiban.server.expression.std;%0A%0Aimport com.akiban.server.error.OverflowException;%0Aimport com.akiban.server.expression.Expression;%0Aimport com.akiban.server.expression.ExpressionEvaluation;%0Aimport com.akiban.server.types.AkType;%0Aimport com.akiban.server.types.NullValueSource;%0Aimport com.akiban.server.types.ValueSource;%0Aimport com.akiban.server.types.util.ValueHolder;%0A%0Apublic class TruncateStringExpression extends AbstractUnaryExpression%0A%7B%0A    public TruncateStringExpression(int length, Expression operand) %7B%0A        super(AkType.DECIMAL, operand);%0A        this.length = length;%0A    %7D%0A%0A    @Override%0A    protected String name() %7B%0A        return %22TruncateString%22;%0A    %7D%0A%0A    @Override%0A    public String toString() %7B%0A        return name() + %22(%22 + operand() + %22,%22 + length + %22)%22;%0A    %7D%0A%0A    @Override%0A    public ExpressionEvaluation evaluation() %7B%0A        return new InnerEvaluation(length, operandEvaluation());%0A    %7D%0A%0A    private final int length;%0A%0A    private static final class InnerEvaluation extends AbstractUnaryExpressionEvaluation %7B%0A        public InnerEvaluation(int length, ExpressionEvaluation ev) %7B%0A            super(ev);%0A            this.length = length;%0A        %7D%0A%0A        @Override%0A        public ValueSource eval() %7B%0A            ValueSource operandSource = operand();%0A            if (operandSource.isNull())%0A                return NullValueSource.only();%0A            String value = operandSource.getString();%0A            if (value.length() %3E length)%0A                value = value.substring(0, length);%0A            return hold(value);%0A        %7D%0A%0A        private ValueSource hold(String value) %7B%0A            if (holder == null) %7B%0A                holder = new ValueHolder();%0A            %7D%0A            holder.putString(value);%0A            return holder;%0A        %7D%0A%0A        private final int length;%0A        private ValueHolder holder;%0A    %7D%0A%7D%0A

Add an expression for truncating strings as part of full CAST.