http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/core/src/main/java/org/apache/calcite/adapter/enumerable/RexToLixTranslator.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/RexToLixTranslator.java
 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/RexToLixTranslator.java
deleted file mode 100644
index 7d5ef75..0000000
--- 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/RexToLixTranslator.java
+++ /dev/null
@@ -1,1146 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.calcite.adapter.enumerable;
-
-import org.apache.calcite.DataContext;
-import org.apache.calcite.adapter.java.JavaTypeFactory;
-import org.apache.calcite.avatica.util.ByteString;
-import org.apache.calcite.avatica.util.DateTimeUtils;
-import org.apache.calcite.linq4j.function.Function1;
-import org.apache.calcite.linq4j.tree.BlockBuilder;
-import org.apache.calcite.linq4j.tree.ConstantExpression;
-import org.apache.calcite.linq4j.tree.Expression;
-import org.apache.calcite.linq4j.tree.ExpressionType;
-import org.apache.calcite.linq4j.tree.Expressions;
-import org.apache.calcite.linq4j.tree.ParameterExpression;
-import org.apache.calcite.linq4j.tree.Primitive;
-import org.apache.calcite.linq4j.tree.UnaryExpression;
-import org.apache.calcite.rel.type.RelDataType;
-import org.apache.calcite.rel.type.RelDataTypeFactoryImpl;
-import org.apache.calcite.rex.RexBuilder;
-import org.apache.calcite.rex.RexCall;
-import org.apache.calcite.rex.RexCorrelVariable;
-import org.apache.calcite.rex.RexDynamicParam;
-import org.apache.calcite.rex.RexFieldAccess;
-import org.apache.calcite.rex.RexInputRef;
-import org.apache.calcite.rex.RexLiteral;
-import org.apache.calcite.rex.RexLocalRef;
-import org.apache.calcite.rex.RexNode;
-import org.apache.calcite.rex.RexProgram;
-import org.apache.calcite.runtime.SqlFunctions;
-import org.apache.calcite.sql.SqlIntervalQualifier;
-import org.apache.calcite.sql.SqlKind;
-import org.apache.calcite.sql.SqlOperator;
-import org.apache.calcite.sql.type.SqlTypeUtil;
-import org.apache.calcite.util.BuiltInMethod;
-import org.apache.calcite.util.ControlFlowException;
-import org.apache.calcite.util.NlsString;
-import org.apache.calcite.util.Pair;
-import org.apache.calcite.util.Util;
-
-import com.google.common.collect.ImmutableMap;
-
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.lang.reflect.Type;
-import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Collections;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-import static org.apache.calcite.sql.fun.OracleSqlOperatorTable.TRANSLATE3;
-import static org.apache.calcite.sql.fun.SqlStdOperatorTable.CHARACTER_LENGTH;
-import static org.apache.calcite.sql.fun.SqlStdOperatorTable.CHAR_LENGTH;
-import static org.apache.calcite.sql.fun.SqlStdOperatorTable.SUBSTRING;
-import static org.apache.calcite.sql.fun.SqlStdOperatorTable.UPPER;
-
-/**
- * Translates {@link org.apache.calcite.rex.RexNode REX expressions} to
- * {@link Expression linq4j expressions}.
- */
-public class RexToLixTranslator {
-  public static final Map<Method, SqlOperator> JAVA_TO_SQL_METHOD_MAP =
-      Util.<Method, SqlOperator>mapOf(
-          findMethod(String.class, "toUpperCase"), UPPER,
-          findMethod(
-              SqlFunctions.class, "substring", String.class, Integer.TYPE,
-              Integer.TYPE), SUBSTRING,
-          findMethod(SqlFunctions.class, "charLength", String.class),
-          CHARACTER_LENGTH,
-          findMethod(SqlFunctions.class, "charLength", String.class),
-          CHAR_LENGTH,
-          findMethod(SqlFunctions.class, "translate3", String.class, 
String.class,
-              String.class), TRANSLATE3);
-
-  final JavaTypeFactory typeFactory;
-  final RexBuilder builder;
-  private final RexProgram program;
-  private final Expression root;
-  private final RexToLixTranslator.InputGetter inputGetter;
-  private final BlockBuilder list;
-  private final Map<? extends RexNode, Boolean> exprNullableMap;
-  private final RexToLixTranslator parent;
-  private final Function1<String, InputGetter> correlates;
-
-  private static Method findMethod(
-      Class<?> clazz, String name, Class... parameterTypes) {
-    try {
-      return clazz.getMethod(name, parameterTypes);
-    } catch (NoSuchMethodException e) {
-      throw new RuntimeException(e);
-    }
-  }
-
-  private RexToLixTranslator(RexProgram program, JavaTypeFactory typeFactory,
-      Expression root, InputGetter inputGetter, BlockBuilder list) {
-    this(program, typeFactory, root, inputGetter, list,
-        Collections.<RexNode, Boolean>emptyMap(),
-        new RexBuilder(typeFactory));
-  }
-
-  private RexToLixTranslator(
-      RexProgram program,
-      JavaTypeFactory typeFactory,
-      Expression root,
-      InputGetter inputGetter,
-      BlockBuilder list,
-      Map<RexNode, Boolean> exprNullableMap,
-      RexBuilder builder) {
-    this(program, typeFactory, root, inputGetter, list, exprNullableMap,
-        builder, null);
-  }
-
-  private RexToLixTranslator(
-      RexProgram program,
-      JavaTypeFactory typeFactory,
-      Expression root,
-      InputGetter inputGetter,
-      BlockBuilder list,
-      Map<? extends RexNode, Boolean> exprNullableMap,
-      RexBuilder builder,
-      RexToLixTranslator parent) {
-    this(program, typeFactory, root, inputGetter, list, exprNullableMap,
-        builder, parent, null);
-  }
-
-  private RexToLixTranslator(
-      RexProgram program,
-      JavaTypeFactory typeFactory,
-      Expression root,
-      InputGetter inputGetter,
-      BlockBuilder list,
-      Map<? extends RexNode, Boolean> exprNullableMap,
-      RexBuilder builder,
-      RexToLixTranslator parent,
-      Function1<String, InputGetter> correlates) {
-    this.program = program;
-    this.typeFactory = typeFactory;
-    this.root = root;
-    this.inputGetter = inputGetter;
-    this.list = list;
-    this.exprNullableMap = exprNullableMap;
-    this.builder = builder;
-    this.parent = parent;
-    this.correlates = correlates;
-  }
-
-  /**
-   * Translates a {@link RexProgram} to a sequence of expressions and
-   * declarations.
-   *
-   * @param program Program to be translated
-   * @param typeFactory Type factory
-   * @param list List of statements, populated with declarations
-   * @param outputPhysType Output type, or null
-   * @param root Root expression
-   * @param inputGetter Generates expressions for inputs
-   * @param correlates Provider of references to the values of correlated
-   *                   variables
-   * @return Sequence of expressions, optional condition
-   */
-  public static List<Expression> translateProjects(RexProgram program,
-      JavaTypeFactory typeFactory,
-      BlockBuilder list,
-      PhysType outputPhysType,
-      Expression root,
-      InputGetter inputGetter,
-      Function1<String, InputGetter> correlates) {
-    List<Type> storageTypes = null;
-    if (outputPhysType != null) {
-      final RelDataType rowType = outputPhysType.getRowType();
-      storageTypes = new ArrayList<>(rowType.getFieldCount());
-      for (int i = 0; i < rowType.getFieldCount(); i++) {
-        storageTypes.add(outputPhysType.getJavaFieldType(i));
-      }
-    }
-    return new RexToLixTranslator(program, typeFactory, root, inputGetter, 
list)
-        .setCorrelates(correlates)
-        .translateList(program.getProjectList(), storageTypes);
-  }
-
-  /** Creates a translator for translating aggregate functions. */
-  public static RexToLixTranslator forAggregation(JavaTypeFactory typeFactory,
-      BlockBuilder list, InputGetter inputGetter) {
-    final ParameterExpression root = DataContext.ROOT;
-    return new RexToLixTranslator(null, typeFactory, root, inputGetter, list);
-  }
-
-  Expression translate(RexNode expr) {
-    final RexImpTable.NullAs nullAs =
-        RexImpTable.NullAs.of(isNullable(expr));
-    return translate(expr, nullAs);
-  }
-
-  Expression translate(RexNode expr, RexImpTable.NullAs nullAs) {
-    return translate(expr, nullAs, null);
-  }
-
-  Expression translate(RexNode expr, Type storageType) {
-    final RexImpTable.NullAs nullAs =
-        RexImpTable.NullAs.of(isNullable(expr));
-    return translate(expr, nullAs, storageType);
-  }
-
-  Expression translate(RexNode expr, RexImpTable.NullAs nullAs,
-      Type storageType) {
-    Expression expression = translate0(expr, nullAs, storageType);
-    expression = EnumUtils.enforce(storageType, expression);
-    assert expression != null;
-    return list.append("v", expression);
-  }
-
-  Expression translateCast(
-      RelDataType sourceType,
-      RelDataType targetType,
-      Expression operand) {
-    Expression convert = null;
-    switch (targetType.getSqlTypeName()) {
-    case ANY:
-      convert = operand;
-      break;
-    case DATE:
-      switch (sourceType.getSqlTypeName()) {
-      case CHAR:
-      case VARCHAR:
-        convert =
-            Expressions.call(BuiltInMethod.STRING_TO_DATE.method, operand);
-        break;
-      case TIMESTAMP:
-        convert = Expressions.convert_(
-            Expressions.call(BuiltInMethod.FLOOR_DIV.method,
-                operand, Expressions.constant(DateTimeUtils.MILLIS_PER_DAY)),
-            int.class);
-      }
-      break;
-    case TIME:
-      switch (sourceType.getSqlTypeName()) {
-      case CHAR:
-      case VARCHAR:
-        convert =
-            Expressions.call(BuiltInMethod.STRING_TO_TIME.method, operand);
-        break;
-      case TIMESTAMP:
-        convert = Expressions.convert_(
-            Expressions.call(
-                BuiltInMethod.FLOOR_MOD.method,
-                operand,
-                Expressions.constant(DateTimeUtils.MILLIS_PER_DAY)),
-            int.class);
-      }
-      break;
-    case TIMESTAMP:
-      switch (sourceType.getSqlTypeName()) {
-      case CHAR:
-      case VARCHAR:
-        convert =
-            Expressions.call(BuiltInMethod.STRING_TO_TIMESTAMP.method, 
operand);
-        break;
-      case DATE:
-        convert = Expressions.multiply(
-            Expressions.convert_(operand, long.class),
-            Expressions.constant(DateTimeUtils.MILLIS_PER_DAY));
-        break;
-      case TIME:
-        convert =
-            Expressions.add(
-                Expressions.multiply(
-                    Expressions.convert_(
-                        Expressions.call(BuiltInMethod.CURRENT_DATE.method, 
root),
-                        long.class),
-                    Expressions.constant(DateTimeUtils.MILLIS_PER_DAY)),
-                Expressions.convert_(operand, long.class));
-        break;
-      }
-      break;
-    case BOOLEAN:
-      switch (sourceType.getSqlTypeName()) {
-      case CHAR:
-      case VARCHAR:
-        convert = Expressions.call(
-            BuiltInMethod.STRING_TO_BOOLEAN.method,
-            operand);
-      }
-      break;
-    case CHAR:
-    case VARCHAR:
-      final SqlIntervalQualifier interval =
-          sourceType.getIntervalQualifier();
-      switch (sourceType.getSqlTypeName()) {
-      case DATE:
-        convert = RexImpTable.optimize2(
-            operand,
-            Expressions.call(
-                BuiltInMethod.UNIX_DATE_TO_STRING.method,
-                operand));
-        break;
-      case TIME:
-        convert = RexImpTable.optimize2(
-            operand,
-            Expressions.call(
-                BuiltInMethod.UNIX_TIME_TO_STRING.method,
-                operand));
-        break;
-      case TIMESTAMP:
-        convert = RexImpTable.optimize2(
-            operand,
-            Expressions.call(
-                BuiltInMethod.UNIX_TIMESTAMP_TO_STRING.method,
-                operand));
-        break;
-      case INTERVAL_YEAR:
-      case INTERVAL_YEAR_MONTH:
-      case INTERVAL_MONTH:
-        convert = RexImpTable.optimize2(
-            operand,
-            Expressions.call(
-                BuiltInMethod.INTERVAL_YEAR_MONTH_TO_STRING.method,
-                operand,
-                Expressions.constant(interval.timeUnitRange)));
-        break;
-      case INTERVAL_DAY:
-      case INTERVAL_DAY_HOUR:
-      case INTERVAL_DAY_MINUTE:
-      case INTERVAL_DAY_SECOND:
-      case INTERVAL_HOUR:
-      case INTERVAL_HOUR_MINUTE:
-      case INTERVAL_HOUR_SECOND:
-      case INTERVAL_MINUTE:
-      case INTERVAL_MINUTE_SECOND:
-      case INTERVAL_SECOND:
-        convert = RexImpTable.optimize2(
-            operand,
-            Expressions.call(
-                BuiltInMethod.INTERVAL_DAY_TIME_TO_STRING.method,
-                operand,
-                Expressions.constant(interval.timeUnitRange),
-                Expressions.constant(
-                    interval.getFractionalSecondPrecision(
-                        typeFactory.getTypeSystem()))));
-        break;
-      case BOOLEAN:
-        convert = RexImpTable.optimize2(
-            operand,
-            Expressions.call(
-                BuiltInMethod.BOOLEAN_TO_STRING.method,
-                operand));
-        break;
-      }
-    }
-    if (convert == null) {
-      convert = convert(operand, typeFactory.getJavaClass(targetType));
-    }
-    // Going from anything to CHAR(n) or VARCHAR(n), make sure value is no
-    // longer than n.
-    boolean pad = false;
-    boolean truncate = true;
-    switch (targetType.getSqlTypeName()) {
-    case CHAR:
-    case BINARY:
-      pad = true;
-      // fall through
-    case VARCHAR:
-    case VARBINARY:
-      final int targetPrecision = targetType.getPrecision();
-      if (targetPrecision >= 0) {
-        switch (sourceType.getSqlTypeName()) {
-        case CHAR:
-        case VARCHAR:
-        case BINARY:
-        case VARBINARY:
-          // If this is a widening cast, no need to truncate.
-          final int sourcePrecision = sourceType.getPrecision();
-          if (SqlTypeUtil.comparePrecision(sourcePrecision, targetPrecision)
-              <= 0) {
-            truncate = false;
-          }
-          // If this is a widening cast, no need to pad.
-          if (SqlTypeUtil.comparePrecision(sourcePrecision, targetPrecision)
-              >= 0
-              && targetPrecision != RelDataType.PRECISION_NOT_SPECIFIED) {
-            pad = false;
-          }
-          // fall through
-        default:
-          if (truncate || pad) {
-            convert =
-                Expressions.call(
-                    pad
-                        ? BuiltInMethod.TRUNCATE_OR_PAD.method
-                        : BuiltInMethod.TRUNCATE.method,
-                    convert,
-                    Expressions.constant(targetPrecision));
-          }
-        }
-      }
-      break;
-    case TIMESTAMP:
-      int targetScale = targetType.getScale();
-      if (targetScale == RelDataType.SCALE_NOT_SPECIFIED) {
-        targetScale = 0;
-      }
-      if (targetScale < sourceType.getScale()) {
-        convert =
-            Expressions.call(
-                BuiltInMethod.ROUND_LONG.method,
-                convert,
-                Expressions.constant(
-                    (long) Math.pow(10, 3 - targetScale)));
-      }
-      break;
-    case INTERVAL_YEAR:
-    case INTERVAL_YEAR_MONTH:
-    case INTERVAL_MONTH:
-    case INTERVAL_DAY:
-    case INTERVAL_DAY_HOUR:
-    case INTERVAL_DAY_MINUTE:
-    case INTERVAL_DAY_SECOND:
-    case INTERVAL_HOUR:
-    case INTERVAL_HOUR_MINUTE:
-    case INTERVAL_HOUR_SECOND:
-    case INTERVAL_MINUTE:
-    case INTERVAL_MINUTE_SECOND:
-    case INTERVAL_SECOND:
-      switch (sourceType.getSqlTypeName().getFamily()) {
-      case NUMERIC:
-        final BigDecimal multiplier = 
targetType.getSqlTypeName().getEndUnit().multiplier;
-        final BigDecimal divider = BigDecimal.ONE;
-        convert = RexImpTable.multiplyDivide(convert, multiplier, divider);
-      }
-    }
-    return convert;
-  }
-
-  /** Translates an expression that is not in the cache.
-   *
-   * @param expr Expression
-   * @param nullAs If false, if expression is definitely not null at
-   *   runtime. Therefore we can optimize. For example, we can cast to int
-   *   using x.intValue().
-   * @return Translated expression
-   */
-  private Expression translate0(RexNode expr, RexImpTable.NullAs nullAs,
-      Type storageType) {
-    if (nullAs == RexImpTable.NullAs.NULL && !expr.getType().isNullable()) {
-      nullAs = RexImpTable.NullAs.NOT_POSSIBLE;
-    }
-    switch (expr.getKind()) {
-    case INPUT_REF:
-      final int index = ((RexInputRef) expr).getIndex();
-      Expression x = inputGetter.field(list, index, storageType);
-
-      Expression input = list.append("inp" + index + "_", x); // safe to share
-      if (nullAs == RexImpTable.NullAs.NOT_POSSIBLE
-          && input.type.equals(storageType)) {
-        // When we asked for not null input that would be stored as box, avoid
-        // unboxing via nullAs.handle below.
-        return input;
-      }
-      Expression nullHandled = nullAs.handle(input);
-
-      // If we get ConstantExpression, just return it (i.e. primitive false)
-      if (nullHandled instanceof ConstantExpression) {
-        return nullHandled;
-      }
-
-      // if nullHandled expression is the same as "input",
-      // then we can just reuse it
-      if (nullHandled == input) {
-        return input;
-      }
-
-      // If nullHandled is different, then it might be unsafe to compute
-      // early (i.e. unbox of null value should not happen _before_ ternary).
-      // Thus we wrap it into brand-new ParameterExpression,
-      // and we are guaranteed that ParameterExpression will not be shared
-      String unboxVarName = "v_unboxed";
-      if (input instanceof ParameterExpression) {
-        unboxVarName = ((ParameterExpression) input).name + "_unboxed";
-      }
-      ParameterExpression unboxed = 
Expressions.parameter(nullHandled.getType(),
-          list.newName(unboxVarName));
-      list.add(Expressions.declare(Modifier.FINAL, unboxed, nullHandled));
-
-      return unboxed;
-    case LOCAL_REF:
-      return translate(
-          deref(expr),
-          nullAs,
-          storageType);
-    case LITERAL:
-      return translateLiteral(
-          (RexLiteral) expr,
-          nullifyType(
-              expr.getType(),
-              isNullable(expr)
-                  && nullAs != RexImpTable.NullAs.NOT_POSSIBLE),
-          typeFactory,
-          nullAs);
-    case DYNAMIC_PARAM:
-      return translateParameter((RexDynamicParam) expr, nullAs, storageType);
-    case CORREL_VARIABLE:
-      throw new RuntimeException("Cannot translate " + expr + ". Correlated"
-          + " variables should always be referenced by field access");
-    case FIELD_ACCESS:
-      RexFieldAccess fieldAccess = (RexFieldAccess) expr;
-      RexNode target = deref(fieldAccess.getReferenceExpr());
-      // only $cor.field access is supported
-      if (!(target instanceof RexCorrelVariable)) {
-        throw new RuntimeException(
-            "cannot translate expression " + expr);
-      }
-      if (correlates == null) {
-        throw new RuntimeException("Cannot translate " + expr + " since "
-            + "correlate variables resolver is not defined");
-      }
-      InputGetter getter =
-          correlates.apply(((RexCorrelVariable) target).getName());
-      return getter.field(list, fieldAccess.getField().getIndex(), 
storageType);
-    default:
-      if (expr instanceof RexCall) {
-        return translateCall((RexCall) expr, nullAs);
-      }
-      throw new RuntimeException(
-          "cannot translate expression " + expr);
-    }
-  }
-
-  /** Dereferences an expression if it is a
-   * {@link org.apache.calcite.rex.RexLocalRef}. */
-  public RexNode deref(RexNode expr) {
-    if (expr instanceof RexLocalRef) {
-      RexLocalRef ref = (RexLocalRef) expr;
-      final RexNode e2 = program.getExprList().get(ref.getIndex());
-      assert ref.getType().equals(e2.getType());
-      return e2;
-    } else {
-      return expr;
-    }
-  }
-
-  /** Translates a call to an operator or function. */
-  private Expression translateCall(RexCall call, RexImpTable.NullAs nullAs) {
-    final SqlOperator operator = call.getOperator();
-    CallImplementor implementor =
-        RexImpTable.INSTANCE.get(operator);
-    if (implementor == null) {
-      throw new RuntimeException("cannot translate call " + call);
-    }
-    return implementor.implement(this, call, nullAs);
-  }
-
-  /** Translates a parameter. */
-  private Expression translateParameter(RexDynamicParam expr,
-      RexImpTable.NullAs nullAs, Type storageType) {
-    if (storageType == null) {
-      storageType = typeFactory.getJavaClass(expr.getType());
-    }
-    return nullAs.handle(
-        convert(
-            Expressions.call(root, BuiltInMethod.DATA_CONTEXT_GET.method,
-                Expressions.constant("?" + expr.getIndex())),
-            storageType));
-  }
-
-  /** Translates a literal.
-   *
-   * @throws AlwaysNull if literal is null but {@code nullAs} is
-   * {@link 
org.apache.calcite.adapter.enumerable.RexImpTable.NullAs#NOT_POSSIBLE}.
-   */
-  public static Expression translateLiteral(
-      RexLiteral literal,
-      RelDataType type,
-      JavaTypeFactory typeFactory,
-      RexImpTable.NullAs nullAs) {
-    final Comparable value = literal.getValue();
-    if (value == null) {
-      switch (nullAs) {
-      case TRUE:
-      case IS_NULL:
-        return RexImpTable.TRUE_EXPR;
-      case FALSE:
-      case IS_NOT_NULL:
-        return RexImpTable.FALSE_EXPR;
-      case NOT_POSSIBLE:
-        throw AlwaysNull.INSTANCE;
-      case NULL:
-      default:
-        return RexImpTable.NULL_EXPR;
-      }
-    } else {
-      switch (nullAs) {
-      case IS_NOT_NULL:
-        return RexImpTable.TRUE_EXPR;
-      case IS_NULL:
-        return RexImpTable.FALSE_EXPR;
-      }
-    }
-    Type javaClass = typeFactory.getJavaClass(type);
-    final Object value2;
-    switch (literal.getType().getSqlTypeName()) {
-    case DECIMAL:
-      if (javaClass == float.class) {
-        return Expressions.constant(value, javaClass);
-      }
-      assert javaClass == BigDecimal.class;
-      return Expressions.new_(BigDecimal.class,
-          Expressions.constant(value.toString()));
-    case DATE:
-      value2 = (int)
-          (((Calendar) value).getTimeInMillis() / 
DateTimeUtils.MILLIS_PER_DAY);
-      javaClass = int.class;
-      break;
-    case TIME:
-      value2 = (int)
-          (((Calendar) value).getTimeInMillis() % 
DateTimeUtils.MILLIS_PER_DAY);
-      javaClass = int.class;
-      break;
-    case TIMESTAMP:
-      value2 = ((Calendar) value).getTimeInMillis();
-      javaClass = long.class;
-      break;
-    case INTERVAL_DAY:
-    case INTERVAL_DAY_HOUR:
-    case INTERVAL_DAY_MINUTE:
-    case INTERVAL_DAY_SECOND:
-    case INTERVAL_HOUR:
-    case INTERVAL_HOUR_MINUTE:
-    case INTERVAL_HOUR_SECOND:
-    case INTERVAL_MINUTE:
-    case INTERVAL_MINUTE_SECOND:
-    case INTERVAL_SECOND:
-      value2 = ((BigDecimal) value).longValue();
-      javaClass = long.class;
-      break;
-    case INTERVAL_YEAR:
-    case INTERVAL_YEAR_MONTH:
-    case INTERVAL_MONTH:
-      value2 = ((BigDecimal) value).intValue();
-      javaClass = int.class;
-      break;
-    case CHAR:
-    case VARCHAR:
-      value2 = ((NlsString) value).getValue();
-      break;
-    case BINARY:
-    case VARBINARY:
-      return Expressions.new_(
-          ByteString.class,
-          Expressions.constant(
-              ((ByteString) value).getBytes(),
-              byte[].class));
-    case SYMBOL:
-      value2 = value;
-      javaClass = value.getClass();
-      break;
-    default:
-      final Primitive primitive = Primitive.ofBoxOr(javaClass);
-      if (primitive != null && value instanceof Number) {
-        value2 = primitive.number((Number) value);
-      } else {
-        value2 = value;
-      }
-    }
-    return Expressions.constant(value2, javaClass);
-  }
-
-  public List<Expression> translateList(
-      List<RexNode> operandList,
-      RexImpTable.NullAs nullAs) {
-    return translateList(operandList, nullAs,
-        EnumUtils.internalTypes(operandList));
-  }
-
-  public List<Expression> translateList(
-      List<RexNode> operandList,
-      RexImpTable.NullAs nullAs,
-      List<? extends Type> storageTypes) {
-    final List<Expression> list = new ArrayList<>();
-    for (Pair<RexNode, ? extends Type> e : Pair.zip(operandList, 
storageTypes)) {
-      list.add(translate(e.left, nullAs, e.right));
-    }
-    return list;
-  }
-
-  /**
-   * Translates the list of {@code RexNode}, using the default output types.
-   * This might be suboptimal in terms of additional box-unbox when you use
-   * the translation later.
-   * If you know the java class that will be used to store the results, use
-   * {@link 
org.apache.calcite.adapter.enumerable.RexToLixTranslator#translateList(java.util.List,
 java.util.List)}
-   * version.
-   *
-   * @param operandList list of RexNodes to translate
-   *
-   * @return translated expressions
-   */
-  public List<Expression> translateList(List<? extends RexNode> operandList) {
-    return translateList(operandList, EnumUtils.internalTypes(operandList));
-  }
-
-  /**
-   * Translates the list of {@code RexNode}, while optimizing for output
-   * storage.
-   * For instance, if the result of translation is going to be stored in
-   * {@code Object[]}, and the input is {@code Object[]} as well,
-   * then translator will avoid casting, boxing, etc.
-   *
-   * @param operandList list of RexNodes to translate
-   * @param storageTypes hints of the java classes that will be used
-   *                     to store translation results. Use null to use
-   *                     default storage type
-   *
-   * @return translated expressions
-   */
-  public List<Expression> translateList(List<? extends RexNode> operandList,
-      List<? extends Type> storageTypes) {
-    final List<Expression> list = new ArrayList<>(operandList.size());
-
-    for (int i = 0; i < operandList.size(); i++) {
-      RexNode rex = operandList.get(i);
-      Type desiredType = null;
-      if (storageTypes != null) {
-        desiredType = storageTypes.get(i);
-      }
-      final Expression translate = translate(rex, desiredType);
-      list.add(translate);
-      // desiredType is still a hint, thus we might get any kind of output
-      // (boxed or not) when hint was provided.
-      // It is favourable to get the type matching desired type
-      if (desiredType == null && !isNullable(rex)) {
-        assert !Primitive.isBox(translate.getType())
-            : "Not-null boxed primitive should come back as primitive: "
-            + rex + ", " + translate.getType();
-      }
-    }
-    return list;
-  }
-
-  public static Expression translateCondition(
-      RexProgram program,
-      JavaTypeFactory typeFactory,
-      BlockBuilder list,
-      InputGetter inputGetter,
-      Function1<String, InputGetter> correlates) {
-    if (program.getCondition() == null) {
-      return RexImpTable.TRUE_EXPR;
-    }
-    final ParameterExpression root = DataContext.ROOT;
-    RexToLixTranslator translator =
-        new RexToLixTranslator(program, typeFactory, root, inputGetter, list);
-    translator = translator.setCorrelates(correlates);
-    return translator.translate(
-        program.getCondition(),
-        RexImpTable.NullAs.FALSE);
-  }
-  public static Expression convert(Expression operand, Type toType) {
-    final Type fromType = operand.getType();
-    return convert(operand, fromType, toType);
-  }
-
-  public static Expression convert(Expression operand, Type fromType,
-      Type toType) {
-    if (fromType.equals(toType)) {
-      return operand;
-    }
-    // E.g. from "Short" to "int".
-    // Generate "x.intValue()".
-    final Primitive toPrimitive = Primitive.of(toType);
-    final Primitive toBox = Primitive.ofBox(toType);
-    final Primitive fromBox = Primitive.ofBox(fromType);
-    final Primitive fromPrimitive = Primitive.of(fromType);
-    final boolean fromNumber = fromType instanceof Class
-        && Number.class.isAssignableFrom((Class) fromType);
-    if (fromType == String.class) {
-      if (toPrimitive != null) {
-        switch (toPrimitive) {
-        case CHAR:
-        case SHORT:
-        case INT:
-        case LONG:
-        case FLOAT:
-        case DOUBLE:
-          // Generate "SqlFunctions.toShort(x)".
-          return Expressions.call(
-              SqlFunctions.class,
-              "to" + SqlFunctions.initcap(toPrimitive.primitiveName),
-              operand);
-        default:
-          // Generate "Short.parseShort(x)".
-          return Expressions.call(
-              toPrimitive.boxClass,
-              "parse" + SqlFunctions.initcap(toPrimitive.primitiveName),
-              operand);
-        }
-      }
-      if (toBox != null) {
-        switch (toBox) {
-        case CHAR:
-          // Generate "SqlFunctions.toCharBoxed(x)".
-          return Expressions.call(
-              SqlFunctions.class,
-              "to" + SqlFunctions.initcap(toBox.primitiveName) + "Boxed",
-              operand);
-        default:
-          // Generate "Short.valueOf(x)".
-          return Expressions.call(
-              toBox.boxClass,
-              "valueOf",
-              operand);
-        }
-      }
-    }
-    if (toPrimitive != null) {
-      if (fromPrimitive != null) {
-        // E.g. from "float" to "double"
-        return Expressions.convert_(
-            operand, toPrimitive.primitiveClass);
-      }
-      if (fromNumber || fromBox == Primitive.CHAR) {
-        // Generate "x.shortValue()".
-        return Expressions.unbox(operand, toPrimitive);
-      } else {
-        // E.g. from "Object" to "short".
-        // Generate "SqlFunctions.toShort(x)"
-        return Expressions.call(
-            SqlFunctions.class,
-            "to" + SqlFunctions.initcap(toPrimitive.primitiveName),
-            operand);
-      }
-    } else if (fromNumber && toBox != null) {
-      // E.g. from "Short" to "Integer"
-      // Generate "x == null ? null : Integer.valueOf(x.intValue())"
-      return Expressions.condition(
-          Expressions.equal(operand, RexImpTable.NULL_EXPR),
-          RexImpTable.NULL_EXPR,
-          Expressions.box(
-              Expressions.unbox(operand, toBox),
-              toBox));
-    } else if (fromPrimitive != null && toBox != null) {
-      // E.g. from "int" to "Long".
-      // Generate Long.valueOf(x)
-      // Eliminate primitive casts like Long.valueOf((long) x)
-      if (operand instanceof UnaryExpression) {
-        UnaryExpression una = (UnaryExpression) operand;
-        if (una.nodeType == ExpressionType.Convert
-            || Primitive.of(una.getType()) == toBox) {
-          return Expressions.box(una.expression, toBox);
-        }
-      }
-      return Expressions.box(operand, toBox);
-    } else if (fromType == java.sql.Date.class) {
-      if (toBox == Primitive.INT) {
-        return Expressions.call(BuiltInMethod.DATE_TO_INT.method, operand);
-      } else {
-        return Expressions.convert_(operand, toType);
-      }
-    } else if (toType == java.sql.Date.class) {
-      // E.g. from "int" or "Integer" to "java.sql.Date",
-      // generate "SqlFunctions.internalToDate".
-      if (isA(fromType, Primitive.INT)) {
-        return Expressions.call(BuiltInMethod.INTERNAL_TO_DATE.method, 
operand);
-      } else {
-        return Expressions.convert_(operand, java.sql.Date.class);
-      }
-    } else if (toType == java.sql.Time.class) {
-      // E.g. from "int" or "Integer" to "java.sql.Time",
-      // generate "SqlFunctions.internalToTime".
-      if (isA(fromType, Primitive.INT)) {
-        return Expressions.call(BuiltInMethod.INTERNAL_TO_TIME.method, 
operand);
-      } else {
-        return Expressions.convert_(operand, java.sql.Time.class);
-      }
-    } else if (toType == java.sql.Timestamp.class) {
-      // E.g. from "long" or "Long" to "java.sql.Timestamp",
-      // generate "SqlFunctions.internalToTimestamp".
-      if (isA(fromType, Primitive.LONG)) {
-        return Expressions.call(BuiltInMethod.INTERNAL_TO_TIMESTAMP.method,
-            operand);
-      } else {
-        return Expressions.convert_(operand, java.sql.Timestamp.class);
-      }
-    } else if (toType == BigDecimal.class) {
-      if (fromBox != null) {
-        // E.g. from "Integer" to "BigDecimal".
-        // Generate "x == null ? null : new BigDecimal(x.intValue())"
-        return Expressions.condition(
-            Expressions.equal(operand, RexImpTable.NULL_EXPR),
-            RexImpTable.NULL_EXPR,
-            Expressions.new_(
-                BigDecimal.class,
-                Expressions.unbox(operand, fromBox)));
-      }
-      if (fromPrimitive != null) {
-        // E.g. from "int" to "BigDecimal".
-        // Generate "new BigDecimal(x)"
-        return Expressions.new_(
-            BigDecimal.class, operand);
-      }
-      // E.g. from "Object" to "BigDecimal".
-      // Generate "x == null ? null : SqlFunctions.toBigDecimal(x)"
-      return Expressions.condition(
-          Expressions.equal(operand, RexImpTable.NULL_EXPR),
-          RexImpTable.NULL_EXPR,
-          Expressions.call(
-              SqlFunctions.class,
-              "toBigDecimal",
-              operand));
-    } else if (toType == String.class) {
-      if (fromPrimitive != null) {
-        switch (fromPrimitive) {
-        case DOUBLE:
-        case FLOAT:
-          // E.g. from "double" to "String"
-          // Generate "SqlFunctions.toString(x)"
-          return Expressions.call(
-              SqlFunctions.class,
-              "toString",
-              operand);
-        default:
-          // E.g. from "int" to "String"
-          // Generate "Integer.toString(x)"
-          return Expressions.call(
-              fromPrimitive.boxClass,
-              "toString",
-              operand);
-        }
-      } else if (fromType == BigDecimal.class) {
-        // E.g. from "BigDecimal" to "String"
-        // Generate "x.toString()"
-        return Expressions.condition(
-            Expressions.equal(operand, RexImpTable.NULL_EXPR),
-            RexImpTable.NULL_EXPR,
-            Expressions.call(
-                SqlFunctions.class,
-                "toString",
-                operand));
-      } else {
-        // E.g. from "BigDecimal" to "String"
-        // Generate "x == null ? null : x.toString()"
-        return Expressions.condition(
-            Expressions.equal(operand, RexImpTable.NULL_EXPR),
-            RexImpTable.NULL_EXPR,
-            Expressions.call(
-                operand,
-                "toString"));
-      }
-    }
-    return Expressions.convert_(operand, toType);
-  }
-
-  static boolean isA(Type fromType, Primitive primitive) {
-    return Primitive.of(fromType) == primitive
-        || Primitive.ofBox(fromType) == primitive;
-  }
-
-  public Expression translateConstructor(
-      List<RexNode> operandList, SqlKind kind) {
-    switch (kind) {
-    case MAP_VALUE_CONSTRUCTOR:
-      Expression map =
-          list.append(
-              "map",
-              Expressions.new_(LinkedHashMap.class),
-              false);
-      for (int i = 0; i < operandList.size(); i++) {
-        RexNode key = operandList.get(i++);
-        RexNode value = operandList.get(i);
-        list.add(
-            Expressions.statement(
-                Expressions.call(
-                    map,
-                    BuiltInMethod.MAP_PUT.method,
-                    Expressions.box(translate(key)),
-                    Expressions.box(translate(value)))));
-      }
-      return map;
-    case ARRAY_VALUE_CONSTRUCTOR:
-      Expression lyst =
-          list.append(
-              "list",
-              Expressions.new_(ArrayList.class),
-              false);
-      for (RexNode value : operandList) {
-        list.add(
-            Expressions.statement(
-                Expressions.call(
-                    lyst,
-                    BuiltInMethod.COLLECTION_ADD.method,
-                    Expressions.box(translate(value)))));
-      }
-      return lyst;
-    default:
-      throw new AssertionError("unexpected: " + kind);
-    }
-  }
-
-  /** Returns whether an expression is nullable. Even if its type says it is
-   * nullable, if we have previously generated a check to make sure that it is
-   * not null, we will say so.
-   *
-   * <p>For example, {@code WHERE a == b} translates to
-   * {@code a != null && b != null && a.equals(b)}. When translating the
-   * 3rd part of the disjunction, we already know a and b are not null.</p>
-   *
-   * @param e Expression
-   * @return Whether expression is nullable in the current translation context
-   */
-  public boolean isNullable(RexNode e) {
-    if (!e.getType().isNullable()) {
-      return false;
-    }
-    final Boolean b = isKnownNullable(e);
-    return b == null || b;
-  }
-
-  /**
-   * Walks parent translator chain and verifies if the expression is nullable.
-   *
-   * @param node RexNode to check if it is nullable or not
-   * @return null when nullability is not known, true or false otherwise
-   */
-  protected Boolean isKnownNullable(RexNode node) {
-    if (!exprNullableMap.isEmpty()) {
-      Boolean nullable = exprNullableMap.get(node);
-      if (nullable != null) {
-        return nullable;
-      }
-    }
-    return parent == null ? null : parent.isKnownNullable(node);
-  }
-
-  /** Creates a read-only copy of this translator that records that a given
-   * expression is nullable. */
-  public RexToLixTranslator setNullable(RexNode e, boolean nullable) {
-    return setNullable(Collections.singletonMap(e, nullable));
-  }
-
-  /** Creates a read-only copy of this translator that records that a given
-   * expression is nullable. */
-  public RexToLixTranslator setNullable(
-      Map<? extends RexNode, Boolean> nullable) {
-    if (nullable == null || nullable.isEmpty()) {
-      return this;
-    }
-    return new RexToLixTranslator(program, typeFactory, root, inputGetter, 
list,
-        nullable, builder, this, correlates);
-  }
-
-  public RexToLixTranslator setBlock(BlockBuilder block) {
-    if (block == list) {
-      return this;
-    }
-    return new RexToLixTranslator(program, typeFactory, root, inputGetter,
-        block, ImmutableMap.<RexNode, Boolean>of(), builder, this, correlates);
-  }
-
-  public RexToLixTranslator setCorrelates(
-      Function1<String, InputGetter> correlates) {
-    if (this.correlates == correlates) {
-      return this;
-    }
-    return new RexToLixTranslator(program, typeFactory, root, inputGetter, 
list,
-        Collections.<RexNode, Boolean>emptyMap(), builder, this, correlates);
-  }
-
-  public RelDataType nullifyType(RelDataType type, boolean nullable) {
-    if (!nullable) {
-      final Primitive primitive = javaPrimitive(type);
-      if (primitive != null) {
-        return typeFactory.createJavaType(primitive.primitiveClass);
-      }
-    }
-    return typeFactory.createTypeWithNullability(type, nullable);
-  }
-
-  private Primitive javaPrimitive(RelDataType type) {
-    if (type instanceof RelDataTypeFactoryImpl.JavaType) {
-      return Primitive.ofBox(
-          ((RelDataTypeFactoryImpl.JavaType) type).getJavaClass());
-    }
-    return null;
-  }
-
-  public Expression getRoot() {
-    return root;
-  }
-
-  /** Translates a field of an input to an expression. */
-  public interface InputGetter {
-    Expression field(BlockBuilder list, int index, Type storageType);
-  }
-
-  /** Implementation of {@link InputGetter} that calls
-   * {@link PhysType#fieldReference}. */
-  public static class InputGetterImpl implements InputGetter {
-    private List<Pair<Expression, PhysType>> inputs;
-
-    public InputGetterImpl(List<Pair<Expression, PhysType>> inputs) {
-      this.inputs = inputs;
-    }
-
-    public Expression field(BlockBuilder list, int index, Type storageType) {
-      int offset = 0;
-      for (Pair<Expression, PhysType> input : inputs) {
-        final PhysType physType = input.right;
-        int fieldCount = physType.getRowType().getFieldCount();
-        if (index >= offset + fieldCount) {
-          offset += fieldCount;
-          continue;
-        }
-        final Expression left = list.append("current", input.left);
-        return physType.fieldReference(left, index - offset, storageType);
-      }
-      throw new IllegalArgumentException("Unable to find field #" + index);
-    }
-  }
-
-  /** Thrown in the unusual (but not erroneous) situation where the expression
-   * we are translating is the null literal but we have already checked that
-   * it is not null. It is easier to throw (and caller will always handle)
-   * than to check exhaustively beforehand. */
-  static class AlwaysNull extends ControlFlowException {
-    @SuppressWarnings("ThrowableInstanceNeverThrown")
-    public static final AlwaysNull INSTANCE = new AlwaysNull();
-
-    private AlwaysNull() {}
-  }
-}
-
-// End RexToLixTranslator.java

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/core/src/main/java/org/apache/calcite/adapter/enumerable/StrictAggImplementor.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/StrictAggImplementor.java
 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/StrictAggImplementor.java
