phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kl...@apache.org
Subject phoenix git commit: PHOENIX-3545 Add integration tests for string upper and lower
Date Mon, 06 Feb 2017 07:26:41 GMT
Repository: phoenix
Updated Branches:
  refs/heads/master 58ae6668c -> 96120337c


PHOENIX-3545 Add integration tests for string upper and lower


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

Branch: refs/heads/master
Commit: 96120337ceb2dc93224e6fdff1f5e06d8207c726
Parents: 58ae666
Author: kliewkliew <kliewkliew@users.noreply.github.com>
Authored: Sun Feb 5 22:57:53 2017 -0800
Committer: kliewkliew <kliewkliew@users.noreply.github.com>
Committed: Sun Feb 5 22:57:53 2017 -0800

----------------------------------------------------------------------
 .../phoenix/end2end/UpperLowerFunctionIT.java   | 119 +++++++++++++++++++
 1 file changed, 119 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/96120337/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpperLowerFunctionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpperLowerFunctionIT.java
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpperLowerFunctionIT.java
new file mode 100644
index 0000000..2c43468
--- /dev/null
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpperLowerFunctionIT.java
@@ -0,0 +1,119 @@
+/*
+ * 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.sql.SQLException;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class UpperLowerFunctionIT extends ParallelStatsDisabledIT {
+    private static String tableName = generateUniqueName();
+    private static String firstName = "Joe";
+    private static String lastName = "Smith";
+
+    @BeforeClass
+    public static void init() throws SQLException {
+        Connection conn = DriverManager.getConnection(getUrl());
+        String ddl = "CREATE TABLE " + tableName + " ("
+                + "id INTEGER PRIMARY KEY,"
+                + "first_name VARCHAR,"
+                + "last_name VARCHAR"
+                + ")";
+        conn.createStatement().execute(ddl);
+        String dml = String.format("UPSERT INTO %s VALUES("
+                        + "1, '%s', '%s'"
+                        + ")",
+                tableName, firstName, lastName);
+        PreparedStatement stmt = conn.prepareStatement(dml);
+        stmt.execute();
+        conn.commit();
+    }
+
+    @Test
+    public void testWhereLower() throws SQLException {
+        Connection conn = DriverManager.getConnection(getUrl());
+
+        ResultSet rs;
+        rs = conn.createStatement().executeQuery(String.format(
+                "SELECT first_name, last_name FROM %s WHERE"
+                        + " LOWER(first_name || ' ' || last_name)"
+                        + " = '%s %s'",
+                tableName, firstName.toLowerCase(), lastName.toLowerCase()));
+        assertTrue(rs.next());
+        assertEquals(firstName, rs.getString(1));
+        assertEquals(lastName, rs.getString(2));
+        assertFalse(rs.next());
+    }
+
+    @Test
+    public void testSelectLower() throws SQLException {
+        Connection conn = DriverManager.getConnection(getUrl());
+
+        ResultSet rs;
+        rs = conn.createStatement().executeQuery(String.format(
+                "SELECT LOWER(first_name || ' ' || last_name) FROM %s WHERE"
+                        + " id = 1",
+                tableName));
+        assertTrue(rs.next());
+        String expected = String.format("%s %s",
+                firstName.toLowerCase(), lastName.toLowerCase());
+        assertEquals(expected, rs.getString(1));
+        assertFalse(rs.next());
+    }
+
+    @Test
+    public void testWhereUpper() throws SQLException {
+        Connection conn = DriverManager.getConnection(getUrl());
+
+        ResultSet rs;
+        rs = conn.createStatement().executeQuery(String.format(
+                "SELECT first_name, last_name FROM %s WHERE"
+                        + " UPPER(first_name || ' ' || last_name)"
+                        + " = '%s %s'",
+                tableName, firstName.toUpperCase(), lastName.toUpperCase()));
+        assertTrue(rs.next());
+        assertEquals(firstName, rs.getString(1));
+        assertEquals(lastName, rs.getString(2));
+        assertFalse(rs.next());
+    }
+
+    @Test
+    public void testSelectUpper() throws SQLException {
+        Connection conn = DriverManager.getConnection(getUrl());
+
+        ResultSet rs;
+        rs = conn.createStatement().executeQuery(String.format(
+                "SELECT UPPER(first_name || ' ' || last_name) FROM %s WHERE"
+                        + " id = 1",
+                tableName));
+        assertTrue(rs.next());
+        String expected = String.format("%s %s",
+                firstName.toUpperCase(), lastName.toUpperCase());
+        assertEquals(expected, rs.getString(1));
+        assertFalse(rs.next());
+    }
+}


Mime
View raw message