/**
* Copyright (C) 2009-2013 FoundationDB, LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.foundationdb.server.types.texpressions;
import com.foundationdb.qp.operator.QueryBindings;
import com.foundationdb.qp.operator.QueryContext;
import com.foundationdb.qp.row.Row;
import com.foundationdb.server.explain.*;
import com.foundationdb.server.explain.std.TExpressionExplainer;
import com.foundationdb.server.types.TInstance;
import com.foundationdb.server.types.TPreptimeValue;
import com.foundationdb.server.types.value.ValueSource;
import com.foundationdb.server.types.value.ValueSources;
public final class TNullExpression implements TPreparedExpression {
public TNullExpression (TInstance type) {
this.type = type.withNullable(true);
}
@Override
public TPreptimeValue evaluateConstant(QueryContext queryContext) {
TEvaluatableExpression eval = build();
return new TPreptimeValue(type, eval.resultValue());
}
@Override
public TInstance resultType() {
return type;
}
@Override
public TEvaluatableExpression build() {
return new InnerEvaluation(type);
}
@Override
public CompoundExplainer getExplainer(ExplainContext context)
{
CompoundExplainer ex = new TExpressionExplainer(Type.LITERAL, "Literal", context);
ex.addAttribute(Label.OPERAND, PrimitiveExplainer.getInstance("NULL"));
return ex;
}
@Override
public String toString() {
return "Literal(NULL)";
}
@Override
public boolean isLiteral() {
return true;
}
private final TInstance type;
private static class InnerEvaluation implements TEvaluatableExpression {
@Override
public ValueSource resultValue() {
return valueSource;
}
@Override
public void evaluate() {
}
@Override
public void with(Row row) {
}
@Override
public void with(QueryContext context) {
}
@Override
public void with(QueryBindings bindings) {
}
private InnerEvaluation(TInstance underlying) {
this.valueSource = ValueSources.getNullSource(underlying);
}
private final ValueSource valueSource;
}
}