deleted file mode 100644
index a34813c..0000000
--- 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/StrictAggImplementor.java
+++ /dev/null
@@ -1,211 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.calcite.adapter.enumerable;
-
-import org.apache.calcite.linq4j.tree.BlockBuilder;
-import org.apache.calcite.linq4j.tree.BlockStatement;
-import org.apache.calcite.linq4j.tree.Expression;
-import org.apache.calcite.linq4j.tree.Expressions;
-import org.apache.calcite.linq4j.tree.ParameterExpression;
-import org.apache.calcite.linq4j.tree.Primitive;
-import org.apache.calcite.linq4j.tree.Types;
-import org.apache.calcite.rel.type.RelDataType;
-import org.apache.calcite.rex.RexNode;
-
-import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * The base implementation of strict aggregate function.
- * @see org.apache.calcite.adapter.enumerable.RexImpTable.CountImplementor
- * @see org.apache.calcite.adapter.enumerable.RexImpTable.SumImplementor
- */
-public abstract class StrictAggImplementor implements AggImplementor {
-  private boolean needTrackEmptySet;
-  private boolean trackNullsPerRow;
-  private int stateSize;
-
-  protected boolean nonDefaultOnEmptySet(AggContext info) {
-    return info.returnRelType().isNullable();
-  }
-
-  protected final int getStateSize() {
-    return stateSize;
-  }
-
-  protected final void accAdvance(AggAddContext add, Expression acc,
-      Expression next) {
-    add.currentBlock().add(
-        Expressions.statement(
-            Expressions.assign(acc, Types.castIfNecessary(acc.type, next))));
-  }
-
-  public final List<Type> getStateType(AggContext info) {
-    List<Type> subState = getNotNullState(info);
-    stateSize = subState.size();
-    needTrackEmptySet = nonDefaultOnEmptySet(info);
-    if (!needTrackEmptySet) {
-      return subState;
-    }
-    final boolean hasNullableArgs = anyNullable(info.parameterRelTypes());
-    trackNullsPerRow = !(info instanceof WinAggContext) || hasNullableArgs;
-
-    List<Type> res = new ArrayList<>(subState.size() + 1);
-    res.addAll(subState);
-    res.add(boolean.class); // has not nulls
-    return res;
-  }
-
-  private boolean anyNullable(List<? extends RelDataType> types) {
-    for (RelDataType type : types) {
-      if (type.isNullable()) {
-        return true;
-      }
-    }
-    return false;
-  }
-
-  public List<Type> getNotNullState(AggContext info) {
-    Type type = info.returnType();
-    type = EnumUtils.fromInternal(type);
-    type = Primitive.unbox(type);
-    return Collections.singletonList(type);
-  }
-
-  public final void implementReset(AggContext info, AggResetContext reset) {
-    if (trackNullsPerRow) {
-      List<Expression> acc = reset.accumulator();
-      Expression flag = acc.get(acc.size() - 1);
-      BlockBuilder block = reset.currentBlock();
-      block.add(
-          Expressions.statement(
-              Expressions.assign(flag,
-                  RexImpTable.getDefaultValue(flag.getType()))));
-    }
-    implementNotNullReset(info, reset);
-  }
-
-  protected void implementNotNullReset(AggContext info,
-      AggResetContext reset) {
-    BlockBuilder block = reset.currentBlock();
-    List<Expression> accumulator = reset.accumulator();
-    for (int i = 0; i < getStateSize(); i++) {
-      Expression exp = accumulator.get(i);
-      block.add(
-          Expressions.statement(
-              Expressions.assign(exp,
-                  RexImpTable.getDefaultValue(exp.getType()))));
-    }
-  }
-
-  public final void implementAdd(AggContext info, final AggAddContext add) {
-    final List<RexNode> args = add.rexArguments();
-    final RexToLixTranslator translator = add.rowTranslator();
-    final List<Expression> conditions = new ArrayList<>();
-    conditions.addAll(
-        translator.translateList(args, RexImpTable.NullAs.IS_NOT_NULL));
-    if (add.rexFilterArgument() != null) {
-      conditions.add(
-          translator.translate(add.rexFilterArgument(),
-              RexImpTable.NullAs.FALSE));
-    }
-    Expression condition = Expressions.foldAnd(conditions);
-    if (Expressions.constant(false).equals(condition)) {
-      return;
-    }
-
-    boolean argsNotNull = Expressions.constant(true).equals(condition);
-    final BlockBuilder thenBlock =
-        argsNotNull
-        ? add.currentBlock()
-        : new BlockBuilder(true, add.currentBlock());
-    if (trackNullsPerRow) {
-      List<Expression> acc = add.accumulator();
-      thenBlock.add(
-          Expressions.statement(
-              Expressions.assign(acc.get(acc.size() - 1),
-                  Expressions.constant(true))));
-    }
-    if (argsNotNull) {
-      implementNotNullAdd(info, add);
-      return;
-    }
-
-    final Map<RexNode, Boolean> nullables = new HashMap<>();
-    for (RexNode arg : args) {
-      if (translator.isNullable(arg)) {
-        nullables.put(arg, false);
-      }
-    }
-    add.nestBlock(thenBlock, nullables);
-    implementNotNullAdd(info, add);
-    add.exitBlock();
-    add.currentBlock().add(Expressions.ifThen(condition, thenBlock.toBlock()));
-  }
-
-  protected abstract void implementNotNullAdd(AggContext info,
-      AggAddContext add);
-
-  public final Expression implementResult(AggContext info,
-      final AggResultContext result) {
-    if (!needTrackEmptySet) {
-      return RexToLixTranslator.convert(
-          implementNotNullResult(info, result), info.returnType());
-    }
-    String tmpName = result.accumulator().isEmpty()
-        ? "ar"
-        : (result.accumulator().get(0) + "$Res");
-    ParameterExpression res = Expressions.parameter(0, info.returnType(),
-        result.currentBlock().newName(tmpName));
-
-    List<Expression> acc = result.accumulator();
-    final BlockBuilder thenBlock = result.nestBlock();
-    Expression nonNull = RexToLixTranslator.convert(
-        implementNotNullResult(info, result), info.returnType());
-    result.exitBlock();
-    thenBlock.add(Expressions.statement(Expressions.assign(res, nonNull)));
-    BlockStatement thenBranch = thenBlock.toBlock();
-    Expression seenNotNullRows =
-        trackNullsPerRow
-        ? acc.get(acc.size() - 1)
-        : ((WinAggResultContext) result).hasRows();
-
-    if (thenBranch.statements.size() == 1) {
-      return Expressions.condition(seenNotNullRows,
-          nonNull, RexImpTable.getDefaultValue(res.getType()));
-    }
-    result.currentBlock().add(Expressions.declare(0, res, null));
-    result.currentBlock().add(
-        Expressions.ifThenElse(seenNotNullRows,
-            thenBranch,
-            Expressions.statement(
-                Expressions.assign(res,
-                    RexImpTable.getDefaultValue(res.getType())))));
-    return res;
-  }
-
-  protected Expression implementNotNullResult(AggContext info,
-      AggResultContext result) {
-    return result.accumulator().get(0);
-  }
-}
-
-// End StrictAggImplementor.java

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/core/src/main/java/org/apache/calcite/adapter/enumerable/StrictWinAggImplementor.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/StrictWinAggImplementor.java
 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/StrictWinAggImplementor.java
