Package org.apache.tajo.engine.eval

Source Code of org.apache.tajo.engine.eval.GeneralFunctionEval

/**
* 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.tajo.engine.eval;

import com.google.common.base.Objects;
import com.google.gson.annotations.Expose;
import org.apache.tajo.catalog.FunctionDesc;
import org.apache.tajo.catalog.Schema;
import org.apache.tajo.engine.function.GeneralFunction;
import org.apache.tajo.datum.Datum;
import org.apache.tajo.storage.Tuple;
import org.apache.tajo.storage.VTuple;
import org.apache.tajo.util.TUtil;

public class GeneralFunctionEval extends FunctionEval {
  @Expose protected GeneralFunction instance;
  private Tuple tuple;
  private Tuple params = null;
  private Schema schema;

  public GeneralFunctionEval(FunctionDesc desc, GeneralFunction instance, EvalNode[] givenArgs) {
    super(EvalType.FUNCTION, desc, givenArgs);
    this.instance = instance;
    this.instance.init(getParamType());
  }

  /* (non-Javadoc)
    * @see nta.query.executor.eval.Expr#evalVal(Tuple)
    */
  @Override
  public void eval(EvalContext ctx, Schema schema, Tuple tuple) {
    this.schema = schema;
    this.tuple = tuple;
  }

  @Override
  public Datum terminate(EvalContext ctx) {
    FuncCallCtx localCtx = (FuncCallCtx) ctx;
    if (this.params == null) {
      params = new VTuple(argEvals.length);
    }

    if(argEvals != null) {
      params.clear();
      for(int i=0;i < argEvals.length; i++) {
        argEvals[i].eval(localCtx.argCtxs[i], schema, tuple);
        params.put(i, argEvals[i].terminate(localCtx.argCtxs[i]));
      }
    }
    return instance.eval(params);
  }
 
  @Override
  public boolean equals(Object obj) {
    if (obj instanceof GeneralFunctionEval) {
      GeneralFunctionEval other = (GeneralFunctionEval) obj;
      return super.equals(other) &&
          TUtil.checkEquals(instance, other.instance);
    }
   
    return false;
  }
 
  @Override
  public int hashCode() {
    return Objects.hashCode(funcDesc, instance);
  }
 
  @Override
  public Object clone() throws CloneNotSupportedException {
    GeneralFunctionEval eval = (GeneralFunctionEval) super.clone();
    eval.instance = (GeneralFunction) instance.clone();
    return eval;
  }
}
TOP

Related Classes of org.apache.tajo.engine.eval.GeneralFunctionEval

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.