Repository: phoenix
Updated Branches:
  refs/heads/4.0 349d36bce -> 5a988cb82


http://git-wip-us.apache.org/repos/asf/phoenix/blob/5a988cb8/phoenix-core/src/test/java/org/apache/phoenix/expression/ArithmeticOperationTest.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/test/java/org/apache/phoenix/expression/ArithmeticOperationTest.java
 
b/phoenix-core/src/test/java/org/apache/phoenix/expression/ArithmeticOperationTest.java
new file mode 100644
index 0000000..028e49a
--- /dev/null
+++ 
b/phoenix-core/src/test/java/org/apache/phoenix/expression/ArithmeticOperationTest.java
@@ -0,0 +1,303 @@
+/*
+ * 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;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.math.BigDecimal;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.phoenix.exception.ValueTypeIncompatibleException;
+import org.apache.phoenix.expression.function.RandomFunction;
+import org.apache.phoenix.expression.visitor.CloneExpressionVisitor;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.schema.types.PInteger;
+import org.junit.Test;
+
+
+public class ArithmeticOperationTest {
+
+    // Addition
+    // result scale should be: max(ls, rs)
+    // result precision should be: max(lp - ls, rp - rs) + 1 + max(ls, rs)
+    @Test
+    public void testDecimalAddition() throws Exception {
+        LiteralExpression op1, op2, op3;
+        List<Expression> children;
+        DecimalAddExpression e;
+
+        op1 = LiteralExpression.newConstant(new 
BigDecimal("1234567890123456789012345678901"), PDecimal.INSTANCE, 31, 0);
+        op2 = LiteralExpression.newConstant(new BigDecimal("12345"), 
PDecimal.INSTANCE, 5, 0);
+        children = Arrays.<Expression>asList(op1, op2);
+        e = new DecimalAddExpression(children);
+        assertEqualValue(e, PDecimal.INSTANCE, new 
BigDecimal("1234567890123456789012345691246"));
+
+        op1 = LiteralExpression.newConstant(new BigDecimal("12345"), 
PDecimal.INSTANCE, 5, 0);
+        op2 = LiteralExpression.newConstant(new BigDecimal("123.45"), 
PDecimal.INSTANCE, 5, 2);
+        children = Arrays.<Expression>asList(op1, op2);
+        e = new DecimalAddExpression(children);
+        assertEqualValue(e, PDecimal.INSTANCE, new BigDecimal("12468.45"));
+
+        // Exceeds precision.
+        op1 = LiteralExpression.newConstant(new 
BigDecimal("99999999999999999999999999999999999999"), PDecimal.INSTANCE, 38, 0);
+        op2 = LiteralExpression.newConstant(new BigDecimal("123"), 
PDecimal.INSTANCE, 3, 0);
+        children = Arrays.<Expression>asList(op1, op2);
+        e = new DecimalAddExpression(children);
+        try {
+            e.evaluate(null, new ImmutableBytesWritable());
+            fail("Evaluation should have failed");
+        } catch (ValueTypeIncompatibleException ex) {
+        }
+
+        // Pass since we roll out imposing precisioin and scale.
+        op1 = LiteralExpression.newConstant(new 
BigDecimal("99999999999999999999999999999999999999"), PDecimal.INSTANCE, 38, 0);
+        op2 = LiteralExpression.newConstant(new BigDecimal("123"), 
PDecimal.INSTANCE, 3, 0);
+        op3 = LiteralExpression.newConstant(new BigDecimal("-123"), 
PDecimal.INSTANCE, 3, 0);
+        children = Arrays.<Expression>asList(op1, op2, op3);
+        e = new DecimalAddExpression(children);
+        assertEqualValue(e, PDecimal.INSTANCE, new 
BigDecimal("99999999999999999999999999999999999999"));
+
+        // Exceeds scale.
+        op1 = LiteralExpression.newConstant(new 
BigDecimal("12345678901234567890123456789012345678"), PDecimal.INSTANCE, 38, 0);
+        op2 = LiteralExpression.newConstant(new BigDecimal("123.45"), 
PDecimal.INSTANCE, 5, 2);
+        children = Arrays.<Expression>asList(op1, op2);
+        e = new DecimalAddExpression(children);
+        try {
+            e.evaluate(null, new ImmutableBytesWritable());
+            fail("Evaluation should have failed");
+        } catch (ValueTypeIncompatibleException ex) {
+        }
+        
+        // Decimal with no precision and scale.
+        op1 = LiteralExpression.newConstant(new BigDecimal("9999.1"), 
PDecimal.INSTANCE);
+        op2 = LiteralExpression.newConstant(new BigDecimal("1.1111"), 
PDecimal.INSTANCE, 5, 4);
+        children = Arrays.<Expression>asList(op1, op2);
+        e = new DecimalAddExpression(children);
+        assertEqualValue(e, PDecimal.INSTANCE, new BigDecimal("10000.2111"));
+    }
+
+    @Test
+    public void testIntPlusDecimal() throws Exception {
+        LiteralExpression op1, op2;
+        List<Expression> children;
+        DecimalAddExpression e;
+
+        op1 = LiteralExpression.newConstant(new BigDecimal("1234.111"), 
PDecimal.INSTANCE);
+        assertNull(op1.getScale());
+        op2 = LiteralExpression.newConstant(1, PInteger.INSTANCE);
+        children = Arrays.<Expression>asList(op1, op2);
+        e = new DecimalAddExpression(children);
+        assertEqualValue(e, PDecimal.INSTANCE, new BigDecimal("1235.111"));
+    }
+
+    // Subtraction
+    // result scale should be: max(ls, rs)
+    // result precision should be: max(lp - ls, rp - rs) + 1 + max(ls, rs)
+    @Test
+    public void testDecimalSubtraction() throws Exception {
+        LiteralExpression op1, op2, op3;
+        List<Expression> children;
+        DecimalSubtractExpression e;
+
+        op1 = LiteralExpression.newConstant(new 
BigDecimal("1234567890123456789012345678901"), PDecimal.INSTANCE, 31, 0);
+        op2 = LiteralExpression.newConstant(new BigDecimal("12345"), 
PDecimal.INSTANCE, 5, 0);
+        children = Arrays.<Expression>asList(op1, op2);
+        e = new DecimalSubtractExpression(children);
+        assertEqualValue(e, PDecimal.INSTANCE, new 
BigDecimal("1234567890123456789012345666556"));
+
+        op1 = LiteralExpression.newConstant(new BigDecimal("12345"), 
PDecimal.INSTANCE, 5, 0);
+        op2 = LiteralExpression.newConstant(new BigDecimal("123.45"), 
PDecimal.INSTANCE, 5, 2);
+        children = Arrays.<Expression>asList(op1, op2);
+        e = new DecimalSubtractExpression(children);
+        assertEqualValue(e, PDecimal.INSTANCE, new BigDecimal("12221.55"));
+
+        // Excceds precision
+        op1 = LiteralExpression.newConstant(new 
BigDecimal("99999999999999999999999999999999999999"), PDecimal.INSTANCE, 38, 0);
+        op2 = LiteralExpression.newConstant(new BigDecimal("-123"), 
PDecimal.INSTANCE, 3, 0);
+        children = Arrays.<Expression>asList(op1, op2);
+        e = new DecimalSubtractExpression(children);
+        try {
+            e.evaluate(null, new ImmutableBytesWritable());
+            fail("Evaluation should have failed");
+        } catch (ValueTypeIncompatibleException ex) {
+        }
+
+        // Pass since we roll up precision and scale imposing.
+        op1 = LiteralExpression.newConstant(new 
BigDecimal("99999999999999999999999999999999999999"), PDecimal.INSTANCE, 38, 0);
+        op2 = LiteralExpression.newConstant(new BigDecimal("-123"), 
PDecimal.INSTANCE, 3, 0);
+        op3 = LiteralExpression.newConstant(new BigDecimal("123"), 
PDecimal.INSTANCE, 3, 0);
+        children = Arrays.<Expression>asList(op1, op2, op3);
+        e = new DecimalSubtractExpression(children);
+        assertEqualValue(e, PDecimal.INSTANCE, new 
BigDecimal("99999999999999999999999999999999999999"));
+
+        // Exceeds scale.
+        op1 = LiteralExpression.newConstant(new 
BigDecimal("12345678901234567890123456789012345678"), PDecimal.INSTANCE, 38, 0);
+        op2 = LiteralExpression.newConstant(new BigDecimal("123.45"), 
PDecimal.INSTANCE, 5, 2);
+        children = Arrays.<Expression>asList(op1, op2);
+        e = new DecimalSubtractExpression(children);
+        try {
+            e.evaluate(null, new ImmutableBytesWritable());
+            fail("Evaluation should have failed");
+        } catch (ValueTypeIncompatibleException ex) {
+        }
+        
+        // Decimal with no precision and scale.
+        op1 = LiteralExpression.newConstant(new BigDecimal("1111.1"), 
PDecimal.INSTANCE);
+        op2 = LiteralExpression.newConstant(new BigDecimal("1.1111"), 
PDecimal.INSTANCE, 5, 4);
+        children = Arrays.<Expression>asList(op1, op2);
+        e = new DecimalSubtractExpression(children);
+        assertEqualValue(e, PDecimal.INSTANCE, new BigDecimal("1109.9889"));
+    }
+
+    // Multiplication
+    // result scale should be: ls + rs
+    // result precision should be: lp + rp
+    @Test
+    public void testDecimalMultiplication() throws Exception {
+        LiteralExpression op1, op2;
+        List<Expression> children;
+        DecimalMultiplyExpression e;
+
+        op1 = LiteralExpression.newConstant(new BigDecimal("12345"), 
PDecimal.INSTANCE, 5, 0);
+        op2 = LiteralExpression.newConstant(new BigDecimal("123.45"), 
PDecimal.INSTANCE, 5, 2);
+        children = Arrays.<Expression>asList(op1, op2);
+        e = new DecimalMultiplyExpression(children);
+        assertEqualValue(e, PDecimal.INSTANCE, new BigDecimal("1523990.25"));
+
+        // Value too big, exceeds precision.
+        op1 = LiteralExpression.newConstant(new 
BigDecimal("12345678901234567890123456789012345678"), PDecimal.INSTANCE, 38, 0);
+        op2 = LiteralExpression.newConstant(new BigDecimal("12345"), 
PDecimal.INSTANCE, 5, 0);
+        children = Arrays.<Expression>asList(op1, op2);
+        e = new DecimalMultiplyExpression(children);
+        try {
+            e.evaluate(null, new ImmutableBytesWritable());
+            fail("Evaluation should have failed");
+        } catch (ValueTypeIncompatibleException ex) {
+        }
+
+        // Values exceeds scale.
+        op1 = LiteralExpression.newConstant(new 
BigDecimal("12345678901234567890123456789012345678"), PDecimal.INSTANCE, 38, 0);
+        op2 = LiteralExpression.newConstant(new BigDecimal("1.45"), 
PDecimal.INSTANCE, 3, 2);
+        children = Arrays.<Expression>asList(op1, op2);
+        e = new DecimalMultiplyExpression(children);
+        try {
+            e.evaluate(null, new ImmutableBytesWritable());
+            fail("Evaluation should have failed");
+        } catch (ValueTypeIncompatibleException ex) {
+        }
+        
+        // Decimal with no precision and scale.
+        op1 = LiteralExpression.newConstant(new BigDecimal("1111.1"), 
PDecimal.INSTANCE);
+        assertNull(op1.getScale());
+        op2 = LiteralExpression.newConstant(new BigDecimal("1.1111"), 
PDecimal.INSTANCE, 5, 4);
+        children = Arrays.<Expression>asList(op1, op2);
+        e = new DecimalMultiplyExpression(children);
+        assertEqualValue(e, PDecimal.INSTANCE, new BigDecimal("1234.54321"));
+    }
+
+    // Division
+    // result scale should be: 31 - lp + ls - rs
+    // result precision should be: lp - ls + rp + scale
+    @Test
+    public void testDecimalDivision() throws Exception {
+        LiteralExpression op1, op2;
+        List<Expression> children;
+        DecimalDivideExpression e;
+
+        // The value should be 1234500.0000...00 because we set to scale to be 
24. However, in
+        // PhoenixResultSet.getBigDecimal, the case to (BigDecimal) actually 
cause the scale to be eradicated. As
+        // a result, the resulting value does not have the right form.
+        op1 = LiteralExpression.newConstant(new BigDecimal("12345"), 
PDecimal.INSTANCE, 5, 0);
+        op2 = LiteralExpression.newConstant(new BigDecimal("0.01"), 
PDecimal.INSTANCE, 2, 2);
+        children = Arrays.<Expression>asList(op1, op2);
+        e = new DecimalDivideExpression(children);
+        assertEqualValue(e, PDecimal.INSTANCE, new BigDecimal("1.2345E+6"));
+
+        // Exceeds precision.
+        op1 = LiteralExpression.newConstant(new 
BigDecimal("12345678901234567890123456789012345678"), PDecimal.INSTANCE, 38, 0);
+        op2 = LiteralExpression.newConstant(new BigDecimal("0.01"), 
PDecimal.INSTANCE, 2, 2);
+        children = Arrays.<Expression>asList(op1, op2);
+        e = new DecimalDivideExpression(children);
+        try {
+            e.evaluate(null, new ImmutableBytesWritable());
+            fail("Evaluation should have failed");
+        } catch (ValueTypeIncompatibleException ex) {
+        }
+        
+        // Decimal with no precision and scale.
+        op1 = LiteralExpression.newConstant(new BigDecimal("10"), 
PDecimal.INSTANCE);
+        op2 = LiteralExpression.newConstant(new BigDecimal("3"), 
PDecimal.INSTANCE, 5, 4);
+        assertEquals(Integer.valueOf(4),op2.getScale());
+        children = Arrays.<Expression>asList(op1, op2);
+        e = new DecimalDivideExpression(children);
+        assertEqualValue(e, PDecimal.INSTANCE, new 
BigDecimal("3.3333333333333333333333333333333333333"));
+    }
+
+    @Test
+    public void testPerInvocationClone() throws Exception {
+        LiteralExpression op1, op2, op3, op4;
+        List<Expression> children;
+        Expression e1, e2, e3, e4;
+        ImmutableBytesWritable ptr1 = new ImmutableBytesWritable();
+        ImmutableBytesWritable ptr2 = new ImmutableBytesWritable();
+
+        op1 = LiteralExpression.newConstant(5.0);
+        op2 = LiteralExpression.newConstant(3.0);
+        op3 = LiteralExpression.newConstant(2.0);
+        op4 = LiteralExpression.newConstant(1.0);
+        children = Arrays.<Expression>asList(op1, op2);
+        e1 = new DoubleAddExpression(children);
+        children = Arrays.<Expression>asList(op3, op4);
+        e2 = new DoubleSubtractExpression(children);
+        e3 = new DoubleAddExpression(Arrays.<Expression>asList(e1, e2));
+        e4 = new DoubleAddExpression(Arrays.<Expression>asList(new 
RandomFunction(Arrays.<Expression>asList(LiteralExpression.newConstant(null))), 
e3));
+        CloneExpressionVisitor visitor = new CloneExpressionVisitor();
+        Expression clone = e4.accept(visitor);
+        assertTrue(clone != e4);
+        e4.evaluate(null, ptr1);
+        clone.evaluate(null, ptr2);
+        assertNotEquals(ptr1, ptr2);
+        
+        e4 = new DoubleAddExpression(Arrays.<Expression>asList(new 
RandomFunction(Arrays.<Expression>asList(LiteralExpression.newConstant(1))), 
e3));
+        visitor = new CloneExpressionVisitor();
+        clone = e4.accept(visitor);
+        assertTrue(clone == e4);
+        e4.evaluate(null, ptr1);
+        clone.evaluate(null, ptr2);
+        assertEquals(ptr1, ptr2);
+    }
+
+    private static void assertEqualValue(Expression e, PDataType type, Object 
value) {
+        ImmutableBytesWritable ptr = new ImmutableBytesWritable();
+        boolean evaluated = e.evaluate(null, ptr);
+        assertTrue(evaluated);
+        assertEquals(value, type.toObject(ptr.get()));
+        CloneExpressionVisitor visitor = new CloneExpressionVisitor();
+        Expression clone = e.accept(visitor);
+        evaluated = clone.evaluate(null, ptr);
+        assertTrue(evaluated);
+        assertEquals(value, type.toObject(ptr.get()));
+    }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/5a988cb8/phoenix-core/src/test/java/org/apache/phoenix/expression/ILikeExpressionTest.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/test/java/org/apache/phoenix/expression/ILikeExpressionTest.java
 
b/phoenix-core/src/test/java/org/apache/phoenix/expression/ILikeExpressionTest.java
index 2c4af74..3033edf 100644
--- 
a/phoenix-core/src/test/java/org/apache/phoenix/expression/ILikeExpressionTest.java
+++ 
b/phoenix-core/src/test/java/org/apache/phoenix/expression/ILikeExpressionTest.java
@@ -32,7 +32,7 @@ public class ILikeExpressionTest {
       LiteralExpression v = LiteralExpression.newConstant(value);
       LiteralExpression p = LiteralExpression.newConstant(expression);
       List<Expression> children = Arrays.<Expression>asList(v,p);
-      LikeExpression e = new LikeExpression(children, 
LikeType.CASE_INSENSITIVE);
+      LikeExpression e = LikeExpression.create(children, 
LikeType.CASE_INSENSITIVE);
       ImmutableBytesWritable ptr = new ImmutableBytesWritable();
       boolean evaluated = e.evaluate(null, ptr);
       Boolean result = (Boolean)e.getDataType().toObject(ptr);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/5a988cb8/phoenix-core/src/test/java/org/apache/phoenix/expression/LikeExpressionTest.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/test/java/org/apache/phoenix/expression/LikeExpressionTest.java
 
b/phoenix-core/src/test/java/org/apache/phoenix/expression/LikeExpressionTest.java
index 81b7124..27e6547 100644
--- 
a/phoenix-core/src/test/java/org/apache/phoenix/expression/LikeExpressionTest.java
+++ 
b/phoenix-core/src/test/java/org/apache/phoenix/expression/LikeExpressionTest.java
@@ -32,7 +32,7 @@ public class LikeExpressionTest {
       LiteralExpression v = LiteralExpression.newConstant(value);
       LiteralExpression p = LiteralExpression.newConstant(expression);
       List<Expression> children = Arrays.<Expression>asList(v,p);
-      LikeExpression e = new LikeExpression(children, LikeType.CASE_SENSITIVE);
+      LikeExpression e = LikeExpression.create(children, 
LikeType.CASE_SENSITIVE);
       ImmutableBytesWritable ptr = new ImmutableBytesWritable();
       boolean evaluated = e.evaluate(null, ptr);
       Boolean result = (Boolean)e.getDataType().toObject(ptr);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/5a988cb8/phoenix-core/src/test/java/org/apache/phoenix/expression/SortOrderExpressionTest.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/test/java/org/apache/phoenix/expression/SortOrderExpressionTest.java
 
b/phoenix-core/src/test/java/org/apache/phoenix/expression/SortOrderExpressionTest.java
index 464153d..f75bb3e 100644
--- 
a/phoenix-core/src/test/java/org/apache/phoenix/expression/SortOrderExpressionTest.java
+++ 
b/phoenix-core/src/test/java/org/apache/phoenix/expression/SortOrderExpressionTest.java
@@ -289,16 +289,16 @@ public class SortOrderExpressionTest {
     
     private void runCompareTest(CompareOp op, boolean expectedResult, Object 
lhsValue, PDataType lhsDataType, Object rhsValue, PDataType rhsDataType) throws 
Exception {
         List<Expression> args = Lists.newArrayList(getLiteral(lhsValue, 
lhsDataType), getLiteral(rhsValue, rhsDataType));
-        evaluateAndAssertResult(new ComparisonExpression(op, args), 
expectedResult, "lhsDataType: " + lhsDataType + " rhsDataType: " + rhsDataType);
+        evaluateAndAssertResult(new ComparisonExpression(args, op), 
expectedResult, "lhsDataType: " + lhsDataType + " rhsDataType: " + rhsDataType);
         
         args = Lists.newArrayList(getInvertedLiteral(lhsValue, lhsDataType), 
getLiteral(rhsValue, rhsDataType));
-        evaluateAndAssertResult(new ComparisonExpression(op, args), 
expectedResult, "lhs (inverted) dataType: " + lhsDataType + " rhsDataType: " + 
rhsDataType);
+        evaluateAndAssertResult(new ComparisonExpression(args, op), 
expectedResult, "lhs (inverted) dataType: " + lhsDataType + " rhsDataType: " + 
rhsDataType);
         
         args = Lists.newArrayList(getLiteral(lhsValue, lhsDataType), 
getInvertedLiteral(rhsValue, rhsDataType));
-        evaluateAndAssertResult(new ComparisonExpression(op, args), 
expectedResult, "lhsDataType: " + lhsDataType + " rhs (inverted) dataType: " + 
rhsDataType);
+        evaluateAndAssertResult(new ComparisonExpression(args, op), 
expectedResult, "lhsDataType: " + lhsDataType + " rhs (inverted) dataType: " + 
rhsDataType);
         
         args = Lists.newArrayList(getInvertedLiteral(lhsValue, lhsDataType), 
getInvertedLiteral(rhsValue, rhsDataType));
-        evaluateAndAssertResult(new ComparisonExpression(op, args), 
expectedResult, "lhs (inverted) dataType: " + lhsDataType + " rhs (inverted) 
dataType: " + rhsDataType);                
+        evaluateAndAssertResult(new ComparisonExpression(args, op), 
expectedResult, "lhs (inverted) dataType: " + lhsDataType + " rhs (inverted) 
dataType: " + rhsDataType);                
     }
     
     private void evaluateAndAssertResult(Expression expression, Object 
expectedResult) {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/5a988cb8/phoenix-core/src/test/java/org/apache/phoenix/expression/function/ExternalSqlTypeIdFunctionTest.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/test/java/org/apache/phoenix/expression/function/ExternalSqlTypeIdFunctionTest.java
 
b/phoenix-core/src/test/java/org/apache/phoenix/expression/function/ExternalSqlTypeIdFunctionTest.java
index 7f9cc9b..e9dff40 100644
--- 
a/phoenix-core/src/test/java/org/apache/phoenix/expression/function/ExternalSqlTypeIdFunctionTest.java
+++ 
b/phoenix-core/src/test/java/org/apache/phoenix/expression/function/ExternalSqlTypeIdFunctionTest.java
@@ -17,7 +17,13 @@
  */
 package org.apache.phoenix.expression.function;
 