deleted file mode 100644
index f2b0790..0000000
--- 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/StrictWinAggImplementor.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.calcite.adapter.enumerable;
-
-import org.apache.calcite.linq4j.tree.Expression;
-
-import java.lang.reflect.Type;
-import java.util.List;
-
-/**
- * The base implementation of strict window aggregate function.
- * @see 
org.apache.calcite.adapter.enumerable.RexImpTable.FirstLastValueImplementor
- * @see org.apache.calcite.adapter.enumerable.RexImpTable.RankImplementor
- * @see org.apache.calcite.adapter.enumerable.RexImpTable.RowNumberImplementor
- */
-public abstract class StrictWinAggImplementor extends StrictAggImplementor
-    implements WinAggImplementor {
-  protected abstract void implementNotNullAdd(WinAggContext info,
-      WinAggAddContext add);
-
-  protected boolean nonDefaultOnEmptySet(WinAggContext info) {
-    return super.nonDefaultOnEmptySet(info);
-  }
-
-  public List<Type> getNotNullState(WinAggContext info) {
-    return super.getNotNullState(info);
-  }
-
-  protected void implementNotNullReset(WinAggContext info,
-      WinAggResetContext reset) {
-    super.implementNotNullReset(info, reset);
-  }
-
-  protected Expression implementNotNullResult(WinAggContext info,
-      WinAggResultContext result) {
-    return super.implementNotNullResult(info, result);
-  }
-
-  @Override protected final void implementNotNullAdd(AggContext info,
-      AggAddContext add) {
-    implementNotNullAdd((WinAggContext) info, (WinAggAddContext) add);
-  }
-
-  @Override protected boolean nonDefaultOnEmptySet(AggContext info) {
-    return nonDefaultOnEmptySet((WinAggContext) info);
-  }
-
-  @Override public final List<Type> getNotNullState(AggContext info) {
-    return getNotNullState((WinAggContext) info);
-  }
-
-  @Override protected final void implementNotNullReset(AggContext info,
-      AggResetContext reset) {
-    implementNotNullReset((WinAggContext) info, (WinAggResetContext) reset);
-  }
-
-  @Override protected final Expression implementNotNullResult(AggContext info,
-      AggResultContext result) {
-    return implementNotNullResult((WinAggContext) info,
-        (WinAggResultContext) result);
-  }
-
-  public boolean needCacheWhenFrameIntact() {
-    return true;
-  }
-}
-
-// End StrictWinAggImplementor.java

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/core/src/main/java/org/apache/calcite/adapter/enumerable/WinAggAddContext.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/WinAggAddContext.java
 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/WinAggAddContext.java
