Uploaded image for project: 'Phoenix'
  1. Phoenix
  2. PHOENIX-2139

LIKE '%' is not filtering out null columns

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 4.5.0
    • Labels:
      None

      Description

      Found based on PhoenixDatabaseMetaData.getColumns() not filtering when column name is null.

      This test should pass:

          @Test
          public void testLikeEverythingExpression() throws Exception {
              Connection conn = DriverManager.getConnection(getUrl());
              String ddl = "CREATE TABLE t (k1 VARCHAR, k2 VARCHAR, CONSTRAINT pk PRIMARY KEY (k1,k2))";
              conn.createStatement().execute(ddl);
              conn.createStatement().execute("UPSERT INTO t VALUES('aa','bb')");
              conn.createStatement().execute("UPSERT INTO t VALUES('ab','bc')");
              conn.createStatement().execute("UPSERT INTO t VALUES(null,'cc')");
              conn.createStatement().execute("UPSERT INTO t VALUES('dd',null)");
              conn.commit();
              
              ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM t WHERE k1 LIKE '%'");
              assertTrue(rs.next());
              assertEquals("aa", rs.getString(1));
              assertEquals("bb", rs.getString(2));
              assertTrue(rs.next());
              assertEquals("ab", rs.getString(1));
              assertEquals("bc", rs.getString(2));
              assertTrue(rs.next());
              assertEquals("dd", rs.getString(1));
              assertEquals(null, rs.getString(2));
              assertFalse(rs.next());
              
              rs = conn.createStatement().executeQuery("SELECT * FROM t WHERE k2 LIKE '%'");
              assertTrue(rs.next());
              assertEquals(null, rs.getString(1));
              assertEquals("cc", rs.getString(2));
              assertTrue(rs.next());
              assertEquals("aa", rs.getString(1));
              assertEquals("bb", rs.getString(2));
              assertTrue(rs.next());
              assertEquals("ab", rs.getString(1));
              assertEquals("bc", rs.getString(2));
              assertFalse(rs.next());
              
              conn.close();
          }
      

        Attachments

        1. PHOENIX-2139.patch
          3 kB
          James Taylor
        2. PHOENIX-2139_v2.patch
          4 kB
          James Taylor

          Activity

            People

            • Assignee:
              jamestaylor James Taylor
              Reporter:
              jamestaylor James Taylor
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: