PHOENIX-2593 Ensure all built-ins have required constructors (Dumindu Buddhika)


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/9a44b492
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/9a44b492
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/9a44b492

Branch: refs/heads/calcite
Commit: 9a44b492673497e65e41ff45f3bcf7fb23982e35
Parents: 59b336e
Author: James Taylor <jtay...@salesforce.com>
Authored: Sun Jan 17 12:11:04 2016 -0800
Committer: James Taylor <jtay...@salesforce.com>
Committed: Sun Jan 17 12:11:04 2016 -0800

----------------------------------------------------------------------
 .../expression/function/CeilFunction.java       |  2 +
 .../expression/function/FloorFunction.java      |  4 +-
 .../expression/function/NowFunction.java        |  2 +
 .../expression/function/RoundFunction.java      |  4 +-
 .../expression/function/ToCharFunction.java     |  4 ++
 .../expression/function/ToDateFunction.java     |  4 ++
 .../expression/function/ToNumberFunction.java   |  4 ++
 .../expression/function/ToTimeFunction.java     |  4 ++
 .../function/ToTimestampFunction.java           |  4 ++
 .../expression/function/TruncFunction.java      |  2 +
 .../BuiltinFunctionConstructorTest.java         | 65 ++++++++++++++++++++
 11 files changed, 95 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/9a44b492/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilFunction.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilFunction.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilFunction.java