deleted file mode 100644
index 13717e5..0000000
--- 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/WinAggAddContext.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.calcite.adapter.enumerable;
-
-import org.apache.calcite.linq4j.tree.Expression;
-
-/**
- * Information for a call to
- * {@link AggImplementor#implementAdd(AggContext, AggAddContext)}.
- *
- * <p>{@link WinAggAddContext} is used when implementing windowed aggregate.
- * Typically, the aggregation implementation will use {@link #arguments()}
- * or {@link #rexArguments()} to update aggregate value.
- * @see AggAddContext
- */
-public interface WinAggAddContext extends AggAddContext, WinAggResultContext {
-  /**
-   * Returns current position inside for-loop of window aggregate.
-   * Note, the position is relative to {@link WinAggFrameContext#startIndex()}.
-   * This is NOT current row as in "rows between current row".
-   * If you need to know the relative index of the current row in the 
partition,
-   * use {@link WinAggFrameContext#index()}.
-   * @return current position inside for-loop of window aggregate.
-   * @see WinAggFrameContext#index()
-   * @see WinAggFrameContext#startIndex()
-   */
-  Expression currentPosition();
-}
-
-// End WinAggAddContext.java

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/core/src/main/java/org/apache/calcite/adapter/enumerable/WinAggContext.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/WinAggContext.java 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/WinAggContext.java
deleted file mode 100644
index db0a6cd..0000000
--- 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/WinAggContext.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.calcite.adapter.enumerable;
-
-/**
- * Marker interface to allow
- * {@link org.apache.calcite.adapter.enumerable.AggImplementor}
- * to tell if it is used in regular or windowed context.
- */
-public interface WinAggContext extends AggContext {
-}
-
-// End WinAggContext.java

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/core/src/main/java/org/apache/calcite/adapter/enumerable/WinAggFrameContext.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/WinAggFrameContext.java
 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/WinAggFrameContext.java
