<commit_before>/**
 * END USER LICENSE AGREEMENT (“EULA”)
 *
 * READ THIS AGREEMENT CAREFULLY (date: 9/13/2011):
 * http://www.akiban.com/licensing/20110913
 *
 * BY INSTALLING OR USING ALL OR ANY PORTION OF THE SOFTWARE, YOU ARE ACCEPTING
 * ALL OF THE TERMS AND CONDITIONS OF THIS AGREEMENT. YOU AGREE THAT THIS
 * AGREEMENT IS ENFORCEABLE LIKE ANY WRITTEN AGREEMENT SIGNED BY YOU.
 *
 * IF YOU HAVE PAID A LICENSE FEE FOR USE OF THE SOFTWARE AND DO NOT AGREE TO
 * THESE TERMS, YOU MAY RETURN THE SOFTWARE FOR A FULL REFUND PROVIDED YOU (A) DO
 * NOT USE THE SOFTWARE AND (B) RETURN THE SOFTWARE WITHIN THIRTY (30) DAYS OF
 * YOUR INITIAL PURCHASE.
 *
 * IF YOU WISH TO USE THE SOFTWARE AS AN EMPLOYEE, CONTRACTOR, OR AGENT OF A
 * CORPORATION, PARTNERSHIP OR SIMILAR ENTITY, THEN YOU MUST BE AUTHORIZED TO SIGN
 * FOR AND BIND THE ENTITY IN ORDER TO ACCEPT THE TERMS OF THIS AGREEMENT. THE
 * LICENSES GRANTED UNDER THIS AGREEMENT ARE EXPRESSLY CONDITIONED UPON ACCEPTANCE
 * BY SUCH AUTHORIZED PERSONNEL.
 *
 * IF YOU HAVE ENTERED INTO A SEPARATE WRITTEN LICENSE AGREEMENT WITH AKIBAN FOR
 * USE OF THE SOFTWARE, THE TERMS AND CONDITIONS OF SUCH OTHER AGREEMENT SHALL
 * PREVAIL OVER ANY CONFLICTING TERMS OR CONDITIONS IN THIS AGREEMENT.
 */

package com.akiban.server.types3.mcompat.mfuncs;

import com.akiban.server.types3.*;
import com.akiban.server.types3.mcompat.mtypes.MBigDecimal;
import com.akiban.server.types3.mcompat.mtypes.MBigDecimalWrapper;
import com.akiban.server.types3.mcompat.mtypes.MNumeric;
import com.akiban.server.types3.pvalue.PValueSource;
import com.akiban.server.types3.pvalue.PValueTarget;
import com.akiban.server.types3.texpressions.TInputSetBuilder;
import com.akiban.server.types3.texpressions.TOverloadBase;
import java.util.List;

public class MCeil extends TOverloadBase {

    @Override
    protected void buildInputSets(TInputSetBuilder builder) {
        builder.covers(MNumeric.DECIMAL, 0);
    }

    @Override
    protected void doEvaluate(TExecutionContext context, LazyList<? extends PValueSource> inputs, PValueTarget output) {
        MBigDecimalWrapper result = (MBigDecimalWrapper) inputs.get(0).getObject();
        output.putObject(result.ceil());
    }

    @Override
    public String overloadName() {
        return "CEIL";
    }

