use of org.apache.hadoop.hbase.client.HBaseAdmin in project phoenix by apache.
the class CreateTableIT method testCreateTableColumnFamilyHBaseAttribs1.
/**
* Test that when the ddl only has PK cols, ttl is set.
*/
@Test
public void testCreateTableColumnFamilyHBaseAttribs1() throws Exception {
String ddl = "create table IF NOT EXISTS TEST1 (" + " id char(1) NOT NULL," + " col1 integer NOT NULL," + " col2 bigint NOT NULL," + " CONSTRAINT NAME_PK PRIMARY KEY (id, col1, col2)" + " ) TTL=86400, 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("TEST1")).getColumnFamilies();
assertEquals(1, columnFamilies.length);
assertEquals(86400, columnFamilies[0].getTimeToLive());
}
use of org.apache.hadoop.hbase.client.HBaseAdmin in project phoenix by apache.
the class CreateSchemaIT method testCreateSchema.
@Test
public void testCreateSchema() throws Exception {
long ts = nextTimestamp();
Properties props = new Properties();
props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts));
props.setProperty(QueryServices.IS_NAMESPACE_MAPPING_ENABLED, Boolean.toString(true));
String ddl = "CREATE SCHEMA TEST_SCHEMA";
try (Connection conn = DriverManager.getConnection(getUrl(), props);
HBaseAdmin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
conn.createStatement().execute(ddl);
assertNotNull(admin.getNamespaceDescriptor("TEST_SCHEMA"));
}
props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
conn.createStatement().execute(ddl);
fail();
} catch (SchemaAlreadyExistsException e) {
// expected
}
props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts - 20));
try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
conn.createStatement().execute(ddl);
fail();
} catch (NewerSchemaAlreadyExistsException e) {
// expected
}
props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 50));
Connection conn = DriverManager.getConnection(getUrl(), props);
try {
conn.createStatement().execute("CREATE SCHEMA " + SchemaUtil.SCHEMA_FOR_DEFAULT_NAMESPACE);
fail();
} catch (SQLException e) {
assertEquals(SQLExceptionCode.SCHEMA_NOT_ALLOWED.getErrorCode(), e.getErrorCode());
}
try {
conn.createStatement().execute("CREATE SCHEMA " + SchemaUtil.HBASE_NAMESPACE);
fail();
} catch (SQLException e) {
assertEquals(SQLExceptionCode.SCHEMA_NOT_ALLOWED.getErrorCode(), e.getErrorCode());
}
conn.close();
}
use of org.apache.hadoop.hbase.client.HBaseAdmin in project phoenix by apache.
the class CreateTableIT method testCreateTableColumnFamilyHBaseAttribs4.
/**
* Tests that when:
* 1) DDL has both pk as well as key value columns
* 2) Key value columns have both default and explicit column family names
* 3) Replication scope specifier has the explicit column family name.
*
* Then:
* 1)REPLICATION_SCOPE is set.
* 2)The default column family has DEFAULT_REPLICATION_SCOPE.
* 3)The explicit column family has the REPLICATION_SCOPE specified in DDL.
*/
@Test
public void testCreateTableColumnFamilyHBaseAttribs4() throws Exception {
String ddl = "create table IF NOT EXISTS TEST4 (" + " id char(1) NOT NULL," + " col1 integer NOT NULL," + " b.col2 bigint," + " col3 bigint, " + " CONSTRAINT NAME_PK PRIMARY KEY (id, col1)" + " ) b.REPLICATION_SCOPE=1, 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("TEST4")).getColumnFamilies();
assertEquals(2, columnFamilies.length);
assertEquals("0", columnFamilies[0].getNameAsString());
assertEquals(DEFAULT_REPLICATION_SCOPE, columnFamilies[0].getScope());
assertEquals("B", columnFamilies[1].getNameAsString());
assertEquals(1, columnFamilies[1].getScope());
}
use of org.apache.hadoop.hbase.client.HBaseAdmin in project phoenix by apache.
the class CreateTableIT method testCreateTableColumnFamilyHBaseAttribs2.
/**
* Tests that when:
* 1) DDL has both pk as well as key value columns
* 2) Key value columns have different column family names
* 3) TTL specifier doesn't have column family name.
*
* Then:
* 1)TTL is set.
* 2)All column families have the same TTL.
*/
@Test
public void testCreateTableColumnFamilyHBaseAttribs2() throws Exception {
String ddl = "create table IF NOT EXISTS TEST2 (" + " id char(1) NOT NULL," + " col1 integer NOT NULL," + " b.col2 bigint," + " c.col3 bigint, " + " CONSTRAINT NAME_PK PRIMARY KEY (id, col1)" + " ) TTL=86400, 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("TEST2")).getColumnFamilies();
assertEquals(2, columnFamilies.length);
assertEquals(86400, columnFamilies[0].getTimeToLive());
assertEquals("B", columnFamilies[0].getNameAsString());
assertEquals(86400, columnFamilies[1].getTimeToLive());
assertEquals("C", columnFamilies[1].getNameAsString());
}
use of org.apache.hadoop.hbase.client.HBaseAdmin in project phoenix by apache.
the class CreateTableIT method testCreateTableColumnFamilyHBaseAttribs5.
/**
* Tests that when:
* 1) DDL has both pk as well as key value columns
* 2) Key value columns have explicit column family names
* 3) Different REPLICATION_SCOPE specifiers for different column family names.
*
* Then:
* 1)REPLICATION_SCOPE is set.
* 2)Each explicit column family has the REPLICATION_SCOPE as specified in DDL.
*/
@Test
public void testCreateTableColumnFamilyHBaseAttribs5() throws Exception {
String ddl = "create table IF NOT EXISTS TEST5 (" + " id char(1) NOT NULL," + " col1 integer NOT NULL," + " b.col2 bigint," + " c.col3 bigint, " + " CONSTRAINT NAME_PK PRIMARY KEY (id, col1)" + " ) b.REPLICATION_SCOPE=0, c.REPLICATION_SCOPE=1, 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("TEST5")).getColumnFamilies();
assertEquals(2, columnFamilies.length);
assertEquals("B", columnFamilies[0].getNameAsString());
assertEquals(0, columnFamilies[0].getScope());
assertEquals("C", columnFamilies[1].getNameAsString());
assertEquals(1, columnFamilies[1].getScope());
}
Aggregations