deleted file mode 100644
index 73782a3..0000000
--- 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/WinAggFrameContext.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.calcite.adapter.enumerable;
-
-import org.apache.calcite.linq4j.tree.Expression;
-
-/**
- * Provides information on the current window.
- *
- * <p>All the indexes are ready to be used in
- * {@link 
WinAggResultContext#arguments(org.apache.calcite.linq4j.tree.Expression)},
- * {@link 
WinAggFrameResultContext#rowTranslator(org.apache.calcite.linq4j.tree.Expression)}
- * and similar methods.
- */
-public interface WinAggFrameContext {
-  /**
-   * Returns the index of the current row in the partition.
-   * In other words, it is close to ~ROWS BETWEEN CURRENT ROW.
-   * Note to use {@link #startIndex()} when you need zero-based row position.
-   * @return the index of the very first row in partition
-   */
-  Expression index();
-
-  /**
-   * Returns the index of the very first row in partition.
-   * @return index of the very first row in partition
-   */
-  Expression startIndex();
-
-  /**
-   * Returns the index of the very last row in partition.
-   * @return index of the very last row in partition
-   */
-  Expression endIndex();
-
-  /**
-   * Returns the boolean expression that tells if the partition has rows.
-   * The partition might lack rows in cases like ROWS BETWEEN 1000 PRECEDING
-   * AND 900 PRECEDING.
-   * @return boolean expression that tells if the partition has rows
-   */
-  Expression hasRows();
-
-  /**
-   * Returns the number of rows in the current frame (subject to framing
-   * clause).
-   * @return number of rows in the current partition or 0 if the partition
-   *   is empty
-   */
-  Expression getFrameRowCount();
-
-  /**
-   * Returns the number of rows in the current partition (as determined by
-   * PARTITION BY clause).
-   * @return number of rows in the current partition or 0 if the partition
-   *   is empty
-   */
-  Expression getPartitionRowCount();
-}
-
-// End WinAggFrameContext.java

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/core/src/main/java/org/apache/calcite/adapter/enumerable/WinAggFrameResultContext.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/WinAggFrameResultContext.java
 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/WinAggFrameResultContext.java
