PHOENIX-2684 LiteralExpression.getBooleanLiteralExpression should compare with .equals() (Julian Eberius)
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/60ef7cd5 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/60ef7cd5 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/60ef7cd5 Branch: refs/heads/calcite Commit: 60ef7cd54e26fd1635e503c7d7981ba2cdf4c6fc Parents: 43b34da Author: James Taylor <jtay...@salesforce.com> Authored: Mon Feb 15 09:50:43 2016 -0800 Committer: James Taylor <jtay...@salesforce.com> Committed: Mon Feb 15 10:14:58 2016 -0800 ---------------------------------------------------------------------- .../phoenix/end2end/CompareDecimalToLongIT.java | 241 ------------------ .../apache/phoenix/end2end/PrimitiveTypeIT.java | 245 +++++++++++++++++++ .../phoenix/expression/LiteralExpression.java | 2 +- .../java/org/apache/phoenix/query/BaseTest.java | 14 +- 4 files changed, 252 insertions(+), 250 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/60ef7cd5/phoenix-core/src/it/java/org/apache/phoenix/end2end/CompareDecimalToLongIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CompareDecimalToLongIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CompareDecimalToLongIT.java deleted file mode 100644 index 3a358c4..0000000 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CompareDecimalToLongIT.java +++ /dev/null @@ -1,241 +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.phoenix.end2end; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.util.Properties; - -import org.apache.phoenix.util.PhoenixRuntime; -import org.junit.Test; - - -public class CompareDecimalToLongIT extends BaseClientManagedTimeIT { - protected static void initTableValues(byte[][] splits, long ts) throws Exception { - ensureTableCreated(getUrl(),"LongInKeyTest",splits, ts-2); - - // Insert all rows at ts - String url = getUrl() + ";" + PhoenixRuntime.CURRENT_SCN_ATTRIB + "=" + ts; - Connection conn = DriverManager.getConnection(url); - conn.setAutoCommit(true); - PreparedStatement stmt = conn.prepareStatement( - "upsert into " + - "LongInKeyTest VALUES(?)"); - stmt.setLong(1, 2); - stmt.execute(); - conn.close(); - } - - @Test - public void testCompareLongGTDecimal() throws Exception { - long ts = nextTimestamp(); - initTableValues(null, ts); - String query = "SELECT l FROM LongInKeyTest where l > 1.5"; - Properties props = new Properties(); - props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2 - Connection conn = DriverManager.getConnection(getUrl(), props); - try { - PreparedStatement statement = conn.prepareStatement(query); - ResultSet rs = statement.executeQuery(); - assertTrue (rs.next()); - assertEquals(2, rs.getLong(1)); - assertFalse(rs.next()); - } finally { - conn.close(); - } - } - - @Test - public void testCompareLongGTEDecimal() throws Exception { - long ts = nextTimestamp(); - initTableValues(null, ts); - String query = "SELECT l FROM LongInKeyTest where l >= 1.5"; - Properties props = new Properties(); - props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2 - Connection conn = DriverManager.getConnection(getUrl(), props); - try { - PreparedStatement statement = conn.prepareStatement(query); - ResultSet rs = statement.executeQuery(); - /* - * Failing because we're not converting the constant to the type of the RHS - * when forming the start/stop key. - * For this case, 1.5 -> 1L - * if where l < 1.5 then 1.5 -> 1L and then to 2L because it's not inclusive - * - */ - assertTrue (rs.next()); - assertEquals(2, rs.getLong(1)); - assertFalse(rs.next()); - } finally { - conn.close(); - } - } - - @Test - public void testCompareLongLTDecimal() throws Exception { - long ts = nextTimestamp(); - initTableValues(null, ts); - String query = "SELECT l FROM LongInKeyTest where l < 1.5"; - Properties props = new Properties(); - props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2 - Connection conn = DriverManager.getConnection(getUrl(), props); - try { - PreparedStatement statement = conn.prepareStatement(query); - ResultSet rs = statement.executeQuery(); - /* - * Failing because we're not converting the constant to the type of the RHS - * when forming the start/stop key. - * For this case, 1.5 -> 1L - * if where l < 1.5 then 1.5 -> 1L and then to 2L because it's not inclusive - * - */ - assertFalse(rs.next()); - } finally { - conn.close(); - } - } - - @Test - public void testCompareLongLTEDecimal() throws Exception { - long ts = nextTimestamp(); - initTableValues(null, ts); - String query = "SELECT l FROM LongInKeyTest where l <= 1.5"; - Properties props = new Properties(); - props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2 - Connection conn = DriverManager.getConnection(getUrl(), props); - try { - PreparedStatement statement = conn.prepareStatement(query); - ResultSet rs = statement.executeQuery(); - /* - * Failing because we're not converting the constant to the type of the RHS - * when forming the start/stop key. - * For this case, 1.5 -> 1L - * if where l < 1.5 then 1.5 -> 1L and then to 2L because it's not inclusive - * - */ - assertFalse(rs.next()); - } finally { - conn.close(); - } - } - @Test - public void testCompareLongGTDecimal2() throws Exception { - long ts = nextTimestamp(); - initTableValues(null, ts); - String query = "SELECT l FROM LongInKeyTest where l > 2.5"; - Properties props = new Properties(); - props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2 - Connection conn = DriverManager.getConnection(getUrl(), props); - try { - PreparedStatement statement = conn.prepareStatement(query); - ResultSet rs = statement.executeQuery(); - /* - * Failing because we're not converting the constant to the type of the RHS - * when forming the start/stop key. - * For this case, 1.5 -> 1L - * if where l < 1.5 then 1.5 -> 1L and then to 2L because it's not inclusive - * - */ - assertFalse(rs.next()); - } finally { - conn.close(); - } - } - - @Test - public void testCompareLongGTEDecimal2() throws Exception { - long ts = nextTimestamp(); - initTableValues(null, ts); - String query = "SELECT l FROM LongInKeyTest where l >= 2.5"; - Properties props = new Properties(); - props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2 - Connection conn = DriverManager.getConnection(getUrl(), props); - try { - PreparedStatement statement = conn.prepareStatement(query); - ResultSet rs = statement.executeQuery(); - /* - * Failing because we're not converting the constant to the type of the RHS - * when forming the start/stop key. - * For this case, 1.5 -> 1L - * if where l < 1.5 then 1.5 -> 1L and then to 2L because it's not inclusive - * - */ - assertFalse(rs.next()); - } finally { - conn.close(); - } - } - - @Test - public void testCompareLongLTDecimal2() throws Exception { - long ts = nextTimestamp(); - initTableValues(null, ts); - String query = "SELECT l FROM LongInKeyTest where l < 2.5"; - Properties props = new Properties(); - props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2 - Connection conn = DriverManager.getConnection(getUrl(), props); - try { - PreparedStatement statement = conn.prepareStatement(query); - ResultSet rs = statement.executeQuery(); - /* - * Failing because we're not converting the constant to the type of the RHS - * when forming the start/stop key. - * For this case, 1.5 -> 1L - * if where l < 1.5 then 1.5 -> 1L and then to 2L because it's not inclusive - * - */ - assertTrue (rs.next()); - assertEquals(2, rs.getLong(1)); - assertFalse(rs.next()); - } finally { - conn.close(); - } - } - - @Test - public void testCompareLongLTEDecimal2() throws Exception { - long ts = nextTimestamp(); - initTableValues(null, ts); - String query = "SELECT l FROM LongInKeyTest where l <= 2.5"; - Properties props = new Properties(); - props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2 - Connection conn = DriverManager.getConnection(getUrl(), props); - try { - PreparedStatement statement = conn.prepareStatement(query); - ResultSet rs = statement.executeQuery(); - /* - * Failing because we're not converting the constant to the type of the RHS - * when forming the start/stop key. - * For this case, 1.5 -> 1L - * if where l < 1.5 then 1.5 -> 1L and then to 2L because it's not inclusive - * - */ - assertTrue (rs.next()); - assertEquals(2, rs.getLong(1)); - assertFalse(rs.next()); - } finally { - conn.close(); - } - } -} http://git-wip-us.apache.org/repos/asf/phoenix/blob/60ef7cd5/phoenix-core/src/it/java/org/apache/phoenix/end2end/PrimitiveTypeIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/PrimitiveTypeIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/PrimitiveTypeIT.java new file mode 100644 index 0000000..cc92ea9 --- /dev/null +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/PrimitiveTypeIT.java @@ -0,0 +1,245 @@ +/* + * 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.end2end; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.util.Properties; + +import org.apache.phoenix.util.PropertiesUtil; +import org.apache.phoenix.util.TestUtil; +import org.junit.Test; + + +public class PrimitiveTypeIT extends BaseHBaseManagedTimeIT { + private static void initTableValues(Connection conn) throws Exception { + conn.createStatement().execute("create table T (l bigint not null primary key, b boolean)"); + PreparedStatement stmt = conn.prepareStatement( + "upsert into " + + "T VALUES(?)"); + stmt.setLong(1, 2); + stmt.execute(); + conn.commit(); + } + + @Test + public void testCompareLongGTDecimal() throws Exception { + Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES); + Connection conn = DriverManager.getConnection(getUrl(), props); + initTableValues(conn); + String query = "SELECT l FROM T where l > 1.5"; + try { + PreparedStatement statement = conn.prepareStatement(query); + ResultSet rs = statement.executeQuery(); + assertTrue (rs.next()); + assertEquals(2, rs.getLong(1)); + assertFalse(rs.next()); + } finally { + conn.close(); + } + } + + @Test + public void testCompareLongGTEDecimal() throws Exception { + Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES); + Connection conn = DriverManager.getConnection(getUrl(), props); + initTableValues(conn); + String query = "SELECT l FROM T where l >= 1.5"; + try { + PreparedStatement statement = conn.prepareStatement(query); + ResultSet rs = statement.executeQuery(); + /* + * Failing because we're not converting the constant to the type of the RHS + * when forming the start/stop key. + * For this case, 1.5 -> 1L + * if where l < 1.5 then 1.5 -> 1L and then to 2L because it's not inclusive + * + */ + assertTrue (rs.next()); + assertEquals(2, rs.getLong(1)); + assertFalse(rs.next()); + } finally { + conn.close(); + } + } + + @Test + public void testCompareLongLTDecimal() throws Exception { + Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES); + Connection conn = DriverManager.getConnection(getUrl(), props); + initTableValues(conn); + String query = "SELECT l FROM T where l < 1.5"; + try { + PreparedStatement statement = conn.prepareStatement(query); + ResultSet rs = statement.executeQuery(); + /* + * Failing because we're not converting the constant to the type of the RHS + * when forming the start/stop key. + * For this case, 1.5 -> 1L + * if where l < 1.5 then 1.5 -> 1L and then to 2L because it's not inclusive + * + */ + assertFalse(rs.next()); + } finally { + conn.close(); + } + } + + @Test + public void testCompareLongLTEDecimal() throws Exception { + Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES); + Connection conn = DriverManager.getConnection(getUrl(), props); + initTableValues(conn); + String query = "SELECT l FROM T where l <= 1.5"; + try { + PreparedStatement statement = conn.prepareStatement(query); + ResultSet rs = statement.executeQuery(); + /* + * Failing because we're not converting the constant to the type of the RHS + * when forming the start/stop key. + * For this case, 1.5 -> 1L + * if where l < 1.5 then 1.5 -> 1L and then to 2L because it's not inclusive + * + */ + assertFalse(rs.next()); + } finally { + conn.close(); + } + } + @Test + public void testCompareLongGTDecimal2() throws Exception { + Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES); + Connection conn = DriverManager.getConnection(getUrl(), props); + initTableValues(conn); + String query = "SELECT l FROM T where l > 2.5"; + try { + PreparedStatement statement = conn.prepareStatement(query); + ResultSet rs = statement.executeQuery(); + /* + * Failing because we're not converting the constant to the type of the RHS + * when forming the start/stop key. + * For this case, 1.5 -> 1L + * if where l < 1.5 then 1.5 -> 1L and then to 2L because it's not inclusive + * + */ + assertFalse(rs.next()); + } finally { + conn.close(); + } + } + + @Test + public void testCompareLongGTEDecimal2() throws Exception { + Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES); + Connection conn = DriverManager.getConnection(getUrl(), props); + initTableValues(conn); + String query = "SELECT l FROM T where l >= 2.5"; + try { + PreparedStatement statement = conn.prepareStatement(query); + ResultSet rs = statement.executeQuery(); + /* + * Failing because we're not converting the constant to the type of the RHS + * when forming the start/stop key. + * For this case, 1.5 -> 1L + * if where l < 1.5 then 1.5 -> 1L and then to 2L because it's not inclusive + * + */ + assertFalse(rs.next()); + } finally { + conn.close(); + } + } + + @Test + public void testCompareLongLTDecimal2() throws Exception { + Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES); + Connection conn = DriverManager.getConnection(getUrl(), props); + initTableValues(conn); + String query = "SELECT l FROM T where l < 2.5"; + try { + PreparedStatement statement = conn.prepareStatement(query); + ResultSet rs = statement.executeQuery(); + /* + * Failing because we're not converting the constant to the type of the RHS + * when forming the start/stop key. + * For this case, 1.5 -> 1L + * if where l < 1.5 then 1.5 -> 1L and then to 2L because it's not inclusive + * + */ + assertTrue (rs.next()); + assertEquals(2, rs.getLong(1)); + assertFalse(rs.next()); + } finally { + conn.close(); + } + } + + @Test + public void testCompareLongLTEDecimal2() throws Exception { + Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES); + Connection conn = DriverManager.getConnection(getUrl(), props); + initTableValues(conn); + String query = "SELECT l FROM T where l <= 2.5"; + try { + PreparedStatement statement = conn.prepareStatement(query); + ResultSet rs = statement.executeQuery(); + /* + * Failing because we're not converting the constant to the type of the RHS + * when forming the start/stop key. + * For this case, 1.5 -> 1L + * if where l < 1.5 then 1.5 -> 1L and then to 2L because it's not inclusive + * + */ + assertTrue (rs.next()); + assertEquals(2, rs.getLong(1)); + assertFalse(rs.next()); + } finally { + conn.close(); + } + } + + @Test + public void testBooleanAsObject() throws Exception { + Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES); + Connection conn = DriverManager.getConnection(getUrl(), props); + initTableValues(conn); + String query = "upsert into T values (2, ?)"; + try { + PreparedStatement statement = conn.prepareStatement(query); + statement.setObject(1, new Boolean("false")); + statement.execute(); + conn.commit(); + statement = conn.prepareStatement("SELECT l,b,? FROM T"); + statement.setObject(1, new Boolean("false")); + ResultSet rs = statement.executeQuery(); + assertTrue(rs.next()); + assertEquals(2, rs.getLong(1)); + assertEquals(Boolean.FALSE, rs.getObject(2)); + assertEquals(Boolean.FALSE, rs.getObject(3)); + assertFalse(rs.next()); + } finally { + conn.close(); + } + } +} http://git-wip-us.apache.org/repos/asf/phoenix/blob/60ef7cd5/phoenix-core/src/main/java/org/apache/phoenix/expression/LiteralExpression.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/LiteralExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/LiteralExpression.java index e911aae..ad1c7c0 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/expression/LiteralExpression.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/LiteralExpression.java @@ -85,7 +85,7 @@ public class LiteralExpression extends BaseTerminalExpression { } private static LiteralExpression getBooleanLiteralExpression(Boolean bool, Determinism determinism){ - return BOOLEAN_EXPRESSIONS[ (bool==Boolean.FALSE ? 0 : Determinism.values().length) + determinism.ordinal()]; + return BOOLEAN_EXPRESSIONS[ (Boolean.FALSE.equals(bool) ? 0 : Determinism.values().length) + determinism.ordinal()]; } public static boolean isFalse(Expression child) { http://git-wip-us.apache.org/repos/asf/phoenix/blob/60ef7cd5/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java b/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java index a67a530..9539e69 100644 --- a/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java +++ b/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java @@ -172,18 +172,18 @@ import org.junit.rules.TemporaryFolder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import co.cask.tephra.TransactionManager; -import co.cask.tephra.TxConstants; -import co.cask.tephra.distributed.TransactionService; -import co.cask.tephra.metrics.TxMetricsCollector; -import co.cask.tephra.persist.InMemoryTransactionStateStorage; - import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import com.google.common.collect.Sets; import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.google.inject.util.Providers; +import co.cask.tephra.TransactionManager; +import co.cask.tephra.TxConstants; +import co.cask.tephra.distributed.TransactionService; +import co.cask.tephra.metrics.TxMetricsCollector; +import co.cask.tephra.persist.InMemoryTransactionStateStorage; + /** * * Base class that contains all the methods needed by @@ -429,8 +429,6 @@ public abstract class BaseTest { " (i integer not null primary key)"); builder.put("IntIntKeyTest","create table IntIntKeyTest" + " (i integer not null primary key, j integer)"); - builder.put("LongInKeyTest","create table LongInKeyTest" + - " (l bigint not null primary key)"); builder.put("PKIntValueTest", "create table PKIntValueTest" + " (pk integer not null primary key)"); builder.put("PKBigIntValueTest", "create table PKBigIntValueTest" +