    @Override
    public TOverloadResult resultType() {
        return TOverloadResult.custom(MNumeric.DECIMAL.instance(), new TCustomOverloadResult() {
            private final int ZERO_DEFAULT = 13;
            private final int BIGINT_DEFAULT = 17;
            private final int DECIMAL_DEFAULT = 16;

            @Override
            public TInstance resultInstance(List<TPreptimeValue> inputs, TPreptimeContext context) {
                TPreptimeValue preptimeValue = inputs.get(0);
                int precision = preptimeValue.instance().attribute(MBigDecimal.Attrs.PRECISION);
                int scale = preptimeValue.instance().attribute(MBigDecimal.Attrs.SCALE);
                
                // Special case: DECIMAL(0,0)
                if (precision + scale == 0) 
                    return MNumeric.BIGINT.instance(ZERO_DEFAULT);
                
                int length = precision - scale;
                if (length >= 0 && length < 9)
                    return MNumeric.INT.instance(length+3);
                if (length >= 9 && length < 14)
                    return MNumeric.BIGINT.instance(BIGINT_DEFAULT);
                return MNumeric.DECIMAL.instance(DECIMAL_DEFAULT, 0);
            }         
        });
    }
}
<commit_msg>Keep argument type same as input<commit_after>/**
 * END USER LICENSE AGREEMENT (“EULA”)
 *
 * READ THIS AGREEMENT CAREFULLY (date: 9/13/2011):
 * http://www.akiban.com/licensing/20110913
 *
 * BY INSTALLING OR USING ALL OR ANY PORTION OF THE SOFTWARE, YOU ARE ACCEPTING
 * ALL OF THE TERMS AND CONDITIONS OF THIS AGREEMENT. YOU AGREE THAT THIS
 * AGREEMENT IS ENFORCEABLE LIKE ANY WRITTEN AGREEMENT SIGNED BY YOU.
 *
 * IF YOU HAVE PAID A LICENSE FEE FOR USE OF THE SOFTWARE AND DO NOT AGREE TO
 * THESE TERMS, YOU MAY RETURN THE SOFTWARE FOR A FULL REFUND PROVIDED YOU (A) DO
 * NOT USE THE SOFTWARE AND (B) RETURN THE SOFTWARE WITHIN THIRTY (30) DAYS OF
 * YOUR INITIAL PURCHASE.
 *
 * IF YOU WISH TO USE THE SOFTWARE AS AN EMPLOYEE, CONTRACTOR, OR AGENT OF A
 * CORPORATION, PARTNERSHIP OR SIMILAR ENTITY, THEN YOU MUST BE AUTHORIZED TO SIGN
 * FOR AND BIND THE ENTITY IN ORDER TO ACCEPT THE TERMS OF THIS AGREEMENT. THE
 * LICENSES GRANTED UNDER THIS AGREEMENT ARE EXPRESSLY CONDITIONED UPON ACCEPTANCE
 * BY SUCH AUTHORIZED PERSONNEL.
 *
 * IF YOU HAVE ENTERED INTO A SEPARATE WRITTEN LICENSE AGREEMENT WITH AKIBAN FOR
 * USE OF THE SOFTWARE, THE TERMS AND CONDITIONS OF SUCH OTHER AGREEMENT SHALL
 * PREVAIL OVER ANY CONFLICTING TERMS OR CONDITIONS IN THIS AGREEMENT.
 */

package com.akiban.server.types3.mcompat.mfuncs;

import com.akiban.server.types3.*;
import com.akiban.server.types3.mcompat.mtypes.MBigDecimal;
import com.akiban.server.types3.mcompat.mtypes.MBigDecimalWrapper;
import com.akiban.server.types3.mcompat.mtypes.MNumeric;
import com.akiban.server.types3.pvalue.PValueSource;
import com.akiban.server.types3.pvalue.PValueTarget;
import com.akiban.server.types3.texpressions.TInputSetBuilder;
import com.akiban.server.types3.texpressions.TOverloadBase;
import java.util.List;

public class MCeil extends TOverloadBase {

    private TClass argumentType;
    
    private MCeil(TClass argumentType) {
        this.argumentType = argumentType;
    }
    
    @Override
    protected void buildInputSets(TInputSetBuilder builder) {
        builder.covers(argumentType, 0);
    }

    @Override
    protected void doEvaluate(TExecutionContext context, LazyList<? extends PValueSource> inputs, PValueTarget output) {
        MBigDecimalWrapper result = (MBigDecimalWrapper) inputs.get(0).getObject();
        output.putObject(result.ceil());
    }

    @Override
    public String overloadName() {
        return "CEIL";
    }

    @Override
    public TOverloadResult resultType() {
        return TOverloadResult.custom(MNumeric.DECIMAL.instance(), new TCustomOverloadResult() {
            private final int ZERO_DEFAULT = 13;
            private final int BIGINT_DEFAULT = 17;
            private final int DECIMAL_DEFAULT = 16;

            @Override
            public TInstance resultInstance(List<TPreptimeValue> inputs, TPreptimeContext context) {
                TPreptimeValue preptimeValue = inputs.get(0);
                int precision = preptimeValue.instance().attribute(MBigDecimal.Attrs.PRECISION);
                int scale = preptimeValue.instance().attribute(MBigDecimal.Attrs.SCALE);
                
                // Special case: DECIMAL(0,0)
                if (precision + scale == 0) 
                    return MNumeric.BIGINT.instance(ZERO_DEFAULT);
                
                int length = precision - scale;
                if (length >= 0 && length < 9)
                    return MNumeric.INT.instance(length+3);
                if (length >= 9 && length < 14)
                    return MNumeric.BIGINT.instance(BIGINT_DEFAULT);
                return MNumeric.DECIMAL.instance(DECIMAL_DEFAULT, 0);
            }         
        });
    }
}

{'fraction_non_alphanumeric': 0.07868265123329199, 'fraction_numerical': 0.012401818933443571, 'mean_word_length': 2.879208979155532, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5395595', 'n_tokens_mistral': 2321, 'n_tokens_neox': 2160, 'n_words': 641}