deleted file mode 100644
index f0b4d87..0000000
--- 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/WinAggFrameResultContext.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.calcite.adapter.enumerable;
-
-import org.apache.calcite.linq4j.tree.Expression;
-
-/**
- * Provides information on the current window when computing the result of
- * the aggregation.
- */
-public interface WinAggFrameResultContext extends WinAggFrameContext {
-  /**
-   * Converts absolute index position of the given relative position.
-   * @param offset offset of the requested row
-   * @param seekType the type of offset (start of window, end of window, etc)
-   * @return absolute position of the requested row
-   */
-  Expression computeIndex(Expression offset,
-      WinAggImplementor.SeekType seekType);
-
-  /**
-   * Returns boolean the expression that checks if the given index is in
-   * the frame bounds.
-   * @param rowIndex index if the row to check
-   * @return expression that validates frame bounds for the given index
-   */
-  Expression rowInFrame(Expression rowIndex);
-
-  /**
-   * Returns boolean the expression that checks if the given index is in
-   * the partition bounds.
-   * @param rowIndex index if the row to check
-   * @return expression that validates partition bounds for the given index
-   */
-  Expression rowInPartition(Expression rowIndex);
-
-  /**
-   * Returns row translator for given absolute row position.
-   * @param rowIndex absolute index of the row.
-   * @return translator for the requested row
-   */
-  RexToLixTranslator rowTranslator(Expression rowIndex);
-
-  /**
-   * Compares two rows given by absolute positions according to the order
-   * collation of the current window.
-   * @param a absolute index of the first row
-   * @param b absolute index of the second row
-   * @return result of comparison as as in {@link Comparable#compareTo}
-   */
-  Expression compareRows(Expression a, Expression b);
-}
-
-// End WinAggFrameResultContext.java

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/core/src/main/java/org/apache/calcite/adapter/enumerable/WinAggImplementor.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/WinAggImplementor.java
 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/WinAggImplementor.java