index 706aadf..b65010a 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilFunction.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/CeilFunction.java
@@ -46,6 +46,8 @@ import org.apache.phoenix.schema.types.PVarchar;
 public abstract class CeilFunction extends ScalarFunction {
     
     public static final String NAME = "CEIL";
+
+    public CeilFunction() {}
     
     public CeilFunction(List<Expression> children) {
         super(children);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/9a44b492/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FloorFunction.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FloorFunction.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FloorFunction.java
index 7938324..f6baa09 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FloorFunction.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FloorFunction.java
@@ -32,8 +32,6 @@ import org.apache.phoenix.schema.types.PVarchar;
  * 
  * Base class for built-in FLOOR function.
  *
- * 
- * @since 3.0.0
  */
 @BuiltInFunction(name = FloorFunction.NAME,
                  nodeClass = FloorParseNode.class,
@@ -47,6 +45,8 @@ public abstract class FloorFunction extends ScalarFunction {
     
     public static final String NAME = "FLOOR";
     
+    public FloorFunction() {}
+    
     public FloorFunction(List<Expression> children) {
         super(children);
     }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/9a44b492/phoenix-core/src/main/java/org/apache/phoenix/expression/function/NowFunction.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/NowFunction.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/NowFunction.java
index dc90249..83a5e53 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/NowFunction.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/NowFunction.java
@@ -35,6 +35,8 @@ nodeClass=CurrentDateParseNode.class, args= {})
 public abstract class NowFunction extends ScalarFunction {
     
     public static final String NAME = "NOW";
+
+    public NowFunction() {}
     
     public NowFunction(List<Expression> children) throws SQLException {
         super(children);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/9a44b492/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundFunction.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundFunction.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundFunction.java
index 9277716..7d0306c 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundFunction.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RoundFunction.java
@@ -31,8 +31,6 @@ import org.apache.phoenix.schema.types.PVarchar;
 /**
  * Base class for RoundFunction.
  * 
- * 
- * @since 0.1
  */
 @BuiltInFunction(name = RoundFunction.NAME, 
                  nodeClass = RoundParseNode.class,
@@ -46,6 +44,8 @@ public abstract class RoundFunction extends ScalarFunction {
     
     public static final String NAME = "ROUND";
     
+    public RoundFunction() {}
+    
     public RoundFunction(List<Expression> children) {
         super(children);
     }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/9a44b492/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToCharFunction.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToCharFunction.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToCharFunction.java
index e0bc68b..a14a0cb 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToCharFunction.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToCharFunction.java
@@ -57,6 +57,10 @@ public class ToCharFunction extends ScalarFunction {
     public ToCharFunction() {
     }
 
+    public ToCharFunction(List<Expression> children) throws  SQLException {
+        this(children, null, null, null);
+    }
+
     public ToCharFunction(List<Expression> children, FunctionArgumentType 
type, String formatString, Format formatter) throws SQLException {
         super(children.subList(0, 1));
         Preconditions.checkNotNull(formatString);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/9a44b492/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToDateFunction.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToDateFunction.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToDateFunction.java
index 01b0dfd..f41d959 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToDateFunction.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToDateFunction.java
@@ -59,6 +59,10 @@ public class ToDateFunction extends ScalarFunction {
     public ToDateFunction() {
     }
 
+    public ToDateFunction(List<Expression> children) throws SQLException {
+        this(children, null, null);
+    }
+    
     public ToDateFunction(List<Expression> children, String dateFormat, String 
timeZoneId) throws SQLException {
         super(children);
         init(dateFormat, timeZoneId);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/9a44b492/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToNumberFunction.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToNumberFunction.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToNumberFunction.java
index ed70f2d..e7659a1 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToNumberFunction.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToNumberFunction.java
@@ -60,6 +60,10 @@ public class ToNumberFunction extends ScalarFunction {
     
     public ToNumberFunction() {}
 
+    public ToNumberFunction(List<Expression> children) throws SQLException {
+        this(children, null, null, null);
+    }
+
     public ToNumberFunction(List<Expression> children, FunctionArgumentType 
type, String formatString, Format formatter) throws SQLException {
         super(children.subList(0, 1));
         Preconditions.checkNotNull(type);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/9a44b492/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToTimeFunction.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToTimeFunction.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToTimeFunction.java
index 3a26584..2fa0553 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToTimeFunction.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToTimeFunction.java
@@ -47,6 +47,10 @@ public class ToTimeFunction extends ToDateFunction {
     public ToTimeFunction() {
     }
 
+    public ToTimeFunction(List<Expression> children) throws SQLException {
+        this(children, null, null);
+    }
+
     public ToTimeFunction(List<Expression> children, String dateFormat, String 
timeZoneId) throws SQLException {
         super(children, dateFormat, timeZoneId);
     }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/9a44b492/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToTimestampFunction.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToTimestampFunction.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToTimestampFunction.java
index 17643a2..5a4828f 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToTimestampFunction.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/ToTimestampFunction.java
@@ -47,6 +47,10 @@ public class ToTimestampFunction extends ToDateFunction {
     public ToTimestampFunction() {
     }
 
+    public ToTimestampFunction(List<Expression> children) throws SQLException {
+        this(children, null, null);
+    }
+
     public ToTimestampFunction(List<Expression> children, String dateFormat, 
String timeZoneId) throws SQLException {
         super(children, dateFormat, timeZoneId);
     }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/9a44b492/phoenix-core/src/main/java/org/apache/phoenix/expression/function/TruncFunction.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/TruncFunction.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/TruncFunction.java
index a4e79c2..3b9616c 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/TruncFunction.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/TruncFunction.java
@@ -51,6 +51,8 @@ args = {
 public abstract class TruncFunction extends ScalarFunction {
     
     public static final String NAME = "TRUNC";
+
+    public TruncFunction() {}
     
     public TruncFunction(List<Expression> children) throws SQLException {
         super(children);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/9a44b492/phoenix-core/src/test/java/org/apache/phoenix/expression/function/BuiltinFunctionConstructorTest.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/test/java/org/apache/phoenix/expression/function/BuiltinFunctionConstructorTest.java
 
b/phoenix-core/src/test/java/org/apache/phoenix/expression/function/BuiltinFunctionConstructorTest.java
new file mode 100644
index 0000000..5258283
--- /dev/null
+++ 
b/phoenix-core/src/test/java/org/apache/phoenix/expression/function/BuiltinFunctionConstructorTest.java
@@ -0,0 +1,65 @@
+/*
+ * 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.phoenix.expression.function;
+
+import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.phoenix.expression.function.ScalarFunction;
+import org.apache.phoenix.expression.Expression;
+import org.apache.phoenix.expression.ExpressionType;
+import org.junit.Test;
+
+public class BuiltinFunctionConstructorTest {
+
+    @Test
+    public void testChildrenListConstructors() {
+        ExpressionType[] types = ExpressionType.values();
+        List<Expression> children = new ArrayList<>();
+        for(int i = 0; i < types.length; i++) {
+            try {
+                
if((ScalarFunction.class.isAssignableFrom(types[i].getExpressionClass())) && 
(types[i].getExpressionClass() != UDFExpression.class)) {
+                    Constructor cons = 
types[i].getExpressionClass().getDeclaredConstructor(List.class);
+                    cons.setAccessible(true);
+                    cons.newInstance(children);
+                }
+            } catch (NoSuchMethodException e) {
+                throw new RuntimeException(e);
+            } catch (Exception e) {
+            }
+        }
+    }
+
+    @Test
+    public void testNoArgumentConstructors() {
+        ExpressionType[] types = ExpressionType.values();
+        for(int i = 0; i < types.length; i++) {
+            try {
+                
if(!AggregateFunction.class.isAssignableFrom(types[i].getExpressionClass())) {
+                    Constructor cons = 
types[i].getExpressionClass().getDeclaredConstructor();
+                    cons.setAccessible(true);
+                    cons.newInstance();
+                }
+            } catch (NoSuchMethodException e) {
+                throw new RuntimeException(e);
+            } catch (Exception e) {
+            }
+        }
+    }
+}

Reply via email to