use of org.apache.hadoop.hbase.client.HBaseAdmin in project phoenix by apache.
the class AlterTableIT method testSettingNotHColumnNorPhoenixPropertyEndsUpAsHTableProperty.
@Test
public void testSettingNotHColumnNorPhoenixPropertyEndsUpAsHTableProperty() throws Exception {
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
Connection conn = DriverManager.getConnection(getUrl(), props);
try {
String ddl = "create table " + dataTableFullName + " (" + " id char(1) NOT NULL," + " col1 integer NOT NULL," + " col2 bigint NOT NULL," + " CONSTRAINT NAME_PK PRIMARY KEY (id, col1, col2)" + " ) " + tableDDLOptions;
conn.createStatement().execute(ddl);
ddl = "ALTER TABLE " + dataTableFullName + " ADD NEWCF.COL3 INTEGER NEWCF.UNKNOWN_PROP='ABC'";
try {
conn.createStatement().execute(ddl);
fail();
} catch (SQLException e) {
assertEquals(SQLExceptionCode.CANNOT_SET_TABLE_PROPERTY_ADD_COLUMN.getErrorCode(), e.getErrorCode());
}
ddl = "ALTER TABLE " + dataTableFullName + " SET UNKNOWN_PROP='ABC'";
conn.createStatement().execute(ddl);
try (HBaseAdmin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
HTableDescriptor tableDesc = admin.getTableDescriptor(Bytes.toBytes(dataTableFullName));
assertEquals("ABC", tableDesc.getValue("UNKNOWN_PROP"));
}
} finally {
conn.close();
}
}
use of org.apache.hadoop.hbase.client.HBaseAdmin in project phoenix by apache.
the class AlterTableIT method testSetPropertyAndAddColumnForNewAndExistingColumnFamily.
@Test
public void testSetPropertyAndAddColumnForNewAndExistingColumnFamily() throws Exception {
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
Connection conn = DriverManager.getConnection(getUrl(), props);
String ddl = "CREATE TABLE " + dataTableFullName + " " + " (a_string varchar not null, col1 integer, CF1.col2 integer" + " CONSTRAINT pk PRIMARY KEY (a_string)) " + tableDDLOptions;
try {
conn.createStatement().execute(ddl);
conn.createStatement().execute("ALTER TABLE " + dataTableFullName + " ADD col4 integer, CF1.col5 integer, CF2.col6 integer IN_MEMORY=true, CF1.REPLICATION_SCOPE=1, CF2.IN_MEMORY=false ");
try (HBaseAdmin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
HColumnDescriptor[] columnFamilies = admin.getTableDescriptor(Bytes.toBytes(dataTableFullName)).getColumnFamilies();
assertEquals(3, columnFamilies.length);
assertEquals("0", columnFamilies[0].getNameAsString());
assertTrue(columnFamilies[0].isInMemory());
assertEquals(0, columnFamilies[0].getScope());
assertEquals("CF1", columnFamilies[1].getNameAsString());
assertTrue(columnFamilies[1].isInMemory());
assertEquals(1, columnFamilies[1].getScope());
assertEquals("CF2", columnFamilies[2].getNameAsString());
assertFalse(columnFamilies[2].isInMemory());
assertEquals(0, columnFamilies[2].getScope());
}
} finally {
conn.close();
}
}
use of org.apache.hadoop.hbase.client.HBaseAdmin in project phoenix by apache.
the class AlterTableIT method testSetHColumnPropertyForTableWithOnlyPKCols1.
@Test
public void testSetHColumnPropertyForTableWithOnlyPKCols1() throws Exception {
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
Connection conn = DriverManager.getConnection(getUrl(), props);
conn.setAutoCommit(false);
try {
String ddl = "create table " + dataTableFullName + " (" + " id char(1) NOT NULL," + " col1 integer NOT NULL," + " col2 bigint NOT NULL," + " CONSTRAINT NAME_PK PRIMARY KEY (id, col1, col2)" + " ) " + generateDDLOptions("TTL=86400, SALT_BUCKETS = 4, DEFAULT_COLUMN_FAMILY='XYZ'");
conn.createStatement().execute(ddl);
ddl = "ALTER TABLE " + dataTableFullName + " SET IN_MEMORY=true";
conn.createStatement().execute(ddl);
conn.commit();
try (HBaseAdmin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
HTableDescriptor tableDesc = admin.getTableDescriptor(Bytes.toBytes(dataTableFullName));
HColumnDescriptor[] columnFamilies = tableDesc.getColumnFamilies();
assertEquals(1, columnFamilies.length);
assertEquals(true, columnFamilies[0].isInMemory());
assertEquals("XYZ", columnFamilies[0].getNameAsString());
}
} finally {
conn.close();
}
}
use of org.apache.hadoop.hbase.client.HBaseAdmin in project phoenix by apache.
the class CreateTableIT method testCreateTableColumnFamilyHBaseAttribs6.
/**
* Tests that when:
* 1) DDL has both pk as well as key value columns
* 2) There is a default column family specified.
*
* Then:
* 1)TTL is set for the specified default column family.
*
*/
@Test
public void testCreateTableColumnFamilyHBaseAttribs6() throws Exception {
String ddl = "create table IF NOT EXISTS TEST6 (" + " id char(1) NOT NULL," + " col1 integer NOT NULL," + " col2 bigint," + " col3 bigint, " + " CONSTRAINT NAME_PK PRIMARY KEY (id, col1)" + " ) DEFAULT_COLUMN_FAMILY='a', TTL=10000, SALT_BUCKETS = 4";
long ts = nextTimestamp();
Properties props = new Properties();
props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts));
Connection conn = DriverManager.getConnection(getUrl(), props);
conn.createStatement().execute(ddl);
HBaseAdmin admin = driver.getConnectionQueryServices(getUrl(), props).getAdmin();
HColumnDescriptor[] columnFamilies = admin.getTableDescriptor(Bytes.toBytes("TEST6")).getColumnFamilies();
assertEquals(1, columnFamilies.length);
assertEquals("a", columnFamilies[0].getNameAsString());
assertEquals(10000, columnFamilies[0].getTimeToLive());
}
use of org.apache.hadoop.hbase.client.HBaseAdmin in project phoenix by apache.
the class CreateTableIT method testCreateTableColumnFamilyHBaseAttribs7.
/**
* Tests that when:
* 1) DDL has only pk columns
* 2) There is a default column family specified.
*
* Then:
* 1)TTL is set for the specified default column family.
*
*/
@Test
public void testCreateTableColumnFamilyHBaseAttribs7() throws Exception {
String ddl = "create table IF NOT EXISTS TEST7 (" + " id char(1) NOT NULL," + " col1 integer NOT NULL," + " CONSTRAINT NAME_PK PRIMARY KEY (id, col1)" + " ) DEFAULT_COLUMN_FAMILY='a', TTL=10000, SALT_BUCKETS = 4";
long ts = nextTimestamp();
Properties props = new Properties();
props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts));
Connection conn = DriverManager.getConnection(getUrl(), props);
conn.createStatement().execute(ddl);
HBaseAdmin admin = driver.getConnectionQueryServices(getUrl(), props).getAdmin();
HColumnDescriptor[] columnFamilies = admin.getTableDescriptor(Bytes.toBytes("TEST7")).getColumnFamilies();
assertEquals(1, columnFamilies.length);
assertEquals("a", columnFamilies[0].getNameAsString());
assertEquals(10000, columnFamilies[0].getTimeToLive());
}
Aggregations