http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/952cf517/core/src/test/java/org/apache/carbondata/scan/expression/conditional/GreaterThanExpressionUnitTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/carbondata/scan/expression/conditional/GreaterThanExpressionUnitTest.java b/core/src/test/java/org/apache/carbondata/scan/expression/conditional/GreaterThanExpressionUnitTest.java deleted file mode 100644 index e0805a6..0000000 --- a/core/src/test/java/org/apache/carbondata/scan/expression/conditional/GreaterThanExpressionUnitTest.java +++ /dev/null @@ -1,364 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.carbondata.scan.expression.conditional; - -import java.math.BigDecimal; -import java.sql.Timestamp; -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; - -import org.apache.carbondata.core.metadata.DataType; -import org.apache.carbondata.scan.expression.ColumnExpression; -import org.apache.carbondata.scan.expression.ExpressionResult; -import org.apache.carbondata.scan.expression.exception.FilterIllegalMemberException; -import org.apache.carbondata.scan.expression.exception.FilterUnsupportedException; -import org.apache.carbondata.scan.filter.intf.RowImpl; - -import mockit.Mock; -import mockit.MockUp; -import org.apache.spark.sql.types.Decimal; -import org.junit.Test; - -import static junit.framework.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -public class GreaterThanExpressionUnitTest { - static GreaterThanExpression greaterThanExpression; - - @Test public void testEvaluateForGreaterThanExpressionWithStringDataType() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression left = new ColumnExpression("left_name", DataType.STRING); - left.setColIndex(0); - ColumnExpression right = new ColumnExpression("right_name", DataType.STRING); - right.setColIndex(1); - greaterThanExpression = new GreaterThanExpression(left, right); - RowImpl value = new RowImpl(); - String[] row = { "string1" }; - String[] row1 = { "String's Value" }; - Object objectRow[] = { row, row1 }; - new MockUp<ExpressionResult>() { - Boolean returnMockFlag = true; - - @Mock public String getString() { - if (returnMockFlag) { - returnMockFlag = false; - return "string1"; - - } else { - return "String's Value"; - - } - - } - }; - value.setValues(objectRow); - ExpressionResult result = greaterThanExpression.evaluate(value); - assertTrue(result.getBoolean()); - } - - @Test public void testEvaluateForGreaterThanExpressionWithShortDataType() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression right = new ColumnExpression("id", DataType.SHORT); - right.setColIndex(0); - ColumnExpression left = new ColumnExpression("id", DataType.SHORT); - left.setColIndex(1); - greaterThanExpression = new GreaterThanExpression(left, right); - RowImpl value = new RowImpl(); - Short[] row = { 170 }; - Short[] row1 = { 70 }; - Object objectRow[] = { row, row1 }; - value.setValues(objectRow); - - new MockUp<ExpressionResult>() { - Boolean returnMockFlag = true; - - @Mock public Short getShort() { - if (returnMockFlag) { - returnMockFlag = false; - return 170; - - } else { - return 70; - - } - - } - }; - - ExpressionResult result = greaterThanExpression.evaluate(value); - assertTrue(result.getBoolean()); - - } - - @Test public void testEvaluateForGreaterThanExpressionWithDoubleDataType() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression right = new ColumnExpression("right_contact", DataType.DOUBLE); - right.setColIndex(0); - ColumnExpression left = new ColumnExpression("left_contact", DataType.DOUBLE); - left.setColIndex(1); - greaterThanExpression = new GreaterThanExpression(left, right); - RowImpl value = new RowImpl(); - Double[] row = { 44D }; - Double[] row1 = { 20D }; - Object objectRow[] = { row1, row }; - value.setValues(objectRow); - - new MockUp<ExpressionResult>() { - Boolean returnMockFlag = true; - - @Mock public Double getDouble() { - if (returnMockFlag) { - returnMockFlag = false; - return 44D; - - } else { - return 20D; - - } - - } - }; - - ExpressionResult result = greaterThanExpression.evaluate(value); - assertTrue(result.getBoolean()); - } - - @Test public void testEvaluateForGreaterThanExpressionWithIntDataType() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression right = new ColumnExpression("right_number", DataType.INT); - right.setColIndex(0); - ColumnExpression left = new ColumnExpression("left_number", DataType.INT); - left.setColIndex(1); - greaterThanExpression = new GreaterThanExpression(left, right); - RowImpl value = new RowImpl(); - Integer[] row = { 140 }; - Integer[] row1 = { 150 }; - Object objectRow[] = { row, row1 }; - value.setValues(objectRow); - - new MockUp<ExpressionResult>() { - Boolean returnMockFlag = true; - - @Mock public Integer getInt() { - if (returnMockFlag) { - returnMockFlag = false; - return 150; - - } else { - return 140; - - } - - } - }; - - ExpressionResult result = greaterThanExpression.evaluate(value); - assertTrue(result.getBoolean()); - } - - @Test public void testEvaluateForGreaterThanExpressionWithTimestampDataType() - throws FilterUnsupportedException, FilterIllegalMemberException { - try { - ColumnExpression left = new ColumnExpression("timestamp", DataType.TIMESTAMP); - left.setColIndex(0); - ColumnExpression right = new ColumnExpression("timestamp", DataType.TIMESTAMP); - right.setColIndex(1); - - greaterThanExpression = new GreaterThanExpression(left, right); - - RowImpl value = new RowImpl(); - - DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); - - Date date = dateFormat.parse("23/09/2007"); - long time = date.getTime(); - Timestamp[] row = { new Timestamp(time) }; - - Date date1 = dateFormat.parse("24/09/2007"); - long time1 = date1.getTime(); - Timestamp[] row1 = { new Timestamp(time1) }; - - Object objectRow[] = { row1, row }; - value.setValues(objectRow); - - new MockUp<ExpressionResult>() { - Boolean returnMockFlag = true; - - @Mock public Long getTime() { - if (returnMockFlag) { - returnMockFlag = false; - return 1190592000L; - } else { - return 1190505600L; - } - } - }; - - ExpressionResult result = greaterThanExpression.evaluate(value); - assertTrue(result.getBoolean()); - } catch (ParseException e) { - System.out.println("Error while parsing " + e.getMessage()); - } - } - - @Test public void testEvaluateForGreaterThanExpressionWithLongDataType() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression right = new ColumnExpression("contact", DataType.LONG); - right.setColIndex(0); - ColumnExpression left = new ColumnExpression("contact", DataType.LONG); - left.setColIndex(1); - greaterThanExpression = new GreaterThanExpression(left, right); - RowImpl value = new RowImpl(); - Long[] row = { 1234567654321L }; - Long[] row1 = { 123456765432234L }; - Object objectRow[] = { row1, row }; - value.setValues(objectRow); - - new MockUp<ExpressionResult>() { - Boolean returnMockFlag = true; - - @Mock public Long getLong() { - if (returnMockFlag) { - returnMockFlag = false; - return 123456765432234L; - } else { - return 1234567654321L; - } - } - }; - - ExpressionResult result = greaterThanExpression.evaluate(value); - assertTrue(result.getBoolean()); - } - - @Test public void testEvaluateForGreaterThanExpressionWithDecimalDataType() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression right = new ColumnExpression("contact", DataType.DECIMAL); - right.setColIndex(0); - ColumnExpression left = new ColumnExpression("contact", DataType.DECIMAL); - left.setColIndex(1); - greaterThanExpression = new GreaterThanExpression(left, right); - RowImpl value = new RowImpl(); - Decimal[] row = new Decimal[] { Decimal.apply(12345.0) }; - Decimal[] row1 = new Decimal[] { Decimal.apply(123451245.0) }; - Object objectRow[] = { row1, row }; - value.setValues(objectRow); - - new MockUp<ExpressionResult>() { - Boolean returnMockFlag = true; - - @Mock public BigDecimal getDecimal() { - if (returnMockFlag) { - returnMockFlag = false; - return new BigDecimal(123451245.0); - } else { - return new BigDecimal(12345.0); - } - } - }; - - ExpressionResult result = greaterThanExpression.evaluate(value); - assertTrue(result.getBoolean()); - } - - @Test(expected = FilterUnsupportedException.class) public void testForGreaterThanExpressionWithDefaultCase() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression right = new ColumnExpression("contact", DataType.BOOLEAN); - right.setColIndex(0); - greaterThanExpression = new GreaterThanExpression(right, right); - RowImpl value = new RowImpl(); - Boolean[] row = { true }; - Object objectRow[] = { row }; - value.setValues(objectRow); - greaterThanExpression.evaluate(value); - } - - @Test public void testEvaluateForGreaterThanExpressionWithIsNullReturnTrue() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression right = new ColumnExpression("id", DataType.SHORT); - right.setColIndex(0); - greaterThanExpression = new GreaterThanExpression(right, right); - RowImpl value = new RowImpl(); - Short[] row = { 15 }; - Object objectRow[] = { row }; - value.setValues(objectRow); - - new MockUp<ExpressionResult>() { - @Mock public boolean isNull() { - return true; - } - }; - - new MockUp<ExpressionResult>() { - @Mock public Short getShort() { - return 15; - } - }; - - ExpressionResult result = greaterThanExpression.evaluate(value); - assertFalse(result.getBoolean()); - - } - - @Test public void testEvaluateForGreaterThanExpressionWithLeftAndRightDifferentDataType() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression left = new ColumnExpression("name", DataType.STRING); - left.setColIndex(0); - ColumnExpression right = new ColumnExpression("number", DataType.INT); - right.setColIndex(1); - greaterThanExpression = new GreaterThanExpression(left, right); - RowImpl value = new RowImpl(); - String[] row = { "String1" }; - Integer[] row1 = { 14 }; - Object objectRow[] = { row, row1 }; - value.setValues(objectRow); - - new MockUp<ExpressionResult>() { - Boolean returnMockFlag = true; - - @Mock public Integer getInt() { - if (returnMockFlag) { - returnMockFlag = false; - return 15; - } else { - return 14; - - } - - } - }; - - ExpressionResult result = greaterThanExpression.evaluate(value); - assertTrue(result.getBoolean()); - } - - @Test public void testForGreaterThanExpressionWithGetString() throws Exception { - ColumnExpression right = new ColumnExpression("right_name", DataType.STRING); - right.setColIndex(0); - ColumnExpression left = new ColumnExpression("left_name", DataType.STRING); - left.setColIndex(0); - greaterThanExpression = new GreaterThanExpression(left, right); - String expected_result = "GreaterThan(ColumnExpression(left_name),ColumnExpression(right_name))"; - String result = greaterThanExpression.getString(); - assertEquals(expected_result, result); - } -}
http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/952cf517/core/src/test/java/org/apache/carbondata/scan/expression/conditional/InExpressionUnitTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/carbondata/scan/expression/conditional/InExpressionUnitTest.java b/core/src/test/java/org/apache/carbondata/scan/expression/conditional/InExpressionUnitTest.java deleted file mode 100644 index fd7bde9..0000000 --- a/core/src/test/java/org/apache/carbondata/scan/expression/conditional/InExpressionUnitTest.java +++ /dev/null @@ -1,276 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.carbondata.scan.expression.conditional; - -import java.math.BigDecimal; -import java.sql.Timestamp; -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; - -import org.apache.carbondata.core.metadata.DataType; -import org.apache.carbondata.scan.expression.ColumnExpression; -import org.apache.carbondata.scan.expression.ExpressionResult; -import org.apache.carbondata.scan.expression.exception.FilterIllegalMemberException; -import org.apache.carbondata.scan.expression.exception.FilterUnsupportedException; -import org.apache.carbondata.scan.filter.intf.RowImpl; - -import mockit.Mock; -import mockit.MockUp; -import org.apache.spark.sql.types.Decimal; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -public class InExpressionUnitTest { - - static InExpression inExpression; - - @Test public void testEvaluateForInExpressionWithString() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression left = new ColumnExpression("left_name", DataType.STRING); - left.setColIndex(0); - ColumnExpression right = new ColumnExpression("right_name", DataType.STRING); - right.setColIndex(1); - inExpression = new InExpression(left, right); - RowImpl value = new RowImpl(); - String row = "string1"; - String row1 = "string1"; - Object objectRow[] = { row, row1 }; - - new MockUp<ExpressionResult>() { - - @Mock public DataType getDataType() { - return DataType.STRING; - } - - @Mock public String getString() { - return "string1"; - } - }; - - value.setValues(objectRow); - ExpressionResult result = inExpression.evaluate(value); - assertTrue(result.getBoolean()); - } - - @Test public void testEvaluateForInExpressionWithShortDataType() - throws FilterUnsupportedException, FilterIllegalMemberException { - - ColumnExpression left = new ColumnExpression("left_id", DataType.SHORT); - left.setColIndex(0); - ColumnExpression right = new ColumnExpression("right_id", DataType.SHORT); - right.setColIndex(1); - inExpression = new InExpression(left, right); - RowImpl value = new RowImpl(); - Short row = 150; - Short row1 = 150; - Object objectRow[] = { row, row1 }; - value.setValues(objectRow); - - new MockUp<ExpressionResult>() { - @Mock public Short getShort() { - return 150; - } - }; - - ExpressionResult result = inExpression.evaluate(value); - assertEquals(result.getDataType(), DataType.BOOLEAN); - - } - - @Test public void testEvaluateForInExpressionWithIntDataType() - throws FilterUnsupportedException, FilterIllegalMemberException { - - ColumnExpression left = new ColumnExpression("left_id", DataType.INT); - left.setColIndex(0); - ColumnExpression right = new ColumnExpression("right_id", DataType.INT); - right.setColIndex(1); - inExpression = new InExpression(left, right); - RowImpl value = new RowImpl(); - Integer row = 15052; - Integer row1 = 15052; - Object objectRow[] = { row, row1 }; - value.setValues(objectRow); - - new MockUp<ExpressionResult>() { - @Mock public Integer getInt() { - return 15052; - } - }; - - ExpressionResult result = inExpression.evaluate(value); - assertEquals(result.getDataType(), DataType.BOOLEAN); - - } - - @Test public void testEvaluateForInExpressionWithDoubleDataType() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression left = new ColumnExpression("left_contact", DataType.DOUBLE); - left.setColIndex(0); - ColumnExpression right = new ColumnExpression("right_contact", DataType.DOUBLE); - right.setColIndex(1); - inExpression = new InExpression(left, right); - RowImpl value = new RowImpl(); - Double row = 44521D; - Double row1 = 44521D; - Object objectRow[] = { row, row1 }; - value.setValues(objectRow); - - new MockUp<ExpressionResult>() { - @Mock public Double getDouble() { - return 44521D; - } - }; - - ExpressionResult result = inExpression.evaluate(value); - assertTrue(result.getBoolean()); - } - - @Test public void testEvaluateForInExpressionWithLongDataType() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression left = new ColumnExpression("left_contact", DataType.LONG); - left.setColIndex(0); - ColumnExpression right = new ColumnExpression("right_contact", DataType.LONG); - right.setColIndex(1); - inExpression = new InExpression(left, right); - RowImpl value = new RowImpl(); - Long row = 1234567654321L; - Long row1 = 1234567654321L; - Object objectRow[] = { row, row1 }; - value.setValues(objectRow); - - new MockUp<ExpressionResult>() { - @Mock public Long getLong() { - return 1234567654321L; - } - }; - - ExpressionResult result = inExpression.evaluate(value); - assertTrue(result.getBoolean()); - } - - @Test public void testEvaluateForInExpressionWithTimestampDataType() - throws FilterUnsupportedException, FilterIllegalMemberException { - try { - ColumnExpression left = new ColumnExpression("left_timestamp", DataType.TIMESTAMP); - left.setColIndex(0); - ColumnExpression right = new ColumnExpression("right_timestamp", DataType.TIMESTAMP); - right.setColIndex(1); - inExpression = new InExpression(left, right); - - RowImpl value = new RowImpl(); - DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); - Date date = dateFormat.parse("23/09/2007"); - - long time = date.getTime(); - - Timestamp row = new Timestamp(time); - Timestamp row1 = new Timestamp(time); - Object objectRow[] = { row, row1 }; - value.setValues(objectRow); - - new MockUp<ExpressionResult>() { - @Mock public Long getTime() { - return 18465213000000L; - } - }; - - ExpressionResult result = inExpression.evaluate(value); - assertFalse(result.getBoolean()); - } catch (ParseException e) { - System.out.println("Error while parsing " + e.getMessage()); - } - } - - @Test public void testEvaluateForInExpressionWithDecimalDataType() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression left = new ColumnExpression("left_contact", DataType.DECIMAL); - left.setColIndex(0); - ColumnExpression right = new ColumnExpression("right_contact", DataType.DECIMAL); - right.setColIndex(1); - inExpression = new InExpression(left, right); - RowImpl value = new RowImpl(); - Decimal row = Decimal.apply(123452154.0); - Decimal row1 = Decimal.apply(123452154.0); - Object objectRow[] = { row, row1 }; - value.setValues(objectRow); - - new MockUp<ExpressionResult>() { - @Mock public BigDecimal getDecimal() { - return new BigDecimal(123452154.0); - } - }; - - ExpressionResult result = inExpression.evaluate(value); - assertTrue(result.getBoolean()); - } - - @Test(expected = FilterUnsupportedException.class) public void testForInExpressionWithDefaultCase() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression left = new ColumnExpression("contact", DataType.BOOLEAN); - left.setColIndex(0); - ColumnExpression right = new ColumnExpression("contact", DataType.BOOLEAN); - right.setColIndex(1); - inExpression = new InExpression(left, right); - RowImpl value = new RowImpl(); - Boolean row = true; - Boolean row1 = true; - Object objectRow[] = { row, row1 }; - value.setValues(objectRow); - inExpression.evaluate(value); - } - - @Test public void testForInExpressionWithGetString() throws Exception { - ColumnExpression left = new ColumnExpression("left_name", DataType.STRING); - left.setColIndex(0); - ColumnExpression right = new ColumnExpression("right_name", DataType.STRING); - right.setColIndex(1); - inExpression = new InExpression(left, right); - String expected_result = "IN(ColumnExpression(left_name),ColumnExpression(right_name))"; - String result = inExpression.getString(); - assertEquals(expected_result, result); - } - - @Test public void testEvaluateForInExpressionWithLeftAndRightDifferentDataType() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression right = new ColumnExpression("name", DataType.STRING); - right.setColIndex(0); - ColumnExpression left = new ColumnExpression("number", DataType.INT); - left.setColIndex(1); - inExpression = new InExpression(left, right); - RowImpl value = new RowImpl(); - String row1 = "String1"; - Integer row = 14523 ; - Object objectRow[] = { row1, row }; - value.setValues(objectRow); - - new MockUp<ExpressionResult>() { - @Mock public Integer getInt() { - return 14523; - } - }; - - ExpressionResult result = inExpression.evaluate(value); - assertTrue(result.getBoolean()); - } -} http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/952cf517/core/src/test/java/org/apache/carbondata/scan/expression/conditional/LessThanEqualToExpressionUnitTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/carbondata/scan/expression/conditional/LessThanEqualToExpressionUnitTest.java b/core/src/test/java/org/apache/carbondata/scan/expression/conditional/LessThanEqualToExpressionUnitTest.java deleted file mode 100644 index f7aaa99..0000000 --- a/core/src/test/java/org/apache/carbondata/scan/expression/conditional/LessThanEqualToExpressionUnitTest.java +++ /dev/null @@ -1,368 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.carbondata.scan.expression.conditional; - -import java.math.BigDecimal; -import java.sql.Timestamp; -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; - -import org.apache.carbondata.core.metadata.DataType; -import org.apache.carbondata.scan.expression.ColumnExpression; -import org.apache.carbondata.scan.expression.ExpressionResult; -import org.apache.carbondata.scan.expression.exception.FilterIllegalMemberException; -import org.apache.carbondata.scan.expression.exception.FilterUnsupportedException; -import org.apache.carbondata.scan.filter.intf.RowImpl; - -import mockit.Mock; -import mockit.MockUp; -import org.apache.spark.sql.types.Decimal; -import org.junit.Test; - -import static junit.framework.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -public class LessThanEqualToExpressionUnitTest { - - static LessThanEqualToExpression lessThanEqualToExpression; - - @Test public void testEvaluateForLessThanEqualToExpressionWithBothStringISSame() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression left = new ColumnExpression("left_name", DataType.STRING); - left.setColIndex(0); - ColumnExpression right = new ColumnExpression("right_name", DataType.STRING); - left.setColIndex(1); - lessThanEqualToExpression = new LessThanEqualToExpression(left, left); - RowImpl value = new RowImpl(); - String[] row = { "String is Value" }; - String[] row1 = { "string1" }; - Object objectRow[] = { row, row1 }; - - new MockUp<ExpressionResult>() { - Boolean returnMockFlag = true; - - @Mock public String getString() { - if (returnMockFlag) { - returnMockFlag = false; - return "String is Value"; - - } else { - return "string1"; - - } - - } - }; - - value.setValues(objectRow); - ExpressionResult result = lessThanEqualToExpression.evaluate(value); - assertTrue(result.getBoolean()); - } - - @Test public void testEvaluateForLessThanEqualToExpressionWithShortDataType() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression right = new ColumnExpression("id", DataType.SHORT); - right.setColIndex(0); - ColumnExpression left = new ColumnExpression("id", DataType.SHORT); - left.setColIndex(1); - lessThanEqualToExpression = new LessThanEqualToExpression(left, right); - RowImpl value = new RowImpl(); - Short[] row = { 1550 }; - Short[] row1 = { 3365 }; - Object objectRow[] = { row, row1 }; - value.setValues(objectRow); - - new MockUp<ExpressionResult>() { - Boolean returnMockFlag = true; - - @Mock public Short getShort() { - if (returnMockFlag) { - returnMockFlag = false; - return 1550; - - } else { - return 3365; - - } - - } - }; - - ExpressionResult result = lessThanEqualToExpression.evaluate(value); - assertTrue(result.getBoolean()); - - } - - @Test public void testEvaluateForLessThanEqualToExpressionWithDoubleDataType() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression right = new ColumnExpression("right_contact", DataType.DOUBLE); - right.setColIndex(0); - ColumnExpression left = new ColumnExpression("left_contact", DataType.DOUBLE); - left.setColIndex(1); - lessThanEqualToExpression = new LessThanEqualToExpression(left, right); - RowImpl value = new RowImpl(); - Double[] row = { 4852.2D }; - Double[] row1 = { 4852.2D }; - Object objectRow[] = { row1, row }; - value.setValues(objectRow); - - new MockUp<ExpressionResult>() { - Boolean returnMockFlag = true; - - @Mock public Double getDouble() { - if (returnMockFlag) { - returnMockFlag = false; - return 4852.2D; - - } else { - return 4852.2D; - - } - - } - }; - - ExpressionResult result = lessThanEqualToExpression.evaluate(value); - assertTrue(result.getBoolean()); - } - - @Test public void testEvaluateForLessThanEqualToExpressionWithIntDataType() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression right = new ColumnExpression("right_number", DataType.INT); - right.setColIndex(0); - ColumnExpression left = new ColumnExpression("left_number", DataType.INT); - left.setColIndex(1); - lessThanEqualToExpression = new LessThanEqualToExpression(left, right); - RowImpl value = new RowImpl(); - Integer[] row = { 144580 }; - Integer[] row1 = { 14500 }; - Object objectRow[] = { row, row1 }; - value.setValues(objectRow); - - new MockUp<ExpressionResult>() { - Boolean returnMockFlag = true; - - @Mock public Integer getInt() { - if (returnMockFlag) { - returnMockFlag = false; - return 14500; - - } else { - return 144580; - - } - - } - }; - - ExpressionResult result = lessThanEqualToExpression.evaluate(value); - assertTrue(result.getBoolean()); - } - - @Test public void testEvaluateForLessThanEqualToExpressionWithTimestampDataType() - throws FilterUnsupportedException, FilterIllegalMemberException { - try { - ColumnExpression left = new ColumnExpression("timestamp", DataType.TIMESTAMP); - left.setColIndex(0); - ColumnExpression right = new ColumnExpression("timestamp", DataType.TIMESTAMP); - right.setColIndex(1); - - lessThanEqualToExpression = new LessThanEqualToExpression(left, right); - - RowImpl value = new RowImpl(); - - DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); - - Date date = dateFormat.parse("23/09/2007"); - long time = date.getTime(); - Timestamp[] row = { new Timestamp(time) }; - - Date date1 = dateFormat.parse("24/09/2007"); - long time1 = date1.getTime(); - Timestamp[] row1 = { new Timestamp(time1) }; - - Object objectRow[] = { row, row1 }; - value.setValues(objectRow); - - new MockUp<ExpressionResult>() { - Boolean returnMockFlag = true; - - @Mock public Long getTime() { - if (returnMockFlag) { - returnMockFlag = false; - return 1190505600L; - } else { - return 1190592000L; - } - } - }; - - ExpressionResult result = lessThanEqualToExpression.evaluate(value); - assertTrue(result.getBoolean()); - } catch (ParseException e) { - System.out.println("Error while parsing " + e.getMessage()); - } - } - - @Test public void testEvaluateForLessThanEqualToExpressionWithLongDataType() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression right = new ColumnExpression("right_contact", DataType.LONG); - right.setColIndex(0); - ColumnExpression left = new ColumnExpression("left_contact", DataType.LONG); - left.setColIndex(1); - lessThanEqualToExpression = new LessThanEqualToExpression(left, right); - RowImpl value = new RowImpl(); - Long[] row = { 4751256L }; - Long[] row1 = { 48512586L }; - Object objectRow[] = { row1, row }; - value.setValues(objectRow); - - new MockUp<ExpressionResult>() { - Boolean returnMockFlag = true; - - @Mock public Long getLong() { - if (returnMockFlag) { - returnMockFlag = false; - return 4751256L; - } else { - return 48512586L; - } - } - }; - - ExpressionResult result = lessThanEqualToExpression.evaluate(value); - assertTrue(result.getBoolean()); - } - - @Test public void testEvaluateForLessThanEqualToExpressionWithDecimalDataType() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression right = new ColumnExpression("right_contact", DataType.DECIMAL); - right.setColIndex(0); - ColumnExpression left = new ColumnExpression("left_contact", DataType.DECIMAL); - left.setColIndex(1); - lessThanEqualToExpression = new LessThanEqualToExpression(left, right); - RowImpl value = new RowImpl(); - Decimal[] row = new Decimal[] { Decimal.apply(46851.2) }; - Decimal[] row1 = new Decimal[] { Decimal.apply(45821.02) }; - Object objectRow[] = { row1, row }; - value.setValues(objectRow); - - new MockUp<ExpressionResult>() { - Boolean returnMockFlag = true; - - @Mock public BigDecimal getDecimal() { - if (returnMockFlag) { - returnMockFlag = false; - return new BigDecimal(45821.02); - } else { - return new BigDecimal(46851.2); - } - } - }; - - ExpressionResult result = lessThanEqualToExpression.evaluate(value); - assertTrue(result.getBoolean()); - } - - @Test(expected = FilterUnsupportedException.class) public void testForLessThanEqualToExpressionWithDefaultCase() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression right = new ColumnExpression("contact", DataType.BOOLEAN); - right.setColIndex(0); - lessThanEqualToExpression = new LessThanEqualToExpression(right, right); - RowImpl value = new RowImpl(); - Boolean[] row = { true }; - Object objectRow[] = { row }; - value.setValues(objectRow); - lessThanEqualToExpression.evaluate(value); - } - - @Test public void testEvaluateForLessThanEqualToExpressionWithIsNullReturnTrue() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression right = new ColumnExpression("id", DataType.SHORT); - right.setColIndex(0); - lessThanEqualToExpression = new LessThanEqualToExpression(right, right); - RowImpl value = new RowImpl(); - Short[] row = { 15856 }; - Object objectRow[] = { row }; - value.setValues(objectRow); - - new MockUp<ExpressionResult>() { - @Mock public boolean isNull() { - return true; - } - }; - - new MockUp<ExpressionResult>() { - @Mock public Short getShort() { - return 15856; - } - }; - - ExpressionResult result = lessThanEqualToExpression.evaluate(value); - assertFalse(result.getBoolean()); - - } - - @Test public void testEvaluateForLessThanEqualToExpressionWithLeftAndRightDifferentDataType() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression left = new ColumnExpression("name", DataType.STRING); - left.setColIndex(0); - ColumnExpression right = new ColumnExpression("number", DataType.INT); - right.setColIndex(1); - lessThanEqualToExpression = new LessThanEqualToExpression(left, right); - RowImpl value = new RowImpl(); - String[] row = { "S" }; - Integer[] row1 = { 1450 }; - Object objectRow[] = { row, row1 }; - value.setValues(objectRow); - - new MockUp<ExpressionResult>() { - Boolean returnMockFlag = true; - - @Mock public Integer getInt() { - if (returnMockFlag) { - returnMockFlag = false; - return 84; - } else { - return 1450; - - } - - } - }; - - ExpressionResult result = lessThanEqualToExpression.evaluate(value); - assertTrue(result.getBoolean()); - } - - @Test public void testForLessThanEqualToExpressionWithGetString() throws Exception { - ColumnExpression right = new ColumnExpression("right_name", DataType.STRING); - right.setColIndex(0); - ColumnExpression left = new ColumnExpression("left_name", DataType.STRING); - left.setColIndex(0); - lessThanEqualToExpression = new LessThanEqualToExpression(left, right); - String expected_result = - "LessThanEqualTo(ColumnExpression(left_name),ColumnExpression(right_name))"; - String result = lessThanEqualToExpression.getString(); - assertEquals(expected_result, result); - } -} http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/952cf517/core/src/test/java/org/apache/carbondata/scan/expression/conditional/LessThanExpressionUnitTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/carbondata/scan/expression/conditional/LessThanExpressionUnitTest.java b/core/src/test/java/org/apache/carbondata/scan/expression/conditional/LessThanExpressionUnitTest.java deleted file mode 100644 index be3ab9c..0000000 --- a/core/src/test/java/org/apache/carbondata/scan/expression/conditional/LessThanExpressionUnitTest.java +++ /dev/null @@ -1,364 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.carbondata.scan.expression.conditional; - -import java.math.BigDecimal; -import java.sql.Timestamp; -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; - -import org.apache.carbondata.core.metadata.DataType; -import org.apache.carbondata.scan.expression.ColumnExpression; -import org.apache.carbondata.scan.expression.ExpressionResult; -import org.apache.carbondata.scan.expression.exception.FilterIllegalMemberException; -import org.apache.carbondata.scan.expression.exception.FilterUnsupportedException; -import org.apache.carbondata.scan.filter.intf.RowImpl; - -import mockit.Mock; -import mockit.MockUp; -import org.apache.spark.sql.types.Decimal; -import org.junit.Test; - -import static junit.framework.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -public class LessThanExpressionUnitTest { - static LessThanExpression lessThanExpression; - - @Test public void testEvaluateForLessThanExpressionWithStringDataType() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression left = new ColumnExpression("left_name", DataType.STRING); - left.setColIndex(0); - ColumnExpression right = new ColumnExpression("right_name", DataType.STRING); - right.setColIndex(1); - lessThanExpression = new LessThanExpression(left, right); - RowImpl value = new RowImpl(); - String[] row = { "First String Value" }; - String[] row1 = { "string1" }; - Object objectRow[] = { row, row1 }; - new MockUp<ExpressionResult>() { - Boolean returnMockFlag = true; - - @Mock public String getString() { - if (returnMockFlag) { - returnMockFlag = false; - return "First String Value"; - - } else { - return "string1"; - - } - - } - }; - value.setValues(objectRow); - ExpressionResult result = lessThanExpression.evaluate(value); - assertTrue(result.getBoolean()); - } - - @Test public void testEvaluateForLessThanExpressionWithShortDataType() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression right = new ColumnExpression("id", DataType.SHORT); - right.setColIndex(0); - ColumnExpression left = new ColumnExpression("id", DataType.SHORT); - left.setColIndex(1); - lessThanExpression = new LessThanExpression(left, right); - RowImpl value = new RowImpl(); - Short[] row = { 7052 }; - Short[] row1 = { 7450 }; - Object objectRow[] = { row, row1 }; - value.setValues(objectRow); - - new MockUp<ExpressionResult>() { - Boolean returnMockFlag = true; - - @Mock public Short getShort() { - if (returnMockFlag) { - returnMockFlag = false; - return 7052; - - } else { - return 7450; - - } - - } - }; - - ExpressionResult result = lessThanExpression.evaluate(value); - assertTrue(result.getBoolean()); - - } - - @Test public void testEvaluateForLessThanExpressionWithDoubleDataType() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression right = new ColumnExpression("right_contact", DataType.DOUBLE); - right.setColIndex(0); - ColumnExpression left = new ColumnExpression("left_contact", DataType.DOUBLE); - left.setColIndex(1); - lessThanExpression = new LessThanExpression(left, right); - RowImpl value = new RowImpl(); - Double[] row = { 2087D }; - Double[] row1 = { 4454D }; - Object objectRow[] = { row1, row }; - value.setValues(objectRow); - - new MockUp<ExpressionResult>() { - Boolean returnMockFlag = true; - - @Mock public Double getDouble() { - if (returnMockFlag) { - returnMockFlag = false; - return 2087D; - - } else { - return 4454D; - - } - - } - }; - - ExpressionResult result = lessThanExpression.evaluate(value); - assertTrue(result.getBoolean()); - } - - @Test public void testEvaluateForLessThanExpressionWithIntDataType() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression right = new ColumnExpression("right_number", DataType.INT); - right.setColIndex(0); - ColumnExpression left = new ColumnExpression("left_number", DataType.INT); - left.setColIndex(1); - lessThanExpression = new LessThanExpression(left, right); - RowImpl value = new RowImpl(); - Integer[] row = { 1550 }; - Integer[] row1 = { 1420 }; - Object objectRow[] = { row, row1 }; - value.setValues(objectRow); - - new MockUp<ExpressionResult>() { - Boolean returnMockFlag = true; - - @Mock public Integer getInt() { - if (returnMockFlag) { - returnMockFlag = false; - return 1420; - - } else { - return 1550; - - } - - } - }; - - ExpressionResult result = lessThanExpression.evaluate(value); - assertTrue(result.getBoolean()); - } - - @Test public void testEvaluateForLessThanExpressionWithTimestampDataType() - throws FilterUnsupportedException, FilterIllegalMemberException { - try { - ColumnExpression left = new ColumnExpression("timestamp", DataType.TIMESTAMP); - left.setColIndex(0); - ColumnExpression right = new ColumnExpression("timestamp", DataType.TIMESTAMP); - right.setColIndex(1); - - lessThanExpression = new LessThanExpression(left, right); - - RowImpl value = new RowImpl(); - - DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); - - Date date = dateFormat.parse("23/09/2007"); - long time = date.getTime(); - Timestamp[] row = { new Timestamp(time) }; - - Date date1 = dateFormat.parse("24/09/2007"); - long time1 = date1.getTime(); - Timestamp[] row1 = { new Timestamp(time1) }; - - Object objectRow[] = { row, row1 }; - value.setValues(objectRow); - - new MockUp<ExpressionResult>() { - Boolean returnMockFlag = true; - - @Mock public Long getTime() { - if (returnMockFlag) { - returnMockFlag = false; - return 1190505600L; - } else { - return 1190592000L; - } - } - }; - - ExpressionResult result = lessThanExpression.evaluate(value); - assertTrue(result.getBoolean()); - } catch (ParseException e) { - System.out.println("Error while parsing " + e.getMessage()); - } - } - - @Test public void testEvaluateForLessThanExpressionWithLongDataType() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression right = new ColumnExpression("contact", DataType.LONG); - right.setColIndex(0); - ColumnExpression left = new ColumnExpression("contact", DataType.LONG); - left.setColIndex(1); - lessThanExpression = new LessThanExpression(left, right); - RowImpl value = new RowImpl(); - Long[] row = { 14523656L }; - Long[] row1 = { 12456325L }; - Object objectRow[] = { row1, row }; - value.setValues(objectRow); - - new MockUp<ExpressionResult>() { - Boolean returnMockFlag = true; - - @Mock public Long getLong() { - if (returnMockFlag) { - returnMockFlag = false; - return 12456325L; - } else { - return 14523656L; - } - } - }; - - ExpressionResult result = lessThanExpression.evaluate(value); - assertTrue(result.getBoolean()); - } - - @Test public void testEvaluateForLessThanExpressionWithDecimalDataType() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression right = new ColumnExpression("contact", DataType.DECIMAL); - right.setColIndex(0); - ColumnExpression left = new ColumnExpression("contact", DataType.DECIMAL); - left.setColIndex(1); - lessThanExpression = new LessThanExpression(left, right); - RowImpl value = new RowImpl(); - Decimal[] row = new Decimal[] { Decimal.apply(256324.0) }; - Decimal[] row1 = new Decimal[] { Decimal.apply(123451245.0) }; - Object objectRow[] = { row1, row }; - value.setValues(objectRow); - - new MockUp<ExpressionResult>() { - Boolean returnMockFlag = true; - - @Mock public BigDecimal getDecimal() { - if (returnMockFlag) { - returnMockFlag = false; - return new BigDecimal(256324.0); - } else { - return new BigDecimal(123451245.0); - } - } - }; - - ExpressionResult result = lessThanExpression.evaluate(value); - assertTrue(result.getBoolean()); - } - - @Test(expected = FilterUnsupportedException.class) public void testForLessThanExpressionWithDefaultCase() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression right = new ColumnExpression("contact", DataType.BOOLEAN); - right.setColIndex(0); - lessThanExpression = new LessThanExpression(right, right); - RowImpl value = new RowImpl(); - Boolean[] row = { true }; - Object objectRow[] = { row }; - value.setValues(objectRow); - lessThanExpression.evaluate(value); - } - - @Test public void testEvaluateForLessThanExpressionWithIsNullReturnTrue() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression right = new ColumnExpression("id", DataType.SHORT); - right.setColIndex(0); - lessThanExpression = new LessThanExpression(right, right); - RowImpl value = new RowImpl(); - Short[] row = { 15 }; - Object objectRow[] = { row }; - value.setValues(objectRow); - - new MockUp<ExpressionResult>() { - @Mock public boolean isNull() { - return true; - } - }; - - new MockUp<ExpressionResult>() { - @Mock public Short getShort() { - return 15; - } - }; - - ExpressionResult result = lessThanExpression.evaluate(value); - assertFalse(result.getBoolean()); - - } - - @Test public void testEvaluateForLessThanExpressionWithLeftAndRightDifferentDataType() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression left = new ColumnExpression("name", DataType.STRING); - left.setColIndex(0); - ColumnExpression right = new ColumnExpression("number", DataType.INT); - right.setColIndex(1); - lessThanExpression = new LessThanExpression(left, right); - RowImpl value = new RowImpl(); - String[] row = { "S" }; - Integer[] row1 = { 1864 }; - Object objectRow[] = { row, row1 }; - value.setValues(objectRow); - - new MockUp<ExpressionResult>() { - Boolean returnMockFlag = true; - - @Mock public Integer getInt() { - if (returnMockFlag) { - returnMockFlag = false; - return 84; - } else { - return 1864; - - } - - } - }; - - ExpressionResult result = lessThanExpression.evaluate(value); - assertTrue(result.getBoolean()); - } - - @Test public void testForLessThanExpressionWithGetString() throws Exception { - ColumnExpression right = new ColumnExpression("right_name", DataType.STRING); - right.setColIndex(0); - ColumnExpression left = new ColumnExpression("left_name", DataType.STRING); - left.setColIndex(0); - lessThanExpression = new LessThanExpression(left, right); - String expected_result = "LessThan(ColumnExpression(left_name),ColumnExpression(right_name))"; - String result = lessThanExpression.getString(); - assertEquals(expected_result, result); - } -} http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/952cf517/core/src/test/java/org/apache/carbondata/scan/expression/conditional/ListExpressionUnitTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/carbondata/scan/expression/conditional/ListExpressionUnitTest.java b/core/src/test/java/org/apache/carbondata/scan/expression/conditional/ListExpressionUnitTest.java deleted file mode 100644 index 9722339..0000000 --- a/core/src/test/java/org/apache/carbondata/scan/expression/conditional/ListExpressionUnitTest.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.carbondata.scan.expression.conditional; - -import java.util.List; - -import org.apache.carbondata.core.metadata.DataType; -import org.apache.carbondata.scan.expression.ColumnExpression; -import org.apache.carbondata.scan.expression.Expression; -import org.apache.carbondata.scan.expression.ExpressionResult; -import org.apache.carbondata.scan.expression.exception.FilterIllegalMemberException; -import org.apache.carbondata.scan.expression.exception.FilterUnsupportedException; -import org.apache.carbondata.scan.filter.intf.RowImpl; - -import org.junit.Test; - -import java.util.ArrayList; - -import static org.hamcrest.core.Is.is; -import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - -public class ListExpressionUnitTest { - - static ListExpression listExpression; - - @Test public void test() throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression left = new ColumnExpression("left_name", DataType.STRING); - left.setColIndex(0); - ColumnExpression right = new ColumnExpression("right_name", DataType.STRING); - right.setColIndex(1); - - List<Expression> children = new ArrayList<>(); - children.add(left); - children.add(right); - - listExpression = new ListExpression(children); - RowImpl value = new RowImpl(); - String row = "Row is for left"; - String row1 = "I am row 1"; - Object objectRow[] = { row, row1 }; - value.setValues(objectRow); - String expected_value = "Row is for left"; - ExpressionResult result = listExpression.evaluate(value); - assertThat(expected_value, is(equalTo(result.getList().get(0).getString()))); - } -} http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/952cf517/core/src/test/java/org/apache/carbondata/scan/expression/conditional/NotEqualsExpressionUnitTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/carbondata/scan/expression/conditional/NotEqualsExpressionUnitTest.java b/core/src/test/java/org/apache/carbondata/scan/expression/conditional/NotEqualsExpressionUnitTest.java deleted file mode 100644 index 8a1c814..0000000 --- a/core/src/test/java/org/apache/carbondata/scan/expression/conditional/NotEqualsExpressionUnitTest.java +++ /dev/null @@ -1,406 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.carbondata.scan.expression.conditional; - -import java.math.BigDecimal; -import java.sql.Timestamp; -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; - -import org.apache.carbondata.core.metadata.DataType; -import org.apache.carbondata.scan.expression.ColumnExpression; -import org.apache.carbondata.scan.expression.ExpressionResult; -import org.apache.carbondata.scan.expression.exception.FilterIllegalMemberException; -import org.apache.carbondata.scan.expression.exception.FilterUnsupportedException; -import org.apache.carbondata.scan.filter.intf.RowImpl; - -import mockit.Mock; -import mockit.MockUp; -import org.apache.spark.sql.types.Decimal; -import org.junit.Test; - -import static junit.framework.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -public class NotEqualsExpressionUnitTest { - - static NotEqualsExpression notEqualsExpression; - - @Test public void testEvaluateForNotEqualsExpressionWithBothStringISSame() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression left = new ColumnExpression("left_name", DataType.STRING); - left.setColIndex(0); - ColumnExpression right = new ColumnExpression("right_name", DataType.STRING); - right.setColIndex(1); - notEqualsExpression = new NotEqualsExpression(left, right); - RowImpl value = new RowImpl(); - String[] row = { "string1" }; - String[] row1 = { "string2" }; - Object objectRow[] = { row, row1 }; - - new MockUp<ExpressionResult>() { - Boolean returnMockFlag = true; - - @Mock public String getString() { - if (returnMockFlag) { - returnMockFlag = false; - return "string1"; - - } else { - return "string2"; - } - } - }; - - value.setValues(objectRow); - ExpressionResult result = notEqualsExpression.evaluate(value); - assertTrue(result.getBoolean()); - } - - @Test public void testEvaluateForNotEqualsExpressionWithShortDataType() - throws FilterUnsupportedException, FilterIllegalMemberException { - - ColumnExpression left = new ColumnExpression("left_id", DataType.SHORT); - left.setColIndex(0); - ColumnExpression right = new ColumnExpression("right_id", DataType.SHORT); - right.setColIndex(1); - notEqualsExpression = new NotEqualsExpression(left, right); - RowImpl value = new RowImpl(); - Short[] row = { 15 }; - Short[] row1 = { 16 }; - Object objectRow[] = { row, row1 }; - value.setValues(objectRow); - - new MockUp<ExpressionResult>() { - Boolean returnMockFlag = true; - - @Mock public Short getShort() { - if (returnMockFlag) { - returnMockFlag = false; - return 15; - - } else { - return 16; - - } - - } - }; - - ExpressionResult result = notEqualsExpression.evaluate(value); - assertTrue(result.getBoolean()); - - } - - @Test public void testEvaluateForNotEqualsExpressionWithIntDataType() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression right = new ColumnExpression("right_number", DataType.INT); - right.setColIndex(1); - ColumnExpression left = new ColumnExpression("left_number", DataType.INT); - left.setColIndex(0); - notEqualsExpression = new NotEqualsExpression(left, right); - RowImpl value = new RowImpl(); - Integer[] row = { 15 }; - Integer[] row1 = { 16 }; - Object objectRow[] = { row, row1 }; - value.setValues(objectRow); - - new MockUp<ExpressionResult>() { - Boolean returnMockFlag = true; - - @Mock public Integer getInt() { - if (returnMockFlag) { - returnMockFlag = false; - return 15; - - } else { - return 16; - } - } - }; - - ExpressionResult result = notEqualsExpression.evaluate(value); - assertTrue(result.getBoolean()); - } - - @Test public void testEvaluateForNotEqualsExpressionWithDoubleDataType() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression right = new ColumnExpression("right_contact", DataType.DOUBLE); - right.setColIndex(1); - ColumnExpression left = new ColumnExpression("left_contact", DataType.DOUBLE); - left.setColIndex(0); - notEqualsExpression = new NotEqualsExpression(left, right); - RowImpl value = new RowImpl(); - Double[] row = { 445.2D }; - Double[] row1 = { 452.08D }; - Object objectRow[] = { row, row1 }; - value.setValues(objectRow); - - new MockUp<ExpressionResult>() { - Boolean returnMockFlag = true; - - @Mock public Double getDouble() { - if (returnMockFlag) { - returnMockFlag = false; - return 445.2D; - - } else { - return 452.08D; - } - } - }; - - ExpressionResult result = notEqualsExpression.evaluate(value); - assertTrue(result.getBoolean()); - } - - @Test public void testEvaluateForNotEqualsExpressionWithLongDataType() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression right = new ColumnExpression("right_contact", DataType.LONG); - right.setColIndex(1); - ColumnExpression left = new ColumnExpression("left_contact", DataType.LONG); - left.setColIndex(0); - notEqualsExpression = new NotEqualsExpression(left, right); - RowImpl value = new RowImpl(); - Long[] row = { 1234567654321L }; - Long[] row1 = { 12345676541L }; - Object objectRow[] = { row, row1 }; - value.setValues(objectRow); - - new MockUp<ExpressionResult>() { - Boolean returnMockFlag = true; - - @Mock public Long getLong() { - if (returnMockFlag) { - returnMockFlag = false; - return 1234567654321L; - } else { - return 12345676541L; - } - } - }; - - ExpressionResult result = notEqualsExpression.evaluate(value); - assertTrue(result.getBoolean()); - } - - @Test public void testEvaluateForNotEqualsExpressionWithTimestampDataType() - throws FilterUnsupportedException, FilterIllegalMemberException { - try { - ColumnExpression left = new ColumnExpression("left_timestamp", DataType.TIMESTAMP); - left.setColIndex(0); - ColumnExpression right = new ColumnExpression("right_timestamp", DataType.TIMESTAMP); - right.setColIndex(1); - - notEqualsExpression = new NotEqualsExpression(left, right); - - RowImpl value = new RowImpl(); - - DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); - - Date date = dateFormat.parse("23/09/2007"); - long time = date.getTime(); - Timestamp[] row = { new Timestamp(time) }; - - Date date1 = dateFormat.parse("24/09/2007"); - long time1 = date1.getTime(); - Timestamp[] row1 = { new Timestamp(time1) }; - - Object objectRow[] = { row1, row }; - value.setValues(objectRow); - - new MockUp<ExpressionResult>() { - Boolean returnMockFlag = true; - - @Mock public Long getTime() { - if (returnMockFlag) { - returnMockFlag = false; - return 1190592000L; - } else { - return 1190505600L; - } - } - }; - - ExpressionResult result = notEqualsExpression.evaluate(value); - assertTrue(result.getBoolean()); - } catch (ParseException e) { - System.out.println("Error while parsing " + e.getMessage()); - } - } - - @Test(expected = FilterUnsupportedException.class) public void testForNotEqualsExpressionWithDefaultCase() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression right = new ColumnExpression("contact", DataType.BOOLEAN); - right.setColIndex(0); - notEqualsExpression = new NotEqualsExpression(right, right); - RowImpl value = new RowImpl(); - Boolean[] row = { true }; - Object objectRow[] = { row }; - value.setValues(objectRow); - notEqualsExpression.evaluate(value); - } - - @Test public void testEvaluateWithForNotEqualsExpressionDecimalDataType() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression right = new ColumnExpression("contact", DataType.DECIMAL); - right.setColIndex(1); - ColumnExpression left = new ColumnExpression("contact", DataType.DECIMAL); - left.setColIndex(0); - notEqualsExpression = new NotEqualsExpression(left, right); - RowImpl value = new RowImpl(); - Decimal[] row = new Decimal[] { Decimal.apply(12345.0) }; - Decimal[] row1 = new Decimal[] { Decimal.apply(1235445.0) }; - Object objectRow[] = { row, row1 }; - value.setValues(objectRow); - - new MockUp<ExpressionResult>() { - Boolean returnMockFlag = true; - - @Mock public BigDecimal getDecimal() { - if (returnMockFlag) { - returnMockFlag = false; - return new BigDecimal(12345.0); - } else { - return new BigDecimal(1235445.0); - } - } - }; - - ExpressionResult result = notEqualsExpression.evaluate(value); - assertTrue(result.getBoolean()); - } - - @Test public void testEvaluateForNotEqualsExpressionWithIsNullReturnTrue() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression right = new ColumnExpression("id", DataType.SHORT); - right.setColIndex(0); - notEqualsExpression = new NotEqualsExpression(right, right); - RowImpl value = new RowImpl(); - Short[] row = { 150 }; - Object objectRow[] = { row }; - value.setValues(objectRow); - - new MockUp<ExpressionResult>() { - @Mock public boolean isNull() { - return true; - } - }; - - new MockUp<ExpressionResult>() { - @Mock public Short getShort() { - return 150; - } - }; - - ExpressionResult result = notEqualsExpression.evaluate(value); - assertFalse(result.getBoolean()); - - } - - @Test public void testEvaluateForNotEqualsExpressionWithLeftAndRightDifferentDataType() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression left = new ColumnExpression("name", DataType.STRING); - left.setColIndex(0); - ColumnExpression right = new ColumnExpression("number", DataType.INT); - right.setColIndex(1); - notEqualsExpression = new NotEqualsExpression(left, right); - RowImpl value = new RowImpl(); - String[] row1 = { "S" }; - Integer[] row = { 14 }; - Object objectRow[] = { row, row1 }; - value.setValues(objectRow); - - new MockUp<ExpressionResult>() { - Boolean returnMockFlag = true; - - @Mock public Integer getInt() { - if (returnMockFlag) { - returnMockFlag = false; - return 84; - } else { - return 14; - } - } - }; - - ExpressionResult result = notEqualsExpression.evaluate(value); - assertTrue(result.getBoolean()); - } - - @Test public void testForNotEqualsExpressionWithGetString() throws Exception { - ColumnExpression right = new ColumnExpression("right_name", DataType.STRING); - ColumnExpression left = new ColumnExpression("left_name", DataType.STRING); - notEqualsExpression = new NotEqualsExpression(left, right); - String expected_result = "NotEquals(ColumnExpression(left_name),ColumnExpression(right_name))"; - String result = notEqualsExpression.getString(); - assertEquals(expected_result, result); - } - - @Test public void testEvaluateForNotEqualsExpressionWithNullWhileCreatingObject() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression right = new ColumnExpression("id", DataType.SHORT); - right.setColIndex(0); - notEqualsExpression = new NotEqualsExpression(right, right, false); - RowImpl value = new RowImpl(); - Short[] row = { 15 }; - Object objectRow[] = { row }; - value.setValues(objectRow); - - new MockUp<ExpressionResult>() { - @Mock public boolean isNull() { - return true; - } - }; - - new MockUp<ExpressionResult>() { - @Mock public Short getShort() { - return 15; - } - }; - - ExpressionResult result = notEqualsExpression.evaluate(value); - assertEquals(DataType.BOOLEAN, result.getDataType()); - - } - - @Test public void testEvaluateForNotEqualsExpressionWithNullISTureWhileCreatingObject() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression right = new ColumnExpression("id", DataType.SHORT); - right.setColIndex(0); - notEqualsExpression = new NotEqualsExpression(right, right, true); - RowImpl value = new RowImpl(); - Short[] row = { 15 }; - Object objectRow[] = { row }; - value.setValues(objectRow); - - new MockUp<ExpressionResult>() { - @Mock public boolean isNull() { - return true; - } - }; - - ExpressionResult result = notEqualsExpression.evaluate(value); - assertEquals(DataType.BOOLEAN, result.getDataType()); - - } -} http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/952cf517/core/src/test/java/org/apache/carbondata/scan/expression/conditional/NotInExpressionUnitTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/carbondata/scan/expression/conditional/NotInExpressionUnitTest.java b/core/src/test/java/org/apache/carbondata/scan/expression/conditional/NotInExpressionUnitTest.java deleted file mode 100644 index 44a144c..0000000 --- a/core/src/test/java/org/apache/carbondata/scan/expression/conditional/NotInExpressionUnitTest.java +++ /dev/null @@ -1,275 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.carbondata.scan.expression.conditional; - -import java.math.BigDecimal; -import java.sql.Timestamp; -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; - -import org.apache.carbondata.core.metadata.DataType; -import org.apache.carbondata.scan.expression.ColumnExpression; -import org.apache.carbondata.scan.expression.ExpressionResult; -import org.apache.carbondata.scan.expression.exception.FilterIllegalMemberException; -import org.apache.carbondata.scan.expression.exception.FilterUnsupportedException; -import org.apache.carbondata.scan.filter.intf.RowImpl; - -import mockit.Mock; -import mockit.MockUp; -import org.apache.spark.sql.types.Decimal; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -public class NotInExpressionUnitTest { - - static NotInExpression notInExpression; - - @Test public void testEvaluateForNotInExpressionWithString() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression left = new ColumnExpression("left_name", DataType.STRING); - left.setColIndex(0); - ColumnExpression right = new ColumnExpression("right_name", DataType.STRING); - right.setColIndex(1); - notInExpression = new NotInExpression(left, right); - RowImpl value = new RowImpl(); - String row = "Row is for left"; - String row1 = "I am row 1"; - Object objectRow[] = { row, row1 }; - - new MockUp<ExpressionResult>() { - - @Mock public DataType getDataType() { - return DataType.STRING; - } - - @Mock public String getString() { - return "string1"; - } - }; - - value.setValues(objectRow); - ExpressionResult result = notInExpression.evaluate(value); - assertTrue(result.getBoolean()); - } - - @Test public void testEvaluateForNotInExpressionWithShortDataType() - throws FilterUnsupportedException, FilterIllegalMemberException { - - ColumnExpression left = new ColumnExpression("left_id", DataType.SHORT); - left.setColIndex(0); - ColumnExpression right = new ColumnExpression("right_id", DataType.SHORT); - right.setColIndex(1); - notInExpression = new NotInExpression(left, right); - RowImpl value = new RowImpl(); - Short row = 15653; - Short row1 = 15582; - Object objectRow[] = { row, row1 }; - value.setValues(objectRow); - - new MockUp<ExpressionResult>() { - @Mock public Short getShort() { - return 15582; - } - }; - - ExpressionResult result = notInExpression.evaluate(value); - assertEquals(result.getDataType(), DataType.BOOLEAN); - - } - - @Test public void testEvaluateForNotInExpressionWithIntDataType() - throws FilterUnsupportedException, FilterIllegalMemberException { - - ColumnExpression left = new ColumnExpression("left_id", DataType.INT); - left.setColIndex(0); - ColumnExpression right = new ColumnExpression("right_id", DataType.INT); - right.setColIndex(1); - notInExpression = new NotInExpression(left, right); - RowImpl value = new RowImpl(); - Integer row = 150569; - Integer row1 = 15052; - Object objectRow[] = { row, row1 }; - value.setValues(objectRow); - - new MockUp<ExpressionResult>() { - @Mock public Integer getInt() { - return 15052; - } - }; - - ExpressionResult result = notInExpression.evaluate(value); - assertEquals(result.getDataType(), DataType.BOOLEAN); - - } - - @Test public void testEvaluateForNotInExpressionWithDoubleDataType() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression left = new ColumnExpression("left_contact", DataType.DOUBLE); - left.setColIndex(0); - ColumnExpression right = new ColumnExpression("right_contact", DataType.DOUBLE); - right.setColIndex(1); - notInExpression = new NotInExpression(left, right); - RowImpl value = new RowImpl(); - Double row = 44521D; - Double row1 = 44521.023D; - Object objectRow[] = { row, row1 }; - value.setValues(objectRow); - - new MockUp<ExpressionResult>() { - @Mock public Double getDouble() { - return 44521.023D; - } - }; - - ExpressionResult result = notInExpression.evaluate(value); - assertTrue(result.getBoolean()); - } - - @Test public void testEvaluateForNotInExpressionWithLongDataType() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression left = new ColumnExpression("left_contact", DataType.LONG); - left.setColIndex(0); - ColumnExpression right = new ColumnExpression("right_contact", DataType.LONG); - right.setColIndex(1); - notInExpression = new NotInExpression(left, right); - RowImpl value = new RowImpl(); - Long row = 123456256325632L; - Long row1 = 156212456245556L; - Object objectRow[] = { row, row1 }; - value.setValues(objectRow); - - new MockUp<ExpressionResult>() { - @Mock public Long getLong() { - return 156212456245556L; - } - }; - - ExpressionResult result = notInExpression.evaluate(value); - assertTrue(result.getBoolean()); - } - - @Test public void testEvaluateForNotInExpressionWithTimestampDataType() - throws FilterUnsupportedException, FilterIllegalMemberException { - try { - ColumnExpression left = new ColumnExpression("left_timestamp", DataType.TIMESTAMP); - left.setColIndex(0); - ColumnExpression right = new ColumnExpression("right_timestamp", DataType.TIMESTAMP); - right.setColIndex(1); - notInExpression = new NotInExpression(right, right); - - RowImpl value = new RowImpl(); - DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd"); - Date date = dateFormat.parse("2007/03/03"); - - long time = date.getTime(); - - Timestamp row = new Timestamp(time); - Timestamp row1 = new Timestamp(time); - Object objectRow[] = { row, row1 }; - value.setValues(objectRow); - - new MockUp<ExpressionResult>() { - @Mock public Long getTime() { - return 1172860200000L; - } - }; - - ExpressionResult result = notInExpression.evaluate(value); - assertTrue(result.getBoolean()); - } catch (ParseException e) { - System.out.println("Error while parsing " + e.getMessage()); - } - } - - @Test public void testEvaluateForNotInExpressionWithDecimalDataType() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression left = new ColumnExpression("left_contact", DataType.DECIMAL); - left.setColIndex(0); - ColumnExpression right = new ColumnExpression("right_contact", DataType.DECIMAL); - right.setColIndex(1); - notInExpression = new NotInExpression(left, right); - RowImpl value = new RowImpl(); - Decimal row = Decimal.apply(123452154.0); - Decimal row1 = Decimal.apply(1234521215454.0); - Object objectRow[] = { row, row1 }; - value.setValues(objectRow); - - new MockUp<ExpressionResult>() { - @Mock public BigDecimal getDecimal() { - return new BigDecimal(1234521215454.0); - } - }; - - ExpressionResult result = notInExpression.evaluate(value); - assertTrue(result.getBoolean()); - } - - @Test(expected = FilterUnsupportedException.class) public void testDefaultCaseForNotInExpression() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression left = new ColumnExpression("contact", DataType.BOOLEAN); - left.setColIndex(0); - ColumnExpression right = new ColumnExpression("contact", DataType.BOOLEAN); - right.setColIndex(1); - notInExpression = new NotInExpression(left, right); - RowImpl value = new RowImpl(); - Boolean row = true; - Boolean row1 = true; - Object objectRow[] = { row, row1 }; - value.setValues(objectRow); - notInExpression.evaluate(value); - } - - @Test public void testForNotInExpressionWithGetString() throws Exception { - ColumnExpression left = new ColumnExpression("left_name", DataType.STRING); - left.setColIndex(0); - ColumnExpression right = new ColumnExpression("right_name", DataType.STRING); - right.setColIndex(1); - notInExpression = new NotInExpression(left, right); - String expected_result = "NOT IN(ColumnExpression(left_name),ColumnExpression(right_name))"; - String result = notInExpression.getString(); - assertEquals(expected_result, result); - } - @Test public void testEvaluateForNotInExpressionWithLeftAndRightDifferentDataType() - throws FilterUnsupportedException, FilterIllegalMemberException { - ColumnExpression right = new ColumnExpression("name", DataType.STRING); - right.setColIndex(0); - ColumnExpression left = new ColumnExpression("number", DataType.INT); - left.setColIndex(1); - notInExpression = new NotInExpression(left, right); - RowImpl value = new RowImpl(); - String row1 = "String1"; - Integer row = 14523213; - Object objectRow[] = { row1, row }; - value.setValues(objectRow); - - new MockUp<ExpressionResult>() { - @Mock public Integer getInt() { - return 145232130; - } - }; - - ExpressionResult result = notInExpression.evaluate(value); - assertTrue(result.getBoolean()); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/952cf517/core/src/test/java/org/apache/carbondata/scan/expression/logical/AndExpressionTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/carbondata/scan/expression/logical/AndExpressionTest.java b/core/src/test/java/org/apache/carbondata/scan/expression/logical/AndExpressionTest.java deleted file mode 100644 index 2f15f50..0000000 --- a/core/src/test/java/org/apache/carbondata/scan/expression/logical/AndExpressionTest.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.carbondata.scan.expression.logical; - -import org.apache.carbondata.core.metadata.DataType; -import org.apache.carbondata.scan.expression.ColumnExpression; -import org.apache.carbondata.scan.expression.ExpressionResult; -import org.apache.carbondata.scan.expression.exception.FilterIllegalMemberException; -import org.apache.carbondata.scan.expression.exception.FilterUnsupportedException; -import org.apache.carbondata.scan.filter.intf.RowImpl; -import org.apache.carbondata.scan.filter.intf.RowIntf; - -import mockit.Mock; -import mockit.MockUp; -import org.junit.Before; -import org.junit.Test; - -import static junit.framework.TestCase.assertTrue; -import static org.junit.Assert.assertEquals; - -public class AndExpressionTest { - - private AndExpression andExpression; - - @Before public void setUp() { - ColumnExpression leftExpression = new ColumnExpression("IMEI", DataType.BOOLEAN); - ColumnExpression rightExpression = new ColumnExpression("IMEI", DataType.BOOLEAN); - andExpression = new AndExpression(leftExpression, rightExpression); - } - - @Test(expected = Exception.class) public void testEvaluateForDefault() - throws FilterUnsupportedException, FilterIllegalMemberException { - RowImpl rowImpl = new RowImpl(); - rowImpl.setValues(new Boolean[] { true }); - final ExpressionResult expressionResult = new ExpressionResult(DataType.STRING, "test"); - new MockUp<ColumnExpression>() { - @Mock public ExpressionResult evaluate(RowIntf value) - throws FilterUnsupportedException, FilterIllegalMemberException { - return expressionResult; - } - }; - andExpression.evaluate(rowImpl); - } - - @Test public void testEvaluate() throws FilterUnsupportedException, FilterIllegalMemberException { - RowImpl rowImpl = new RowImpl(); - rowImpl.setValues(new Boolean[] { false }); - final ExpressionResult expressionResult = new ExpressionResult(DataType.BOOLEAN, "test"); - new MockUp<ColumnExpression>() { - @Mock public ExpressionResult evaluate(RowIntf value) - throws FilterUnsupportedException, FilterIllegalMemberException { - return expressionResult; - } - }; - ExpressionResult actualValue = andExpression.evaluate(rowImpl); - assertTrue(actualValue instanceof ExpressionResult); - } - - @Test public void testGetString() { - String actualValue = andExpression.getString(); - String expectedValue = "And(ColumnExpression(IMEI),ColumnExpression(IMEI))"; - assertEquals(expectedValue, actualValue); - } -} http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/952cf517/core/src/test/java/org/apache/carbondata/scan/expression/logical/FalseExpressionTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/carbondata/scan/expression/logical/FalseExpressionTest.java b/core/src/test/java/org/apache/carbondata/scan/expression/logical/FalseExpressionTest.java deleted file mode 100644 index 6ec0b59..0000000 --- a/core/src/test/java/org/apache/carbondata/scan/expression/logical/FalseExpressionTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.carbondata.scan.expression.logical; - -import org.apache.carbondata.core.metadata.DataType; -import org.apache.carbondata.scan.expression.ColumnExpression; -import org.apache.carbondata.scan.expression.ExpressionResult; -import org.apache.carbondata.scan.expression.exception.FilterIllegalMemberException; -import org.apache.carbondata.scan.expression.exception.FilterUnsupportedException; -import org.apache.carbondata.scan.filter.intf.RowImpl; - -import org.junit.Before; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -public class FalseExpressionTest { - private FalseExpression falseExpression; - - @Before public void setUp() { - ColumnExpression columnExpression = new ColumnExpression("IMEI", DataType.BOOLEAN); - falseExpression = new FalseExpression(columnExpression); - } - - @Test public void testEvaluate() throws FilterUnsupportedException, FilterIllegalMemberException { - RowImpl rowImpl = new RowImpl(); - rowImpl.setValues(new Boolean[] { true }); - ExpressionResult actualValue = falseExpression.evaluate(rowImpl); - assertEquals(new ExpressionResult(DataType.BOOLEAN, false), actualValue); - } -} http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/952cf517/core/src/test/java/org/apache/carbondata/scan/expression/logical/OrExpressionTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/carbondata/scan/expression/logical/OrExpressionTest.java b/core/src/test/java/org/apache/carbondata/scan/expression/logical/OrExpressionTest.java deleted file mode 100644 index 44b24e5..0000000 --- a/core/src/test/java/org/apache/carbondata/scan/expression/logical/OrExpressionTest.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.carbondata.scan.expression.logical; - -import org.apache.carbondata.core.metadata.DataType; -import org.apache.carbondata.scan.expression.ColumnExpression; -import org.apache.carbondata.scan.expression.ExpressionResult; -import org.apache.carbondata.scan.expression.exception.FilterIllegalMemberException; -import org.apache.carbondata.scan.expression.exception.FilterUnsupportedException; -import org.apache.carbondata.scan.filter.intf.RowImpl; -import org.apache.carbondata.scan.filter.intf.RowIntf; - -import mockit.Mock; -import mockit.MockUp; -import org.junit.Before; -import org.junit.Test; - -import static junit.framework.TestCase.assertTrue; -import static org.junit.Assert.assertEquals; - -public class OrExpressionTest { - private OrExpression orExpression; - - @Before public void setUp() { - ColumnExpression leftExpression = new ColumnExpression("IMEI", DataType.BOOLEAN); - ColumnExpression rightExpression = new ColumnExpression("IMEI", DataType.BOOLEAN); - orExpression = new OrExpression(leftExpression, rightExpression); - } - - @Test public void testGetString() { - String actualValue = orExpression.getString(); - String expectedValue = "Or(ColumnExpression(IMEI),ColumnExpression(IMEI))"; - assertEquals(expectedValue, actualValue); - } - - @Test public void testEvaluate() throws FilterIllegalMemberException, FilterUnsupportedException { - RowImpl rowImpl = new RowImpl(); - rowImpl.setValues(new Boolean[] { false }); - final ExpressionResult expressionResult = new ExpressionResult(DataType.BOOLEAN, "test"); - new MockUp<ColumnExpression>() { - @Mock public ExpressionResult evaluate(RowIntf value) { - return expressionResult; - } - }; - - assertTrue(orExpression.evaluate(rowImpl) instanceof ExpressionResult); - } - - @Test(expected = Exception.class) public void testEvaluateForDefault() - throws FilterUnsupportedException, FilterIllegalMemberException { - RowImpl rowImpl = new RowImpl(); - rowImpl.setValues(new Boolean[] { true }); - final ExpressionResult expressionResult = new ExpressionResult(DataType.STRING, "test"); - new MockUp<ColumnExpression>() { - @Mock public ExpressionResult evaluate(RowIntf value) - throws FilterUnsupportedException, FilterIllegalMemberException { - return expressionResult; - } - }; - orExpression.evaluate(rowImpl); - } -}