-import com.google.common.collect.Lists;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import java.util.List;
+
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.expression.LiteralExpression;
@@ -25,11 +31,7 @@ import org.apache.phoenix.schema.types.PInteger;
 import org.apache.phoenix.schema.types.PIntegerArray;
 import org.junit.Test;
 
-import java.sql.SQLException;
-import java.sql.Types;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import com.google.common.collect.Lists;
 
 public class ExternalSqlTypeIdFunctionTest {
 
@@ -53,6 +55,17 @@ public class ExternalSqlTypeIdFunctionTest {
         assertEquals(Types.ARRAY, returnValue);
     }
 
+    @Test
+    public void testClone() throws SQLException {
+        Expression inputArg = LiteralExpression.newConstant(
+                PIntegerArray.INSTANCE.getSqlType(), PInteger.INSTANCE);
+        List<Expression> args = Lists.newArrayList(inputArg);
+        ExternalSqlTypeIdFunction externalIdFunction =
+                new ExternalSqlTypeIdFunction(args);
+        ScalarFunction clone = externalIdFunction.clone(args);
+        assertEquals(externalIdFunction, clone);
+    }
+
     private Object executeFunction(Expression inputArg) throws SQLException {
         ExternalSqlTypeIdFunction externalIdFunction =
                 new ExternalSqlTypeIdFunction(Lists.newArrayList(inputArg));

http://git-wip-us.apache.org/repos/asf/phoenix/blob/5a988cb8/phoenix-core/src/test/java/org/apache/phoenix/parse/BuiltInFunctionInfoTest.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/test/java/org/apache/phoenix/parse/BuiltInFunctionInfoTest.java
 
b/phoenix-core/src/test/java/org/apache/phoenix/parse/BuiltInFunctionInfoTest.java
index 4443c21..5cf5de0 100644
--- 
a/phoenix-core/src/test/java/org/apache/phoenix/parse/BuiltInFunctionInfoTest.java
+++ 
b/phoenix-core/src/test/java/org/apache/phoenix/parse/BuiltInFunctionInfoTest.java
@@ -17,24 +17,24 @@
  */
 package org.apache.phoenix.parse;
 
+import static org.junit.Assert.assertEquals;
+
+import java.util.List;
+
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.phoenix.expression.Expression;
-import org.apache.phoenix.expression.function.FunctionExpression;
+import org.apache.phoenix.expression.function.ScalarFunction;
+import org.apache.phoenix.parse.FunctionParseNode.Argument;
+import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
+import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunctionInfo;
+import org.apache.phoenix.schema.tuple.Tuple;
 import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.types.PVarchar;
-import org.apache.phoenix.schema.tuple.Tuple;
 import org.junit.Test;
 
-import java.util.List;
-
-import static org.apache.phoenix.parse.FunctionParseNode.BuiltInFunctionInfo;
-import static org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
-import static org.apache.phoenix.parse.FunctionParseNode.Argument;
-import static org.junit.Assert.assertEquals;
-
 public class BuiltInFunctionInfoTest {
 
-    private static BuiltInFunctionInfo getBuiltInFunctionInfo(Class<? extends 
FunctionExpression> funcClass) {
+    private static BuiltInFunctionInfo getBuiltInFunctionInfo(Class<? extends 
ScalarFunction> funcClass) {
         return new BuiltInFunctionInfo(funcClass, 
funcClass.getAnnotation(BuiltInFunction.class));
     }
 
@@ -62,7 +62,7 @@ public class BuiltInFunctionInfoTest {
         assertEquals("WITH_MULTIPLE_DEFAULT_ARGS", funcInfo.getName());
     }
 
-    private static class BaseFunctionAdapter extends FunctionExpression {
+    private static class BaseFunctionAdapter extends ScalarFunction {
 
 
         private final String name;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/5a988cb8/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java 
b/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
index b0d55e7..872c318 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
@@ -78,12 +78,12 @@ import org.apache.phoenix.parse.LikeParseNode.LikeType;
 import org.apache.phoenix.query.KeyRange;
 import org.apache.phoenix.query.QueryConstants;
 import org.apache.phoenix.schema.PColumn;
-import org.apache.phoenix.schema.types.PDataType;
 import org.apache.phoenix.schema.RowKeyValueAccessor;
 import org.apache.phoenix.schema.TableRef;
 import org.apache.phoenix.schema.stats.GuidePostsInfo;
 import org.apache.phoenix.schema.stats.PTableStats;
 import org.apache.phoenix.schema.tuple.Tuple;
+import org.apache.phoenix.schema.types.PDataType;
 
 import com.google.common.collect.Lists;
 
@@ -249,7 +249,7 @@ public class TestUtil {
     }
 
     public static Expression constantComparison(CompareOp op, PColumn c, 
Object o) {
-        return  new ComparisonExpression(op, Arrays.<Expression>asList(new 
KeyValueColumnExpression(c), LiteralExpression.newConstant(o)));
+        return  new ComparisonExpression(Arrays.<Expression>asList(new 
KeyValueColumnExpression(c), LiteralExpression.newConstant(o)), op);
     }
 
     public static Expression kvColumn(PColumn c) {
@@ -261,15 +261,15 @@ public class TestUtil {
     }
 
     public static Expression constantComparison(CompareOp op, Expression e, 
Object o) {
-        return  new ComparisonExpression(op, Arrays.asList(e, 
LiteralExpression.newConstant(o)));
+        return  new ComparisonExpression(Arrays.asList(e, 
LiteralExpression.newConstant(o)), op);
     }
 
     public static Expression like(Expression e, Object o) {
-        return  new LikeExpression(Arrays.asList(e, 
LiteralExpression.newConstant(o)), LikeType.CASE_SENSITIVE);
+        return LikeExpression.create(Arrays.asList(e, 
LiteralExpression.newConstant(o)), LikeType.CASE_SENSITIVE);
     }
 
     public static Expression ilike(Expression e, Object o) {
-      return  new LikeExpression(Arrays.asList(e, 
LiteralExpression.newConstant(o)), LikeType.CASE_INSENSITIVE);
+      return LikeExpression.create(Arrays.asList(e, 
LiteralExpression.newConstant(o)), LikeType.CASE_INSENSITIVE);
   }
 
     public static Expression substr(Expression e, Object offset, Object 
length) {
@@ -277,7 +277,7 @@ public class TestUtil {
     }
 
     public static Expression columnComparison(CompareOp op, Expression c1, 
Expression c2) {
-        return  new ComparisonExpression(op, Arrays.<Expression>asList(c1, 
c2));
+        return  new ComparisonExpression(Arrays.<Expression>asList(c1, c2), 
op);
     }
 
     public static SingleKeyValueComparisonFilter singleKVFilter(Expression e) {

Reply via email to