}
}
@Test
public void testSelectFromViewOnExistingTable() throws Exception {
PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(
PhoenixConnection.class);
byte[] cfB = Bytes.toBytes(SchemaUtil.normalizeIdentifier("b"));
byte[] cfC = Bytes.toBytes(SchemaUtil.normalizeIdentifier("c"));
byte[][] familyNames = new byte[][] { cfB, cfC };
byte[] htableName = SchemaUtil.getTableNameAsBytes(MDTEST_SCHEMA_NAME, MDTEST_NAME);
HBaseAdmin admin = pconn.getQueryServices().getAdmin();
HTableDescriptor descriptor = new HTableDescriptor(htableName);
for (byte[] familyName : familyNames) {
HColumnDescriptor columnDescriptor = new HColumnDescriptor(familyName);
descriptor.addFamily(columnDescriptor);
}
admin.createTable(descriptor);
long ts = nextTimestamp();
Properties props = new Properties();
props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 5));
Connection conn1 = DriverManager.getConnection(getUrl(), props);
String createStmt = "create view " + MDTEST_NAME + " (id integer not null primary key,"
+ " b.col1 integer, c.col2 bigint, c.col3 varchar(20))";
conn1.createStatement().execute(createStmt);
conn1.close();
props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 6));
PhoenixConnection conn2 = DriverManager.getConnection(getUrl(), props).unwrap(PhoenixConnection.class);
byte[] c1 = Bytes.toBytes("COL1");
byte[] c2 = Bytes.toBytes("COL2");
byte[] c3 = Bytes.toBytes("COL3");
HTableInterface htable = null;
try {
htable = conn2.getQueryServices().getTable(htableName);
Put put = new Put(PDataType.INTEGER.toBytes(1));
put.add(cfB, c1, ts + 6, PDataType.INTEGER.toBytes(1));
put.add(cfC, c2, ts + 6, PDataType.LONG.toBytes(2));
htable.put(put);
put = new Put(PDataType.INTEGER.toBytes(2));
put.add(cfC, c2, ts + 6, PDataType.LONG.toBytes(10));
put.add(cfC, c3, ts + 6, PDataType.VARCHAR.toBytes("abcd"));
htable.put(put);
put = new Put(PDataType.INTEGER.toBytes(3));
put.add(cfB, c1, ts + 6, PDataType.INTEGER.toBytes(3));
put.add(cfC, c2, ts + 6, PDataType.LONG.toBytes(10));
put.add(cfC, c3, ts + 6, PDataType.VARCHAR.toBytes("abcd"));
htable.put(put);
conn2.close();
props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
Connection conn7 = DriverManager.getConnection(getUrl(), props);
String select = "SELECT id, b.col1 FROM " + MDTEST_NAME + " WHERE c.col2=?";
PreparedStatement ps = conn7.prepareStatement(select);