deleted file mode 100644
index 7d2489f..0000000
--- 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/WinAggImplementor.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.calcite.adapter.enumerable;
-
-/**
- * Implements a windowed aggregate function by generating expressions to
- * initialize, add to, and get a result from, an accumulator.
- * Windowed aggregate is more powerful than regular aggregate since it can
- * access rows in the current partition by row indices.
- * Regular aggregate can be used to implement windowed aggregate.
- * <p>This interface does not define new methods: window-specific
- * sub-interfaces are passed when implementing window aggregate.
- *
- * @see org.apache.calcite.adapter.enumerable.StrictWinAggImplementor
- * @see 
org.apache.calcite.adapter.enumerable.RexImpTable.FirstLastValueImplementor
- * @see org.apache.calcite.adapter.enumerable.RexImpTable.RankImplementor
- * @see org.apache.calcite.adapter.enumerable.RexImpTable.RowNumberImplementor
- */
-public interface WinAggImplementor extends AggImplementor {
-  /**
-   * Allows to access rows in window partition relative to first/last and
-   * current row.
-   */
-  public enum SeekType {
-    /**
-     * Start of window.
-     * @see WinAggFrameContext#startIndex()
-     */
-    START,
-    /**
-     * Row position in the frame.
-     * @see WinAggFrameContext#index()
-     */
-    SET,
-    /**
-     * The index of row that is aggregated.
-     * Valid only in {@link WinAggAddContext}.
-     * @see WinAggAddContext#currentPosition()
-     */
-    AGG_INDEX,
-    /**
-     * End of window.
-     * @see WinAggFrameContext#endIndex()
-     */
-    END
-  }
-
-  boolean needCacheWhenFrameIntact();
-}
-
-// End WinAggImplementor.java

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/core/src/main/java/org/apache/calcite/adapter/enumerable/WinAggResetContext.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/WinAggResetContext.java
 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/WinAggResetContext.java
deleted file mode 100644
index 9dee01e..0000000
--- 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/WinAggResetContext.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.calcite.adapter.enumerable;
-
-/**
- * Information for a call to
- * {@link AggImplementor#implementReset(AggContext, AggResetContext)}.
- *
- * <p>The {@link AggResetContext} provides access to the accumulator variables
- * that should be reset.
- *
- * <p>Note: the very first reset of windowed aggregates is performed with null
- * knowledge of indices and row count in the partition.
- * In other words, the implementation should treat indices and partition row
- * count as a hint to pre-size the collections.
- */
-public interface WinAggResetContext
-    extends AggResetContext, WinAggFrameContext {
-}
-
-// End WinAggResetContext.java

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/core/src/main/java/org/apache/calcite/adapter/enumerable/WinAggResultContext.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/WinAggResultContext.java
 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/WinAggResultContext.java
deleted file mode 100644
index 3b83b19..0000000
--- 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/WinAggResultContext.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.calcite.adapter.enumerable;
-
-import org.apache.calcite.linq4j.tree.Expression;
-import org.apache.calcite.rex.RexNode;
-
-import java.util.List;
-
-/**
- * Information for a call to
- * {@link AggImplementor#implementResult(AggContext, AggResultContext)}.
- *
- * <p>Typically, the aggregation implementation will convert
- * {@link #accumulator()} to the resulting value of the aggregation.  The
- * implementation MUST NOT destroy the contents of {@link #accumulator()}.
- */
-public interface WinAggResultContext extends AggResultContext,
-    WinAggFrameResultContext {
-  /**
-   * Returns {@link org.apache.calcite.rex.RexNode} representation of 
arguments.
-   * This can be useful for manual translation of required arguments with
-   * different {@link NullPolicy}.
-   * @return {@link org.apache.calcite.rex.RexNode} representation of arguments
-   */
-  List<RexNode> rexArguments();
-
-  /**
-   * Returns Linq4j form of arguments.
-   * The resulting value is equivalent to
-   * {@code rowTranslator().translateList(rexArguments())}.
-   * This is handy if you need just operate on argument.
-   * @param rowIndex index of the requested row. The index must be in range
-   *                 of partition's startIndex and endIndex.
-   * @return Linq4j form of arguments of the particular row
-   */
-  List<Expression> arguments(Expression rowIndex);
-}
-
-// End WinAggResultContext.java

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/core/src/main/java/org/apache/calcite/adapter/enumerable/impl/AggAddContextImpl.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/impl/AggAddContextImpl.java
 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/impl/AggAddContextImpl.java
deleted file mode 100644
index 18ba8cc..0000000
--- 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/impl/AggAddContextImpl.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.calcite.adapter.enumerable.impl;
-
-import org.apache.calcite.adapter.enumerable.AggAddContext;
-import org.apache.calcite.linq4j.tree.BlockBuilder;
-import org.apache.calcite.linq4j.tree.Expression;
-
-import java.util.List;
-
-/**
- * Implementation of
- * {@link org.apache.calcite.adapter.enumerable.AggAddContext}.
- */
-public abstract class AggAddContextImpl extends AggResultContextImpl
-    implements AggAddContext {
-  public AggAddContextImpl(BlockBuilder block, List<Expression> accumulator) {
-    super(block, accumulator);
-  }
-
-  public final List<Expression> arguments() {
-    return rowTranslator().translateList(rexArguments());
-  }
-}
-
-// End AggAddContextImpl.java

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/core/src/main/java/org/apache/calcite/adapter/enumerable/impl/AggResetContextImpl.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/impl/AggResetContextImpl.java
 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/impl/AggResetContextImpl.java
