tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hyun...@apache.org
Subject [46/51] [partial] TAJO-752: Escalate sub modules in tajo-core into the top-level modules. (hyunsik)
Date Fri, 18 Apr 2014 10:31:58 GMT
http://git-wip-us.apache.org/repos/asf/tajo/blob/026368be/tajo-core/src/main/java/org/apache/tajo/engine/exception/AmbiguousFieldException.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/exception/AmbiguousFieldException.java b/tajo-core/src/main/java/org/apache/tajo/engine/exception/AmbiguousFieldException.java
new file mode 100644
index 0000000..3125e30
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/exception/AmbiguousFieldException.java
@@ -0,0 +1,30 @@
+/**
+ * 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.exception;
+
+public class AmbiguousFieldException extends InvalidQueryException {
+	private static final long serialVersionUID = 3102675985226352347L;
+
+	/**
+	 * @param fieldName
+	 */
+	public AmbiguousFieldException(String fieldName) {
+		super("ERROR: column name "+ fieldName + " is ambiguous");	
+	}
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/026368be/tajo-core/src/main/java/org/apache/tajo/engine/exception/IllegalQueryStatusException.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/exception/IllegalQueryStatusException.java b/tajo-core/src/main/java/org/apache/tajo/engine/exception/IllegalQueryStatusException.java
new file mode 100644
index 0000000..66e9ee7
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/exception/IllegalQueryStatusException.java
@@ -0,0 +1,38 @@
+/**
+ * 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.exception;
+
+public class IllegalQueryStatusException extends Exception {
+
+  public IllegalQueryStatusException() {
+
+  }
+
+  public IllegalQueryStatusException(String msg) {
+    super(msg);
+  }
+
+  public IllegalQueryStatusException(Exception e) {
+    super(e);
+  }
+
+  public IllegalQueryStatusException(String msg, Exception e) {
+    super(msg, e);
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/026368be/tajo-core/src/main/java/org/apache/tajo/engine/exception/InvalidQueryException.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/exception/InvalidQueryException.java b/tajo-core/src/main/java/org/apache/tajo/engine/exception/InvalidQueryException.java
new file mode 100644
index 0000000..fba691d
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/exception/InvalidQueryException.java
@@ -0,0 +1,35 @@
+/**
+ * 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.exception;
+
+public class InvalidQueryException extends RuntimeException {
+	private static final long serialVersionUID = -7085849718839416246L;
+
+  public InvalidQueryException() {
+    super();
+  }
+
+	public InvalidQueryException(String message) {
+    super(message);
+  }
+	
+	public InvalidQueryException(Throwable t) {
+		super(t);
+	}
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/026368be/tajo-core/src/main/java/org/apache/tajo/engine/exception/NoSuchColumnException.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/exception/NoSuchColumnException.java b/tajo-core/src/main/java/org/apache/tajo/engine/exception/NoSuchColumnException.java
new file mode 100644
index 0000000..70191a9
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/exception/NoSuchColumnException.java
@@ -0,0 +1,25 @@
+/*
+ * 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.exception;
+
+public class NoSuchColumnException extends VerifyException {
+  public NoSuchColumnException(String columnName) {
+    super("ERROR: no such a column '" + columnName + "'");
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/026368be/tajo-core/src/main/java/org/apache/tajo/engine/exception/RangeOverflowException.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/exception/RangeOverflowException.java b/tajo-core/src/main/java/org/apache/tajo/engine/exception/RangeOverflowException.java
new file mode 100644
index 0000000..409d6ed
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/exception/RangeOverflowException.java
@@ -0,0 +1,28 @@
+/**
+ * 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.exception;
+
+import org.apache.tajo.storage.Tuple;
+import org.apache.tajo.storage.TupleRange;
+
+public class RangeOverflowException extends RuntimeException {
+  public RangeOverflowException(TupleRange range, Tuple overflowValue, long inc) {
+    super("Overflow Error: tried to increase " + inc + " to " + overflowValue + ", but the range " + range);
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/026368be/tajo-core/src/main/java/org/apache/tajo/engine/exception/VerifyException.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/exception/VerifyException.java b/tajo-core/src/main/java/org/apache/tajo/engine/exception/VerifyException.java
new file mode 100644
index 0000000..beda787
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/exception/VerifyException.java
@@ -0,0 +1,27 @@
+/**
+ * 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.exception;
+
+import org.apache.tajo.engine.planner.PlanningException;
+
+public class VerifyException extends PlanningException {
+  public VerifyException(String message) {
+    super(message);
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/026368be/tajo-core/src/main/java/org/apache/tajo/engine/function/AggFunction.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/function/AggFunction.java b/tajo-core/src/main/java/org/apache/tajo/engine/function/AggFunction.java
new file mode 100644
index 0000000..a5a2583
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/function/AggFunction.java
@@ -0,0 +1,58 @@
+/**
+ * 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.function;
+
+import org.apache.tajo.catalog.Column;
+import org.apache.tajo.catalog.function.Function;
+import org.apache.tajo.catalog.json.CatalogGsonHelper;
+import org.apache.tajo.catalog.proto.CatalogProtos;
+import org.apache.tajo.common.TajoDataTypes.DataType;
+import org.apache.tajo.datum.Datum;
+import org.apache.tajo.storage.Tuple;
+
+public abstract class AggFunction<T extends Datum> extends Function<T> {
+
+  public AggFunction(Column[] definedArgs) {
+    super(definedArgs);
+  }
+
+  public abstract FunctionContext newContext();
+
+  public abstract void eval(FunctionContext ctx, Tuple params);
+
+  public void merge(FunctionContext ctx, Tuple part) {
+    eval(ctx, part);
+  }
+
+  public abstract Datum getPartialResult(FunctionContext ctx);
+
+  public abstract DataType getPartialResultType();
+
+  public abstract T terminate(FunctionContext ctx);
+
+  @Override
+  public String toJson() {
+    return CatalogGsonHelper.toJson(this, AggFunction.class);
+  }
+
+  @Override
+  public CatalogProtos.FunctionType getFunctionType() {
+    return CatalogProtos.FunctionType.AGGREGATION;
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/026368be/tajo-core/src/main/java/org/apache/tajo/engine/function/FunctionContext.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/function/FunctionContext.java b/tajo-core/src/main/java/org/apache/tajo/engine/function/FunctionContext.java
new file mode 100644
index 0000000..076c8ec
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/function/FunctionContext.java
@@ -0,0 +1,22 @@
+/**
+ * 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.function;
+
+public interface FunctionContext {
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/026368be/tajo-core/src/main/java/org/apache/tajo/engine/function/GeneralFunction.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/function/GeneralFunction.java b/tajo-core/src/main/java/org/apache/tajo/engine/function/GeneralFunction.java
new file mode 100644
index 0000000..f7c31a1
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/function/GeneralFunction.java
@@ -0,0 +1,56 @@
+/**
+ * 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.function;
+
+import org.apache.tajo.catalog.Column;
+import org.apache.tajo.catalog.function.Function;
+import org.apache.tajo.catalog.json.CatalogGsonHelper;
+import org.apache.tajo.catalog.proto.CatalogProtos;
+import org.apache.tajo.datum.Datum;
+import org.apache.tajo.engine.eval.FunctionEval;
+import org.apache.tajo.json.GsonObject;
+import org.apache.tajo.storage.Tuple;
+
+public abstract class GeneralFunction extends Function implements GsonObject {
+  public GeneralFunction(Column[] definedArgs) {
+    super(definedArgs);
+  }
+
+  /**
+   * This method gives hints to an actual function instance.
+   */
+  public void init(FunctionEval.ParamType [] paramTypes) {}
+
+  public abstract Datum eval(Tuple params);
+
+	public enum Type {
+	  AGG,
+	  GENERAL
+	}
+
+  @Override
+  public String toJson() {
+    return CatalogGsonHelper.toJson(this, GeneralFunction.class);
+  }
+
+  @Override
+  public CatalogProtos.FunctionType getFunctionType() {
+    return CatalogProtos.FunctionType.GENERAL;
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tajo/blob/026368be/tajo-core/src/main/java/org/apache/tajo/engine/function/annotation/Description.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/function/annotation/Description.java b/tajo-core/src/main/java/org/apache/tajo/engine/function/annotation/Description.java
new file mode 100644
index 0000000..bc6c7a2
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/function/annotation/Description.java
@@ -0,0 +1,50 @@
+/**
+ * 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.function.annotation;
+
+import org.apache.tajo.common.TajoDataTypes.Type;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Description.
+ *
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+public @interface Description {
+
+  String description();
+
+  String detail() default "";
+
+  String example();
+
+  String functionName();
+
+  String[] synonyms() default {};
+
+  Type returnType();
+
+  ParamTypes[] paramTypes() default @ParamTypes;
+
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/026368be/tajo-core/src/main/java/org/apache/tajo/engine/function/annotation/ParamOptionTypes.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/function/annotation/ParamOptionTypes.java b/tajo-core/src/main/java/org/apache/tajo/engine/function/annotation/ParamOptionTypes.java
new file mode 100644
index 0000000..0ef7f4c
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/function/annotation/ParamOptionTypes.java
@@ -0,0 +1,29 @@
+/**
+ * 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.function.annotation;
+
+import org.apache.tajo.common.TajoDataTypes;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+@Retention(RetentionPolicy.RUNTIME)
+public @interface ParamOptionTypes {
+  TajoDataTypes.Type[] paramOptionTypes() default {};
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/026368be/tajo-core/src/main/java/org/apache/tajo/engine/function/annotation/ParamTypes.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/function/annotation/ParamTypes.java b/tajo-core/src/main/java/org/apache/tajo/engine/function/annotation/ParamTypes.java
new file mode 100644
index 0000000..ed2545c
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/function/annotation/ParamTypes.java
@@ -0,0 +1,30 @@
+/**
+ * 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.function.annotation;
+
+import org.apache.tajo.common.TajoDataTypes.Type;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+@Retention(RetentionPolicy.RUNTIME)
+public @interface ParamTypes {
+  Type[] paramTypes() default { Type.NULL_TYPE };
+  ParamOptionTypes[] paramOptionTypes() default {};
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tajo/blob/026368be/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/AvgDouble.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/AvgDouble.java b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/AvgDouble.java
new file mode 100644
index 0000000..df5cc80
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/AvgDouble.java
@@ -0,0 +1,97 @@
+/**
+ * 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.function.builtin;
+
+import org.apache.tajo.catalog.CatalogUtil;
+import org.apache.tajo.catalog.Column;
+import org.apache.tajo.common.TajoDataTypes.DataType;
+import org.apache.tajo.common.TajoDataTypes.Type;
+import org.apache.tajo.datum.Datum;
+import org.apache.tajo.datum.DatumFactory;
+import org.apache.tajo.datum.ProtobufDatum;
+import org.apache.tajo.engine.function.AggFunction;
+import org.apache.tajo.engine.function.FunctionContext;
+import org.apache.tajo.engine.function.annotation.Description;
+import org.apache.tajo.engine.function.annotation.ParamTypes;
+import org.apache.tajo.storage.Tuple;
+
+import static org.apache.tajo.InternalTypes.AvgDoubleProto;
+
+@Description(
+  functionName = "avg",
+  description = "The mean of a set of numbers.",
+  example = "> SELECT avg(expr);",
+  returnType = Type.FLOAT8,
+  paramTypes = {@ParamTypes(paramTypes = {Type.FLOAT8})}
+)
+public class AvgDouble extends AggFunction {
+  public AvgDouble() {
+    super(new Column[] {
+        new Column("expr", Type.FLOAT8)
+    });
+  }
+
+  public AvgContext newContext() {
+    return new AvgContext();
+  }
+
+  public void init() {
+  }
+
+  @Override
+  public void eval(FunctionContext ctx, Tuple params) {
+    AvgContext avgCtx = (AvgContext) ctx;
+    avgCtx.sum += params.get(0).asFloat8();
+    avgCtx.count++;
+  }
+
+  @Override
+  public void merge(FunctionContext ctx, Tuple part) {
+    AvgContext avgCtx = (AvgContext) ctx;
+    ProtobufDatum datum = (ProtobufDatum) part.get(0);
+    AvgDoubleProto proto = (AvgDoubleProto) datum.get();
+    avgCtx.sum += proto.getSum();
+    avgCtx.count += proto.getCount();
+  }
+
+  @Override
+  public Datum getPartialResult(FunctionContext ctx) {
+    AvgContext avgCtx = (AvgContext) ctx;
+    AvgDoubleProto.Builder builder = AvgDoubleProto.newBuilder();
+    builder.setSum(avgCtx.sum);
+    builder.setCount(avgCtx.count);
+    return new ProtobufDatum(builder.build());
+  }
+
+  @Override
+  public DataType getPartialResultType() {
+    return CatalogUtil.newDataType(Type.PROTOBUF, AvgDoubleProto.class.getName());
+  }
+
+  @Override
+  public Datum terminate(FunctionContext ctx) {
+    AvgContext avgCtx = (AvgContext) ctx;
+    return DatumFactory.createFloat8(avgCtx.sum / avgCtx.count);
+  }
+
+  protected class AvgContext implements FunctionContext {
+    double sum;
+    long count;
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/026368be/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/AvgFloat.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/AvgFloat.java b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/AvgFloat.java
new file mode 100644
index 0000000..4a30036
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/AvgFloat.java
@@ -0,0 +1,46 @@
+/**
+ * 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.function.builtin;
+
+import org.apache.tajo.common.TajoDataTypes;
+import org.apache.tajo.engine.function.FunctionContext;
+import org.apache.tajo.engine.function.annotation.Description;
+import org.apache.tajo.engine.function.annotation.ParamTypes;
+import org.apache.tajo.storage.Tuple;
+
+@Description(
+  functionName = "avg",
+  description = "The mean of a set of numbers.",
+  example = "> SELECT avg(expr);",
+  returnType = TajoDataTypes.Type.FLOAT8,
+  paramTypes = {@ParamTypes(paramTypes = {TajoDataTypes.Type.FLOAT4})}
+)
+public class AvgFloat extends AvgDouble {
+
+  public AvgFloat() {
+  }
+
+  @Override
+  public void eval(FunctionContext ctx, Tuple params) {
+    AvgContext avgCtx = (AvgContext) ctx;
+    avgCtx.sum += params.get(0).asFloat4();
+    avgCtx.count++;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/026368be/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/AvgInt.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/AvgInt.java b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/AvgInt.java
new file mode 100644
index 0000000..3c59f13
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/AvgInt.java
@@ -0,0 +1,47 @@
+/**
+ * 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.function.builtin;
+
+import org.apache.tajo.common.TajoDataTypes;
+import org.apache.tajo.engine.function.FunctionContext;
+import org.apache.tajo.engine.function.annotation.Description;
+import org.apache.tajo.engine.function.annotation.ParamTypes;
+import org.apache.tajo.storage.Tuple;
+
+@Description(
+  functionName = "avg",
+  description = "the mean of a set of numbers.",
+  example = "> SELECT avg(expr);",
+  returnType = TajoDataTypes.Type.FLOAT8,
+  paramTypes = {@ParamTypes(paramTypes = {TajoDataTypes.Type.INT4})}
+)
+public class AvgInt extends AvgLong {
+
+  public AvgInt() {
+    super();
+  }
+
+  @Override
+  public void eval(FunctionContext ctx, Tuple params) {
+    AvgContext avgCtx = (AvgContext) ctx;
+    avgCtx.sum += params.get(0).asInt4();
+    avgCtx.count++;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/026368be/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/AvgLong.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/AvgLong.java b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/AvgLong.java
new file mode 100644
index 0000000..5bb5ff9
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/AvgLong.java
@@ -0,0 +1,96 @@
+/**
+ * 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.function.builtin;
+
+import org.apache.tajo.catalog.CatalogUtil;
+import org.apache.tajo.catalog.Column;
+import org.apache.tajo.common.TajoDataTypes.DataType;
+import org.apache.tajo.common.TajoDataTypes.Type;
+import org.apache.tajo.datum.Datum;
+import org.apache.tajo.datum.DatumFactory;
+import org.apache.tajo.datum.Float8Datum;
+import org.apache.tajo.datum.ProtobufDatum;
+import org.apache.tajo.engine.function.AggFunction;
+import org.apache.tajo.engine.function.FunctionContext;
+import org.apache.tajo.engine.function.annotation.Description;
+import org.apache.tajo.engine.function.annotation.ParamTypes;
+import org.apache.tajo.storage.Tuple;
+
+import static org.apache.tajo.InternalTypes.AvgLongProto;
+
+@Description(
+  functionName = "avg",
+  description = "the mean of a set of numbers",
+  example = "> SELECT avg(expr);",
+  returnType = Type.FLOAT8,
+  paramTypes = {@ParamTypes(paramTypes = {Type.INT8})}
+)
+public class AvgLong extends AggFunction<Float8Datum> {
+
+  public AvgLong() {
+    super(new Column[] {
+        new Column("expr", Type.FLOAT8)
+    });
+  }
+
+  public AvgContext newContext() {
+    return new AvgContext();
+  }
+
+  @Override
+  public void eval(FunctionContext ctx, Tuple params) {
+    AvgContext avgCtx = (AvgContext) ctx;
+    avgCtx.sum += params.get(0).asInt8();
+    avgCtx.count++;
+  }
+
+  @Override
+  public void merge(FunctionContext ctx, Tuple part) {
+    AvgContext avgCtx = (AvgContext) ctx;
+    ProtobufDatum datum = (ProtobufDatum) part.get(0);
+    AvgLongProto proto = (AvgLongProto) datum.get();
+    avgCtx.sum += proto.getSum();
+    avgCtx.count += proto.getCount();
+  }
+
+  @Override
+  public Datum getPartialResult(FunctionContext ctx) {
+    AvgContext avgCtx = (AvgContext) ctx;
+    AvgLongProto.Builder builder = AvgLongProto.newBuilder();
+    builder.setSum(avgCtx.sum);
+    builder.setCount(avgCtx.count);
+    return new ProtobufDatum(builder.build());
+  }
+
+  @Override
+  public DataType getPartialResultType() {
+    return CatalogUtil.newDataType(Type.PROTOBUF, AvgLongProto.class.getName());
+  }
+
+  @Override
+  public Float8Datum terminate(FunctionContext ctx) {
+    AvgContext avgCtx = (AvgContext) ctx;
+    return DatumFactory.createFloat8((double) avgCtx.sum / avgCtx.count);
+  }
+
+  protected class AvgContext implements FunctionContext {
+    long sum;
+    long count;
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/026368be/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/Coalesce.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/Coalesce.java b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/Coalesce.java
new file mode 100644
index 0000000..98abb02
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/Coalesce.java
@@ -0,0 +1,44 @@
+/**
+ * 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.function.builtin;
+
+import org.apache.tajo.catalog.Column;
+import org.apache.tajo.datum.Datum;
+import org.apache.tajo.datum.NullDatum;
+import org.apache.tajo.engine.function.GeneralFunction;
+import org.apache.tajo.storage.Tuple;
+
+public abstract class Coalesce extends GeneralFunction {
+  public Coalesce(Column[] definedArgs) {
+    super(definedArgs);
+  }
+
+  @Override
+  public Datum eval(Tuple params) {
+    int paramSize = params.size();
+    for (int i = 0; i < paramSize; i++) {
+      Datum datum = params.get(i);
+      if (datum instanceof NullDatum) {
+        continue;
+      }
+      return datum;
+    }
+    return NullDatum.get();
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/026368be/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/CoalesceDouble.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/CoalesceDouble.java b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/CoalesceDouble.java
new file mode 100644
index 0000000..3e94150
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/CoalesceDouble.java
@@ -0,0 +1,43 @@
+/**
+ * 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.function.builtin;
+
+import org.apache.tajo.catalog.Column;
+import org.apache.tajo.common.TajoDataTypes;
+import org.apache.tajo.engine.function.annotation.Description;
+import org.apache.tajo.engine.function.annotation.ParamTypes;
+
+@Description(
+    functionName = "coalesce",
+    description = "Returns the first of its arguments that is not null.",
+    detail = "Like a CASE expression, COALESCE only evaluates the arguments that are needed to determine the result; " +
+        "that is, arguments to the right of the first non-null argument are not evaluated",
+    example = "> SELECT coalesce(null, null, 10.0);\n"
+        + "10.0",
+    returnType = TajoDataTypes.Type.FLOAT8,
+    paramTypes = {@ParamTypes(paramTypes = {TajoDataTypes.Type.FLOAT8, TajoDataTypes.Type.FLOAT8_ARRAY})}
+)
+public class CoalesceDouble extends Coalesce {
+  public CoalesceDouble() {
+    super(new Column[] {
+        new Column("column", TajoDataTypes.Type.FLOAT8),
+        new Column("params", TajoDataTypes.Type.FLOAT8_ARRAY),
+    });
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/026368be/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/CoalesceLong.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/CoalesceLong.java b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/CoalesceLong.java
new file mode 100644
index 0000000..5d55255
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/CoalesceLong.java
@@ -0,0 +1,44 @@
+/**
+ * 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.function.builtin;
+
+import org.apache.tajo.catalog.Column;
+import org.apache.tajo.common.TajoDataTypes;
+import org.apache.tajo.engine.function.annotation.Description;
+import org.apache.tajo.engine.function.annotation.ParamTypes;
+
+@Description(
+    functionName = "coalesce",
+    description = "Returns the first of its arguments that is not null.",
+    detail = "Like a CASE expression, COALESCE only evaluates the arguments that are needed to determine the result; " +
+        "that is, arguments to the right of the first non-null argument are not evaluated",
+    example = "> SELECT coalesce(null, null, 10);\n"
+        + "10",
+    returnType = TajoDataTypes.Type.INT8,
+    paramTypes = {@ParamTypes(paramTypes = {TajoDataTypes.Type.INT8, TajoDataTypes.Type.INT8_ARRAY})}
+)
+public class CoalesceLong extends Coalesce {
+
+  public CoalesceLong() {
+    super(new Column[] {
+        new Column("column", TajoDataTypes.Type.INT8),
+        new Column("params", TajoDataTypes.Type.INT8_ARRAY),
+    });
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tajo/blob/026368be/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/CoalesceString.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/CoalesceString.java b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/CoalesceString.java
new file mode 100644
index 0000000..50e4786
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/CoalesceString.java
@@ -0,0 +1,44 @@
+/**
+ * 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.function.builtin;
+
+import org.apache.tajo.catalog.Column;
+import org.apache.tajo.common.TajoDataTypes;
+import org.apache.tajo.engine.function.annotation.Description;
+import org.apache.tajo.engine.function.annotation.ParamTypes;
+
+@Description(
+    functionName = "coalesce",
+    description = "Returns the first of its arguments that is not null.",
+    detail = "Like a CASE expression, COALESCE only evaluates the arguments that are needed to determine the result; " +
+        "that is, arguments to the right of the first non-null argument are not evaluated",
+    example = "> SELECT coalesce(null, null, 'default');\n"
+        + "default",
+    returnType = TajoDataTypes.Type.TEXT,
+    paramTypes = {@ParamTypes(paramTypes = {TajoDataTypes.Type.TEXT, TajoDataTypes.Type.TEXT_ARRAY})}
+)
+public class CoalesceString extends Coalesce {
+
+  public CoalesceString() {
+    super(new Column[] {
+        new Column("column", TajoDataTypes.Type.TEXT),
+        new Column("params", TajoDataTypes.Type.TEXT_ARRAY),
+    });
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/026368be/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/CountRows.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/CountRows.java b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/CountRows.java
new file mode 100644
index 0000000..aa1d941
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/CountRows.java
@@ -0,0 +1,84 @@
+/**
+ * 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.function.builtin;
+
+import org.apache.tajo.catalog.CatalogUtil;
+import org.apache.tajo.catalog.Column;
+import org.apache.tajo.common.TajoDataTypes.DataType;
+import org.apache.tajo.common.TajoDataTypes.Type;
+import org.apache.tajo.datum.Datum;
+import org.apache.tajo.datum.DatumFactory;
+import org.apache.tajo.datum.Int8Datum;
+import org.apache.tajo.engine.function.AggFunction;
+import org.apache.tajo.engine.function.FunctionContext;
+import org.apache.tajo.engine.function.annotation.Description;
+import org.apache.tajo.engine.function.annotation.ParamTypes;
+import org.apache.tajo.storage.Tuple;
+
+@Description(
+  functionName = "count",
+  description = "the total number of retrieved rows",
+  example = "> SELECT count(*);",
+  returnType = Type.INT8,
+  paramTypes = {@ParamTypes(paramTypes = {})}
+)
+public class CountRows extends AggFunction<Datum> {
+
+  public CountRows() {
+    super(NoArgs);
+  }
+
+  protected CountRows(Column[] columns) {
+    super(columns);
+  }
+
+  @Override
+  public FunctionContext newContext() {
+    return new CountRowContext();
+  }
+
+  @Override
+  public void eval(FunctionContext ctx, Tuple params) {
+    ((CountRowContext) ctx).count++;
+  }
+
+  @Override
+  public void merge(FunctionContext ctx, Tuple part) {
+    ((CountRowContext) ctx).count += part.get(0).asInt8();
+  }
+
+  @Override
+  public Datum getPartialResult(FunctionContext ctx) {
+    return DatumFactory.createInt8(((CountRowContext) ctx).count);
+  }
+
+  @Override
+  public DataType getPartialResultType() {
+    return CatalogUtil.newSimpleDataType(Type.INT8);
+  }
+
+  @Override
+  public Int8Datum terminate(FunctionContext ctx) {
+    return DatumFactory.createInt8(((CountRowContext) ctx).count);
+  }
+
+  protected class CountRowContext implements FunctionContext {
+    long count;
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/026368be/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/CountValue.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/CountValue.java b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/CountValue.java
new file mode 100644
index 0000000..12d8892
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/CountValue.java
@@ -0,0 +1,55 @@
+/**
+ * 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.function.builtin;
+
+import org.apache.tajo.catalog.Column;
+import org.apache.tajo.common.TajoDataTypes.Type;
+import org.apache.tajo.datum.NullDatum;
+import org.apache.tajo.engine.function.FunctionContext;
+import org.apache.tajo.engine.function.annotation.Description;
+import org.apache.tajo.engine.function.annotation.ParamTypes;
+import org.apache.tajo.storage.Tuple;
+
+/**
+ * Count(column) function
+ */
+@Description(
+  functionName = "count",
+  description = "The number of retrieved rows for "
+          + "which the supplied expressions are non-NULL",
+  example = "> SELECT count(expr);",
+  returnType = Type.INT8,
+  paramTypes = {@ParamTypes(paramTypes = {Type.ANY})}
+)
+public final class CountValue extends CountRows {
+
+  public CountValue() {
+    super(new Column[] {
+        new Column("expr", Type.ANY)
+    });
+  }
+
+  @Override
+  public void eval(FunctionContext ctx, Tuple params) {
+    if (!(params.get(0) instanceof NullDatum)) {
+      ((CountRowContext) ctx).count++;
+    }
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/026368be/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/CountValueDistinct.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/CountValueDistinct.java b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/CountValueDistinct.java
new file mode 100644
index 0000000..c0f5ec3
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/CountValueDistinct.java
@@ -0,0 +1,90 @@
+/**
+ * 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.function.builtin;
+
+import org.apache.tajo.catalog.Column;
+import org.apache.tajo.catalog.proto.CatalogProtos;
+import org.apache.tajo.common.TajoDataTypes.Type;
+import org.apache.tajo.datum.Datum;
+import org.apache.tajo.datum.DatumFactory;
+import org.apache.tajo.datum.Int8Datum;
+import org.apache.tajo.datum.NullDatum;
+import org.apache.tajo.engine.function.FunctionContext;
+import org.apache.tajo.engine.function.annotation.Description;
+import org.apache.tajo.engine.function.annotation.ParamTypes;
+import org.apache.tajo.storage.Tuple;
+
+/**
+ * Count(distinct column) function
+ */
+@Description(
+  functionName = "count",
+  description = " The number of rows for "
+          + "which the supplied expressions are unique and non-NULL.",
+  example = "> SELECT count(expr);",
+  returnType = Type.INT8,
+  paramTypes = {@ParamTypes(paramTypes = {Type.ANY})}
+)
+public final class CountValueDistinct extends CountRows {
+
+  public CountValueDistinct() {
+    super(new Column[] {
+        new Column("expr", Type.ANY)
+    });
+  }
+
+  @Override
+  public void eval(FunctionContext context, Tuple params) {
+  }
+
+  @Override
+  public void merge(FunctionContext context, Tuple part) {
+    CountDistinctValueContext distinctContext = (CountDistinctValueContext) context;
+    Datum value = part.get(0);
+    if ((distinctContext.latest == null || (!distinctContext.latest.equals(value)) && !(value instanceof NullDatum))) {
+      distinctContext.latest = value;
+      distinctContext.count++;
+    }
+  }
+
+  @Override
+  public Datum getPartialResult(FunctionContext ctx) {
+    return DatumFactory.createInt8(((CountDistinctValueContext) ctx).count);
+  }
+
+  @Override
+  public Int8Datum terminate(FunctionContext ctx) {
+    return DatumFactory.createInt8(((CountDistinctValueContext) ctx).count);
+  }
+
+  @Override
+  public FunctionContext newContext() {
+    return new CountDistinctValueContext();
+  }
+
+  private class CountDistinctValueContext implements FunctionContext {
+    long count = 0;
+    Datum latest = null;
+  }
+
+  @Override
+  public CatalogProtos.FunctionType getFunctionType() {
+    return CatalogProtos.FunctionType.DISTINCT_AGGREGATION;
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/026368be/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/Date.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/Date.java b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/Date.java
new file mode 100644
index 0000000..7666e89
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/Date.java
@@ -0,0 +1,62 @@
+/**
+ * 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.function.builtin;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.tajo.catalog.Column;
+import org.apache.tajo.common.TajoDataTypes;
+import org.apache.tajo.datum.DatumFactory;
+import org.apache.tajo.datum.Int8Datum;
+import org.apache.tajo.engine.function.GeneralFunction;
+import org.apache.tajo.engine.function.annotation.Description;
+import org.apache.tajo.engine.function.annotation.ParamTypes;
+import org.apache.tajo.storage.Tuple;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+
+import static org.apache.tajo.common.TajoDataTypes.Type.TEXT;
+
+@Description(
+  functionName = "date",
+  description = "Extracts the date part of the date or datetime expression expr.",
+  example = "> SELECT date(expr);",
+  returnType = TajoDataTypes.Type.INT8,
+  paramTypes = {@ParamTypes(paramTypes = {TajoDataTypes.Type.INT4})}
+)
+public class Date extends GeneralFunction {
+  private final Log LOG = LogFactory.getLog(Date.class);
+  private final static String dateFormat = "dd/MM/yyyy HH:mm:ss";
+
+  public Date() {
+    super(new Column[] {new Column("expr", TEXT)});
+  }
+
+  @Override
+  public Int8Datum eval(Tuple params) {
+    try {
+      return DatumFactory.createInt8(new SimpleDateFormat(dateFormat)
+          .parse(params.get(0).asChars()).getTime());
+    } catch (ParseException e) {
+      LOG.error(e);
+      return null;
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/026368be/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MaxDouble.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MaxDouble.java b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MaxDouble.java
new file mode 100644
index 0000000..5c9ceb1
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MaxDouble.java
@@ -0,0 +1,78 @@
+/**
+ * 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.function.builtin;
+
+import org.apache.tajo.catalog.CatalogUtil;
+import org.apache.tajo.catalog.Column;
+import org.apache.tajo.common.TajoDataTypes.DataType;
+import org.apache.tajo.common.TajoDataTypes.Type;
+import org.apache.tajo.datum.Datum;
+import org.apache.tajo.datum.DatumFactory;
+import org.apache.tajo.datum.Float8Datum;
+import org.apache.tajo.engine.function.AggFunction;
+import org.apache.tajo.engine.function.FunctionContext;
+import org.apache.tajo.engine.function.annotation.Description;
+import org.apache.tajo.engine.function.annotation.ParamTypes;
+import org.apache.tajo.storage.Tuple;
+
+@Description(
+  functionName = "max",
+  description = "the maximum value of expr",
+  example = "> SELECT max(expr);",
+  returnType = Type.FLOAT8,
+  paramTypes = {@ParamTypes(paramTypes = {Type.FLOAT8})}
+)
+public class MaxDouble extends AggFunction<Float8Datum> {
+
+  public MaxDouble() {
+    super(new Column[] {
+        new Column("expr", Type.FLOAT8)
+    });
+  }
+
+  @Override
+  public FunctionContext newContext() {
+    return new MaxContext();
+  }
+
+  @Override
+  public void eval(FunctionContext ctx, Tuple params) {
+    MaxContext maxCtx = (MaxContext) ctx;
+    maxCtx.max = Math.max(maxCtx.max, params.get(0).asFloat8());
+  }
+
+  @Override
+  public Datum getPartialResult(FunctionContext ctx) {
+    return DatumFactory.createFloat8(((MaxContext) ctx).max);
+  }
+
+  @Override
+  public DataType getPartialResultType() {
+    return CatalogUtil.newSimpleDataType(Type.FLOAT8);
+  }
+
+  @Override
+  public Float8Datum terminate(FunctionContext ctx) {
+    return DatumFactory.createFloat8(((MaxContext) ctx).max);
+  }
+
+  private class MaxContext implements FunctionContext {
+    double max;
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/026368be/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MaxFloat.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MaxFloat.java b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MaxFloat.java
new file mode 100644
index 0000000..067026d
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MaxFloat.java
@@ -0,0 +1,76 @@
+/**
+ * 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.function.builtin;
+
+import org.apache.tajo.catalog.CatalogUtil;
+import org.apache.tajo.catalog.Column;
+import org.apache.tajo.common.TajoDataTypes.DataType;
+import org.apache.tajo.common.TajoDataTypes.Type;
+import org.apache.tajo.datum.Datum;
+import org.apache.tajo.datum.DatumFactory;
+import org.apache.tajo.engine.function.AggFunction;
+import org.apache.tajo.engine.function.FunctionContext;
+import org.apache.tajo.engine.function.annotation.Description;
+import org.apache.tajo.engine.function.annotation.ParamTypes;
+import org.apache.tajo.storage.Tuple;
+
+@Description(
+  functionName = "max",
+  description = "the maximum value of expr",
+  example = "> SELECT max(expr);",
+  returnType = Type.FLOAT4,
+  paramTypes = {@ParamTypes(paramTypes = {Type.FLOAT4})}
+)
+public class MaxFloat extends AggFunction<Datum> {
+  public MaxFloat() {
+    super(new Column[] {
+        new Column("expr", Type.FLOAT8)
+    });
+  }
+
+  @Override
+  public FunctionContext newContext() {
+    return new MaxContext();
+  }
+
+  @Override
+  public void eval(FunctionContext ctx, Tuple params) {
+    MaxContext maxCtx = (MaxContext) ctx;
+    maxCtx.max = Math.max(maxCtx.max, params.get(0).asFloat4());
+  }
+
+  @Override
+  public Datum getPartialResult(FunctionContext ctx) {
+    return DatumFactory.createFloat4(((MaxContext) ctx).max);
+  }
+
+  @Override
+  public DataType getPartialResultType() {
+    return CatalogUtil.newSimpleDataType(Type.FLOAT4);
+  }
+
+  @Override
+  public Datum terminate(FunctionContext ctx) {
+    return DatumFactory.createFloat4(((MaxContext) ctx).max);
+  }
+
+  private class MaxContext implements FunctionContext {
+    float max;
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/026368be/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MaxInt.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MaxInt.java b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MaxInt.java
new file mode 100644
index 0000000..a329390
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MaxInt.java
@@ -0,0 +1,77 @@
+/**
+ * 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.function.builtin;
+
+import org.apache.tajo.catalog.CatalogUtil;
+import org.apache.tajo.catalog.Column;
+import org.apache.tajo.common.TajoDataTypes.DataType;
+import org.apache.tajo.common.TajoDataTypes.Type;
+import org.apache.tajo.datum.Datum;
+import org.apache.tajo.datum.DatumFactory;
+import org.apache.tajo.engine.function.AggFunction;
+import org.apache.tajo.engine.function.FunctionContext;
+import org.apache.tajo.engine.function.annotation.Description;
+import org.apache.tajo.engine.function.annotation.ParamTypes;
+import org.apache.tajo.storage.Tuple;
+
+@Description(
+  functionName = "max",
+  description = "the maximum value of expr",
+  example = "> SELECT max(expr);",
+  returnType = Type.INT4,
+  paramTypes = {@ParamTypes(paramTypes = {Type.INT4})}
+)
+public class MaxInt extends AggFunction<Datum> {
+
+  public MaxInt() {
+    super(new Column[] {
+        new Column("expr", Type.INT8)
+    });
+  }
+
+  @Override
+  public FunctionContext newContext() {
+    return new MaxContext();
+  }
+
+  @Override
+  public void eval(FunctionContext ctx, Tuple params) {
+    MaxContext maxCtx = (MaxContext) ctx;
+    maxCtx.max = Math.max(maxCtx.max, params.get(0).asInt4());
+  }
+
+  @Override
+  public Datum getPartialResult(FunctionContext ctx) {
+    return DatumFactory.createInt4(((MaxContext) ctx).max);
+  }
+
+  @Override
+  public DataType getPartialResultType() {
+    return CatalogUtil.newSimpleDataType(Type.INT4);
+  }
+
+  @Override
+  public Datum terminate(FunctionContext ctx) {
+    return DatumFactory.createInt4(((MaxContext) ctx).max);
+  }
+
+  private class MaxContext implements FunctionContext {
+    int max;
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/026368be/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MaxLong.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MaxLong.java b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MaxLong.java
new file mode 100644
index 0000000..71bab1a
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MaxLong.java
@@ -0,0 +1,77 @@
+/**
+ * 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.function.builtin;
+
+import org.apache.tajo.catalog.CatalogUtil;
+import org.apache.tajo.catalog.Column;
+import org.apache.tajo.common.TajoDataTypes.DataType;
+import org.apache.tajo.common.TajoDataTypes.Type;
+import org.apache.tajo.datum.Datum;
+import org.apache.tajo.datum.DatumFactory;
+import org.apache.tajo.datum.Int8Datum;
+import org.apache.tajo.engine.function.AggFunction;
+import org.apache.tajo.engine.function.FunctionContext;
+import org.apache.tajo.engine.function.annotation.Description;
+import org.apache.tajo.engine.function.annotation.ParamTypes;
+import org.apache.tajo.storage.Tuple;
+
+@Description(
+  functionName = "max",
+  description = "the maximum value of expr",
+  example = "> SELECT max(expr);",
+  returnType = Type.INT8,
+  paramTypes = {@ParamTypes(paramTypes = {Type.INT8})}
+)
+public class MaxLong extends AggFunction<Int8Datum> {
+  public MaxLong() {
+    super(new Column[] {
+        new Column("expr", Type.INT8)
+    });
+  }
+
+  @Override
+  public FunctionContext newContext() {
+    return new MaxContext();
+  }
+
+  @Override
+  public void eval(FunctionContext ctx, Tuple params) {
+    MaxContext maxCtx = (MaxContext) ctx;
+    maxCtx.max = Math.max(maxCtx.max, params.get(0).asInt8());
+  }
+
+  @Override
+  public Datum getPartialResult(FunctionContext ctx) {
+    return DatumFactory.createInt8(((MaxContext) ctx).max);
+  }
+
+  @Override
+  public DataType getPartialResultType() {
+    return CatalogUtil.newSimpleDataType(Type.INT8);
+  }
+
+  @Override
+  public Int8Datum terminate(FunctionContext ctx) {
+    return DatumFactory.createInt8(((MaxContext) ctx).max);
+  }
+
+  private class MaxContext implements FunctionContext {
+    long max;
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/026368be/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MaxString.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MaxString.java b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MaxString.java
new file mode 100644
index 0000000..439462f
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MaxString.java
@@ -0,0 +1,81 @@
+/**
+ * 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.function.builtin;
+
+import org.apache.tajo.catalog.CatalogUtil;
+import org.apache.tajo.catalog.Column;
+import org.apache.tajo.common.TajoDataTypes;
+import org.apache.tajo.datum.Datum;
+import org.apache.tajo.datum.DatumFactory;
+import org.apache.tajo.datum.TextDatum;
+import org.apache.tajo.engine.function.AggFunction;
+import org.apache.tajo.engine.function.FunctionContext;
+import org.apache.tajo.engine.function.annotation.Description;
+import org.apache.tajo.engine.function.annotation.ParamTypes;
+import org.apache.tajo.storage.Tuple;
+
+@Description(
+    functionName = "max",
+    description = "the maximum value of expr",
+    example = "> SELECT max(expr);",
+    returnType = TajoDataTypes.Type.TEXT,
+    paramTypes = {@ParamTypes(paramTypes = {TajoDataTypes.Type.TEXT})}
+)
+public class MaxString  extends AggFunction<Datum> {
+
+  public MaxString() {
+    super(new Column[] {
+        new Column("expr", TajoDataTypes.Type.TEXT)
+    });
+  }
+
+  @Override
+  public FunctionContext newContext() {
+    return new MaxContext();
+  }
+
+  @Override
+  public void eval(FunctionContext ctx, Tuple params) {
+    MaxContext maxCtx = (MaxContext) ctx;
+    if (maxCtx.max == null) {
+      maxCtx.max = params.get(0).asChars();
+    } else if (params.get(0).asChars().compareTo(maxCtx.max) > 0) {
+      maxCtx.max = params.get(0).asChars();
+    }
+  }
+
+  @Override
+  public Datum getPartialResult(FunctionContext ctx) {
+    return DatumFactory.createText(((MaxContext) ctx).max);
+  }
+
+  @Override
+  public TajoDataTypes.DataType getPartialResultType() {
+    return CatalogUtil.newSimpleDataType(TajoDataTypes.Type.TEXT);
+  }
+
+  @Override
+  public TextDatum terminate(FunctionContext ctx) {
+    return DatumFactory.createText(((MaxContext) ctx).max);
+  }
+
+  private class MaxContext implements FunctionContext {
+    String max;
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tajo/blob/026368be/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MinDouble.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MinDouble.java b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MinDouble.java
new file mode 100644
index 0000000..7b9e0ab
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MinDouble.java
@@ -0,0 +1,77 @@
+/**
+ * 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.function.builtin;
+
+import org.apache.tajo.catalog.CatalogUtil;
+import org.apache.tajo.catalog.Column;
+import org.apache.tajo.common.TajoDataTypes.DataType;
+import org.apache.tajo.common.TajoDataTypes.Type;
+import org.apache.tajo.datum.Datum;
+import org.apache.tajo.datum.DatumFactory;
+import org.apache.tajo.engine.function.AggFunction;
+import org.apache.tajo.engine.function.FunctionContext;
+import org.apache.tajo.engine.function.annotation.Description;
+import org.apache.tajo.engine.function.annotation.ParamTypes;
+import org.apache.tajo.storage.Tuple;
+
+@Description(
+  functionName = "min",
+  description = "the minimum value of expr",
+  example = "> SELECT min(expr);",
+  returnType = Type.FLOAT8,
+  paramTypes = {@ParamTypes(paramTypes = {Type.FLOAT8})}
+)
+public class MinDouble extends AggFunction<Datum> {
+
+  public MinDouble() {
+    super(new Column[] {
+        new Column("expr", Type.FLOAT8)
+    });
+  }
+
+  @Override
+  public FunctionContext newContext() {
+    return new MinContext();
+  }
+
+  @Override
+  public void eval(FunctionContext ctx, Tuple params) {
+    MinContext minCtx = (MinContext) ctx;
+    minCtx.min = Math.min(minCtx.min, params.get(0).asFloat8());
+  }
+
+  @Override
+  public Datum getPartialResult(FunctionContext ctx) {
+    return DatumFactory.createFloat8(((MinContext) ctx).min);
+  }
+
+  @Override
+  public DataType getPartialResultType() {
+    return CatalogUtil.newSimpleDataType(Type.FLOAT8);
+  }
+
+  @Override
+  public Datum terminate(FunctionContext ctx) {
+    return DatumFactory.createFloat8(((MinContext) ctx).min);
+  }
+
+  private class MinContext implements FunctionContext {
+    double min = Double.MAX_VALUE;
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/026368be/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MinFloat.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MinFloat.java b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MinFloat.java
new file mode 100644
index 0000000..95a97be
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MinFloat.java
@@ -0,0 +1,78 @@
+/**
+ * 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.function.builtin;
+
+import org.apache.tajo.catalog.CatalogUtil;
+import org.apache.tajo.catalog.Column;
+import org.apache.tajo.common.TajoDataTypes.DataType;
+import org.apache.tajo.common.TajoDataTypes.Type;
+import org.apache.tajo.datum.Datum;
+import org.apache.tajo.datum.DatumFactory;
+import org.apache.tajo.datum.Float4Datum;
+import org.apache.tajo.engine.function.AggFunction;
+import org.apache.tajo.engine.function.FunctionContext;
+import org.apache.tajo.engine.function.annotation.Description;
+import org.apache.tajo.engine.function.annotation.ParamTypes;
+import org.apache.tajo.storage.Tuple;
+
+@Description(
+  functionName = "min",
+  description = "the minimum value of expr",
+  example = "> SELECT min(expr);",
+  returnType = Type.FLOAT4,
+  paramTypes = {@ParamTypes(paramTypes = {Type.FLOAT4})}
+)
+public class MinFloat extends AggFunction<Float4Datum> {
+
+  public MinFloat() {
+    super(new Column[] {
+        new Column("expr", Type.FLOAT4)
+    });
+  }
+
+  @Override
+  public FunctionContext newContext() {
+    return new MinContext();
+  }
+
+  @Override
+  public void eval(FunctionContext ctx, Tuple params) {
+    MinContext minCtx = (MinContext) ctx;
+    minCtx.min = Math.min(minCtx.min, params.get(0).asFloat4());
+  }
+
+  @Override
+  public Datum getPartialResult(FunctionContext ctx) {
+    return DatumFactory.createFloat4(((MinContext) ctx).min);
+  }
+
+  @Override
+  public DataType getPartialResultType() {
+    return CatalogUtil.newSimpleDataType(Type.FLOAT4);
+  }
+
+  @Override
+  public Float4Datum terminate(FunctionContext ctx) {
+    return DatumFactory.createFloat4(((MinContext) ctx).min);
+  }
+
+  private class MinContext implements FunctionContext {
+    float min = Float.MAX_VALUE;
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/026368be/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MinInt.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MinInt.java b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MinInt.java
new file mode 100644
index 0000000..24b379a
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MinInt.java
@@ -0,0 +1,77 @@
+/**
+ * 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.function.builtin;
+
+import org.apache.tajo.catalog.CatalogUtil;
+import org.apache.tajo.catalog.Column;
+import org.apache.tajo.common.TajoDataTypes.DataType;
+import org.apache.tajo.common.TajoDataTypes.Type;
+import org.apache.tajo.datum.Datum;
+import org.apache.tajo.datum.DatumFactory;
+import org.apache.tajo.engine.function.AggFunction;
+import org.apache.tajo.engine.function.FunctionContext;
+import org.apache.tajo.engine.function.annotation.Description;
+import org.apache.tajo.engine.function.annotation.ParamTypes;
+import org.apache.tajo.storage.Tuple;
+
+@Description(
+  functionName = "min",
+  description = "the minimum value of expr",
+  example = "> SELECT min(expr);",
+  returnType = Type.INT4,
+  paramTypes = {@ParamTypes(paramTypes = {Type.INT4})}
+)
+public class MinInt extends AggFunction<Datum> {
+
+  public MinInt() {
+    super(new Column[] {
+        new Column("expr", Type.INT8)
+    });
+  }
+
+  @Override
+  public FunctionContext newContext() {
+    return new MinContext();
+  }
+
+  @Override
+  public void eval(FunctionContext ctx, Tuple params) {
+    MinContext minCtx = (MinContext) ctx;
+    minCtx.min = Math.min(minCtx.min, params.get(0).asInt4());
+  }
+
+  @Override
+  public Datum getPartialResult(FunctionContext ctx) {
+    return DatumFactory.createInt4(((MinContext) ctx).min);
+  }
+
+  @Override
+  public DataType getPartialResultType() {
+    return CatalogUtil.newSimpleDataType(Type.INT4);
+  }
+
+  @Override
+  public Datum terminate(FunctionContext ctx) {
+    return DatumFactory.createInt4(((MinContext) ctx).min);
+  }
+
+  private class MinContext implements FunctionContext {
+    int min = Integer.MAX_VALUE;
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/026368be/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MinLong.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MinLong.java b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MinLong.java
new file mode 100644
index 0000000..ad9ebfa
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MinLong.java
@@ -0,0 +1,78 @@
+/**
+ * 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.function.builtin;
+
+import org.apache.tajo.catalog.CatalogUtil;
+import org.apache.tajo.catalog.Column;
+import org.apache.tajo.common.TajoDataTypes.DataType;
+import org.apache.tajo.common.TajoDataTypes.Type;
+import org.apache.tajo.datum.Datum;
+import org.apache.tajo.datum.DatumFactory;
+import org.apache.tajo.datum.Int8Datum;
+import org.apache.tajo.engine.function.AggFunction;
+import org.apache.tajo.engine.function.FunctionContext;
+import org.apache.tajo.engine.function.annotation.Description;
+import org.apache.tajo.engine.function.annotation.ParamTypes;
+import org.apache.tajo.storage.Tuple;
+
+@Description(
+  functionName = "min",
+  description = "the minimum value of expr",
+  example = "> SELECT min(expr);",
+  returnType = Type.INT8,
+  paramTypes = {@ParamTypes(paramTypes = {Type.INT8})}
+)
+public class MinLong extends AggFunction<Datum> {
+
+  public MinLong() {
+    super(new Column[] {
+        new Column("expr", Type.INT8)
+    });
+  }
+
+  @Override
+  public FunctionContext newContext() {
+    return new MinContext();
+  }
+
+  @Override
+  public void eval(FunctionContext ctx, Tuple params) {
+    MinContext minCtx = (MinContext)ctx;
+    minCtx.min = Math.min(minCtx.min, params.get(0).asInt8());
+  }
+
+  @Override
+  public Datum getPartialResult(FunctionContext ctx) {
+    return DatumFactory.createInt8(((MinContext) ctx).min);
+  }
+
+  @Override
+  public DataType getPartialResultType() {
+    return CatalogUtil.newSimpleDataType(Type.INT8);
+  }
+
+  @Override
+  public Int8Datum terminate(FunctionContext ctx) {
+    return DatumFactory.createInt8(((MinContext) ctx).min);
+  }
+
+  private class MinContext implements FunctionContext {
+    long min = Long.MAX_VALUE;
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/026368be/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MinString.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MinString.java b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MinString.java
new file mode 100644
index 0000000..cbf214e
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/MinString.java
@@ -0,0 +1,82 @@
+/**
+ * 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.function.builtin;
+
+import org.apache.tajo.catalog.CatalogUtil;
+import org.apache.tajo.catalog.Column;
+import org.apache.tajo.common.TajoDataTypes.DataType;
+import org.apache.tajo.common.TajoDataTypes.Type;
+import org.apache.tajo.datum.Datum;
+import org.apache.tajo.datum.DatumFactory;
+import org.apache.tajo.datum.TextDatum;
+import org.apache.tajo.engine.function.AggFunction;
+import org.apache.tajo.engine.function.FunctionContext;
+import org.apache.tajo.engine.function.annotation.Description;
+import org.apache.tajo.engine.function.annotation.ParamTypes;
+import org.apache.tajo.storage.Tuple;
+
+@Description(
+  functionName = "min",
+  description = "the minimum value of expr",
+  example = "> SELECT min(expr);",
+  returnType = Type.TEXT,
+  paramTypes = {@ParamTypes(paramTypes = {Type.TEXT})}
+)
+public class MinString extends AggFunction<Datum> {
+
+  public MinString() {
+    super(new Column[] {
+        new Column("expr", Type.TEXT)
+    });
+  }
+
+  @Override
+  public FunctionContext newContext() {
+    return new MinContext();
+  }
+
+  @Override
+  public void eval(FunctionContext ctx, Tuple params) {
+    MinContext minCtx = (MinContext) ctx;
+    if (minCtx.min == null) {
+      minCtx.min = params.get(0).asChars();
+    } else if (params.get(0).asChars().compareTo(minCtx.min) < 0) {
+      minCtx.min = params.get(0).asChars();
+    }
+  }
+
+  @Override
+  public Datum getPartialResult(FunctionContext ctx) {
+    return DatumFactory.createText(((MinContext) ctx).min);
+  }
+
+  @Override
+  public DataType getPartialResultType() {
+    return CatalogUtil.newSimpleDataType(Type.TEXT);
+  }
+
+  @Override
+  public TextDatum terminate(FunctionContext ctx) {
+    return DatumFactory.createText(((MinContext) ctx).min);
+  }
+
+  private class MinContext implements FunctionContext {
+    String min;
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/026368be/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/RandomInt.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/RandomInt.java b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/RandomInt.java
new file mode 100644
index 0000000..bdcf485
--- /dev/null
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/function/builtin/RandomInt.java
@@ -0,0 +1,57 @@
+/**
+ * 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.function.builtin;
+
+import org.apache.tajo.catalog.Column;
+import org.apache.tajo.common.TajoDataTypes;
+import org.apache.tajo.datum.Datum;
+import org.apache.tajo.datum.DatumFactory;
+import org.apache.tajo.engine.function.GeneralFunction;
+import org.apache.tajo.engine.function.annotation.Description;
+import org.apache.tajo.engine.function.annotation.ParamTypes;
+import org.apache.tajo.storage.Tuple;
+
+import java.util.Random;
+
+import static org.apache.tajo.common.TajoDataTypes.Type.INT4;
+
+@Description(
+  functionName = "random",
+  description = "A pseudorandom number",
+  example = "> SELECT random(10);\n"
+          + "4",
+  returnType = TajoDataTypes.Type.INT4,
+  paramTypes = {@ParamTypes(paramTypes = {TajoDataTypes.Type.INT4})}
+)
+public class RandomInt extends GeneralFunction {
+  private Random random;
+
+  public RandomInt() {
+    super(new Column[] {
+        new Column("n", INT4)
+    });
+    random = new Random(System.nanoTime());
+  }
+
+  @Override
+  public Datum eval(Tuple params) {
+    return DatumFactory.createInt4(random.nextInt(params.get(0).asInt4()));
+  }
+
+}


Mime
View raw message