Skip to content

Commit

Permalink
PHOENIX-2120 Padding character is not inverted as required for DESC C…
Browse files Browse the repository at this point in the history
…HAR columns
  • Loading branch information
JamesRTaylor committed Jul 21, 2015
1 parent 936de88 commit dcf845c
Show file tree
Hide file tree
Showing 18 changed files with 495 additions and 178 deletions.
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.phoenix.end2end;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
Expand All @@ -27,8 +28,10 @@
import java.util.ArrayList;
import java.util.List;

import org.apache.hadoop.hbase.util.Bytes;
import org.apache.phoenix.query.QueryConstants;
import org.apache.phoenix.util.ByteUtil;
import org.apache.phoenix.util.TestUtil;
import org.junit.Ignore;
import org.junit.Test;

import com.google.common.collect.Lists;
Expand Down Expand Up @@ -107,26 +110,59 @@ private void testLpad(Connection conn, List<String> inputList, int length, List<
testLpad(conn, inputList, length, fillStringList, "pk", expectedOutputList);
}

@Ignore
@Test
public void testCharPadding() throws Exception {
ResultSet rs;
Connection conn = DriverManager.getConnection(getUrl());

conn.createStatement().execute("CREATE TABLE t (k CHAR(3) PRIMARY KEY)");
conn.createStatement().execute("UPSERT INTO t VALUES('a')");
conn.createStatement().execute("UPSERT INTO t VALUES('ab')");
conn.commit();
rs = conn.createStatement().executeQuery("SELECT * FROM t ORDER BY k");
assertTrue(rs.next());
assertEquals("a", rs.getString(1));
assertTrue(rs.next());
assertEquals("ab", rs.getString(1));
assertFalse(rs.next());

conn.createStatement().execute("CREATE TABLE tdesc (k CHAR(3) PRIMARY KEY DESC)");
conn.createStatement().execute("UPSERT INTO tdesc VALUES('a')");
conn.createStatement().execute("UPSERT INTO tdesc VALUES('ab')");
conn.commit();
rs = conn.createStatement().executeQuery("SELECT * FROM tdesc");
rs = conn.createStatement().executeQuery("SELECT * FROM tdesc ORDER BY k DESC");
assertTrue(rs.next());
assertEquals("ab", rs.getString(1));
assertTrue(rs.next());
assertEquals("a", rs.getString(1));
assertFalse(rs.next());
}

@Test
public void testBinaryPadding() throws Exception {
ResultSet rs;
Connection conn = DriverManager.getConnection(getUrl());

conn.createStatement().execute("CREATE TABLE t (k CHAR(3) PRIMARY KEY)");
conn.createStatement().execute("CREATE TABLE t (k BINARY(3) PRIMARY KEY)");
conn.createStatement().execute("UPSERT INTO t VALUES('a')");
conn.createStatement().execute("UPSERT INTO t VALUES('ab')");
conn.commit();
rs = conn.createStatement().executeQuery("SELECT * FROM t");
rs = conn.createStatement().executeQuery("SELECT * FROM t ORDER BY k");
assertTrue(rs.next());
assertEquals("a", rs.getString(1));
assertArrayEquals(ByteUtil.concat(Bytes.toBytes("a"), QueryConstants.SEPARATOR_BYTE_ARRAY, QueryConstants.SEPARATOR_BYTE_ARRAY), rs.getBytes(1));
assertTrue(rs.next());
assertArrayEquals(ByteUtil.concat(Bytes.toBytes("ab"), QueryConstants.SEPARATOR_BYTE_ARRAY), rs.getBytes(1));
assertFalse(rs.next());

conn.createStatement().execute("CREATE TABLE tdesc (k BINARY(3) PRIMARY KEY DESC)");
conn.createStatement().execute("UPSERT INTO tdesc VALUES('a')");
conn.createStatement().execute("UPSERT INTO tdesc VALUES('ab')");
conn.commit();
rs = conn.createStatement().executeQuery("SELECT * FROM tdesc ORDER BY k DESC");
assertTrue(rs.next());
assertArrayEquals(ByteUtil.concat(Bytes.toBytes("ab"), QueryConstants.SEPARATOR_BYTE_ARRAY), rs.getBytes(1));
assertTrue(rs.next());
assertArrayEquals(ByteUtil.concat(Bytes.toBytes("a"), QueryConstants.SEPARATOR_BYTE_ARRAY, QueryConstants.SEPARATOR_BYTE_ARRAY), rs.getBytes(1));
assertFalse(rs.next());
}

Expand Down
Expand Up @@ -20,10 +20,10 @@
import java.util.List;

import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;

import org.apache.phoenix.expression.Expression;
import org.apache.phoenix.query.KeyRange;
import org.apache.phoenix.schema.PColumn;
import org.apache.phoenix.schema.PTable;

/**
*
Expand Down Expand Up @@ -74,4 +74,10 @@ public interface KeyPart {
* @return the primary key column for this key part
*/
public PColumn getColumn();

/**
* Gets the table metadata object associated with this key part
* @return the table for this key part
*/
public PTable getTable();
}

0 comments on commit dcf845c

Please sign in to comment.