deleted file mode 100644
index 3e66705..0000000
--- 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/impl/AggResetContextImpl.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.calcite.adapter.enumerable.impl;
-
-import org.apache.calcite.adapter.enumerable.AggResetContext;
-import org.apache.calcite.adapter.enumerable.NestedBlockBuilderImpl;
-import org.apache.calcite.linq4j.tree.BlockBuilder;
-import org.apache.calcite.linq4j.tree.Expression;
-
-import java.util.List;
-
-/**
- * Implementation of
- * {@link org.apache.calcite.adapter.enumerable.AggResetContext}
- */
-public class AggResetContextImpl extends NestedBlockBuilderImpl
-    implements AggResetContext {
-  private final List<Expression> accumulator;
-
-  /**
-   * Creates aggregate reset context
-   * @param block code block that will contain the added initialization
-   * @param accumulator accumulator variables that store the intermediate
-   *                    aggregate state
-   */
-  public AggResetContextImpl(BlockBuilder block, List<Expression> accumulator) 
{
-    super(block);
-    this.accumulator = accumulator;
-  }
-
-  public List<Expression> accumulator() {
-    return accumulator;
-  }
-}
-
-// End AggResetContextImpl.java

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/core/src/main/java/org/apache/calcite/adapter/enumerable/impl/AggResultContextImpl.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/impl/AggResultContextImpl.java
 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/impl/AggResultContextImpl.java
deleted file mode 100644
index 1da28c6..0000000
--- 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/impl/AggResultContextImpl.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.calcite.adapter.enumerable.impl;
-
-import org.apache.calcite.adapter.enumerable.AggResultContext;
-import org.apache.calcite.linq4j.tree.BlockBuilder;
-import org.apache.calcite.linq4j.tree.Expression;
-
-import java.util.List;
-
-/**
- * Implementation of
- * {@link org.apache.calcite.adapter.enumerable.AggResultContext}
- */
-public class AggResultContextImpl extends AggResetContextImpl
-    implements AggResultContext {
-  /**
-   * Creates aggregate result context
-   * @param block code block that will contain the result calculation 
statements
-   * @param accumulator accumulator variables that store the intermediate
-   *                    aggregate state
-   */
-  public AggResultContextImpl(BlockBuilder block,
-      List<Expression> accumulator) {
-    super(block, accumulator);
-  }
-}
-
-// End AggResultContextImpl.java

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/core/src/main/java/org/apache/calcite/adapter/enumerable/impl/WinAggAddContextImpl.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/impl/WinAggAddContextImpl.java
 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/impl/WinAggAddContextImpl.java
deleted file mode 100644
index 9932cab..0000000
--- 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/impl/WinAggAddContextImpl.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.calcite.adapter.enumerable.impl;
-
-import org.apache.calcite.adapter.enumerable.RexToLixTranslator;
-import org.apache.calcite.adapter.enumerable.WinAggAddContext;
-import org.apache.calcite.adapter.enumerable.WinAggFrameResultContext;
-import org.apache.calcite.adapter.enumerable.WinAggImplementor;
-import org.apache.calcite.linq4j.tree.BlockBuilder;
-import org.apache.calcite.linq4j.tree.Expression;
-import org.apache.calcite.linq4j.tree.Expressions;
-
-import com.google.common.base.Function;
-
-import java.util.List;
-
-/**
- * Implementation of
- * {@link org.apache.calcite.adapter.enumerable.WinAggAddContext}.
- */
-public abstract class WinAggAddContextImpl extends WinAggResultContextImpl
-    implements WinAggAddContext {
-  public WinAggAddContextImpl(BlockBuilder block, List<Expression> accumulator,
-      Function<BlockBuilder, WinAggFrameResultContext> frame) {
-    super(block, accumulator, frame);
-  }
-
-  public final RexToLixTranslator rowTranslator() {
-    return rowTranslator(
-        computeIndex(Expressions.constant(0),
-            WinAggImplementor.SeekType.AGG_INDEX));
-  }
-
-  public final List<Expression> arguments() {
-    return rowTranslator().translateList(rexArguments());
-  }
-}
-
-// End WinAggAddContextImpl.java

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/core/src/main/java/org/apache/calcite/adapter/enumerable/impl/WinAggResetContextImpl.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/impl/WinAggResetContextImpl.java
 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/impl/WinAggResetContextImpl.java
deleted file mode 100644
index 0145f80..0000000
--- 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/impl/WinAggResetContextImpl.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.calcite.adapter.enumerable.impl;
-
-import org.apache.calcite.adapter.enumerable.WinAggResetContext;
-import org.apache.calcite.linq4j.tree.BlockBuilder;
-import org.apache.calcite.linq4j.tree.Expression;
-
-import java.util.List;
-
-/**
- * Implementation of
- * {@link org.apache.calcite.adapter.enumerable.WinAggResetContext}.
- */
-public class WinAggResetContextImpl extends AggResetContextImpl
-    implements WinAggResetContext {
-  private final Expression index;
-  private final Expression startIndex;
-  private final Expression endIndex;
-  private final Expression frameRowCount;
-  private final Expression partitionRowCount;
-  private final Expression hasRows;
-
-  /**
-   * Creates window aggregate reset context.
-   * @param block code block that will contain the added initialization
-   * @param accumulator accumulator variables that store the intermediate
-   *                    aggregate state
-   * @param index index of the current row in the partition
-   * @param startIndex index of the very first row in partition
-   * @param endIndex index of the very last row in partition
-   * @param hasRows boolean expression that tells if the partition has rows
-   * @param frameRowCount number of rows in the current frame
-   * @param partitionRowCount number of rows in the current partition
-   */
-  public WinAggResetContextImpl(BlockBuilder block,
-      List<Expression> accumulator, Expression index,
-      Expression startIndex, Expression endIndex,
-      Expression hasRows,
-      Expression frameRowCount, Expression partitionRowCount) {
-    super(block, accumulator);
-    this.index = index;
-    this.startIndex = startIndex;
-    this.endIndex = endIndex;
-    this.frameRowCount = frameRowCount;
-    this.partitionRowCount = partitionRowCount;
-    this.hasRows = hasRows;
-  }
-
-  public Expression index() {
-    return index;
-  }
-
-  public Expression startIndex() {
-    return startIndex;
-  }
-
-  public Expression endIndex() {
-    return endIndex;
-  }
-
-  public Expression hasRows() {
-    return hasRows;
-  }
-
-  public Expression getFrameRowCount() {
-    return frameRowCount;
-  }
-
-  public Expression getPartitionRowCount() {
-    return partitionRowCount;
-  }
-}
-
-// End WinAggResetContextImpl.java

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/core/src/main/java/org/apache/calcite/adapter/enumerable/impl/WinAggResultContextImpl.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/impl/WinAggResultContextImpl.java
 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/impl/WinAggResultContextImpl.java
deleted file mode 100644
index d4a5c6f..0000000
--- 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/impl/WinAggResultContextImpl.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.calcite.adapter.enumerable.impl;
-
-import org.apache.calcite.adapter.enumerable.RexToLixTranslator;
-import org.apache.calcite.adapter.enumerable.WinAggFrameResultContext;
-import org.apache.calcite.adapter.enumerable.WinAggImplementor;
-import org.apache.calcite.adapter.enumerable.WinAggResultContext;
-import org.apache.calcite.linq4j.tree.BlockBuilder;
-import org.apache.calcite.linq4j.tree.Expression;
-
-import com.google.common.base.Function;
-
-import java.util.List;
-
-/**
- * Implementation of
- * {@link org.apache.calcite.adapter.enumerable.WinAggResultContext}.
- */
-public abstract class WinAggResultContextImpl extends AggResultContextImpl
-    implements WinAggResultContext {
-
-  private final Function<BlockBuilder, WinAggFrameResultContext> frame;
-
-  /**
-   * Creates window aggregate result context.
-   * @param block code block that will contain the added initialization
-   * @param accumulator accumulator variables that store the intermediate
-   *                    aggregate state
-   */
-  public WinAggResultContextImpl(BlockBuilder block,
-      List<Expression> accumulator,
-      Function<BlockBuilder, WinAggFrameResultContext> frameContextBuilder) {
-    super(block, accumulator);
-    this.frame = frameContextBuilder;
-  }
-
-  private WinAggFrameResultContext getFrame() {
-    return frame.apply(currentBlock());
-  }
-
-  public final List<Expression> arguments(Expression rowIndex) {
-    return rowTranslator(rowIndex).translateList(rexArguments());
-  }
-
-  public Expression computeIndex(Expression offset,
-      WinAggImplementor.SeekType seekType) {
-    return getFrame().computeIndex(offset, seekType);
-  }
-
-  public Expression rowInFrame(Expression rowIndex) {
-    return getFrame().rowInFrame(rowIndex);
-  }
-
-  public Expression rowInPartition(Expression rowIndex) {
-    return getFrame().rowInPartition(rowIndex);
-  }
-
-  public RexToLixTranslator rowTranslator(Expression rowIndex) {
-    return getFrame().rowTranslator(rowIndex)
-        .setNullable(currentNullables());
-  }
-
-  public Expression compareRows(Expression a, Expression b) {
-    return getFrame().compareRows(a, b);
-  }
-
-  public Expression index() {
-    return getFrame().index();
-  }
-
-  public Expression startIndex() {
-    return getFrame().startIndex();
-  }
-
-  public Expression endIndex() {
-    return getFrame().endIndex();
-  }
-
-  public Expression hasRows() {
-    return getFrame().hasRows();
-  }
-
-  public Expression getFrameRowCount() {
-    return getFrame().getFrameRowCount();
-  }
-
-  public Expression getPartitionRowCount() {
-    return getFrame().getPartitionRowCount();
-  }
-}
-
-// End WinAggResultContextImpl.java

Reply via email to