Search in sources :

Example 36 with HBaseAdmin

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());
}
Also used : HBaseAdmin(org.apache.hadoop.hbase.client.HBaseAdmin) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) Connection(java.sql.Connection) PhoenixConnection(org.apache.phoenix.jdbc.PhoenixConnection) Properties(java.util.Properties) Test(org.junit.Test)

Example 37 with HBaseAdmin

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();
}
Also used : HBaseAdmin(org.apache.hadoop.hbase.client.HBaseAdmin) NewerSchemaAlreadyExistsException(org.apache.phoenix.schema.NewerSchemaAlreadyExistsException) SQLException(java.sql.SQLException) NewerSchemaAlreadyExistsException(org.apache.phoenix.schema.NewerSchemaAlreadyExistsException) SchemaAlreadyExistsException(org.apache.phoenix.schema.SchemaAlreadyExistsException) Connection(java.sql.Connection) PhoenixConnection(org.apache.phoenix.jdbc.PhoenixConnection) Properties(java.util.Properties) Test(org.junit.Test)

Example 38 with HBaseAdmin

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());
}
Also used : HBaseAdmin(org.apache.hadoop.hbase.client.HBaseAdmin) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) Connection(java.sql.Connection) PhoenixConnection(org.apache.phoenix.jdbc.PhoenixConnection) Properties(java.util.Properties) Test(org.junit.Test)

Example 39 with HBaseAdmin

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());
}
Also used : HBaseAdmin(org.apache.hadoop.hbase.client.HBaseAdmin) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) Connection(java.sql.Connection) PhoenixConnection(org.apache.phoenix.jdbc.PhoenixConnection) Properties(java.util.Properties) Test(org.junit.Test)

Example 40 with HBaseAdmin

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());
}
Also used : HBaseAdmin(org.apache.hadoop.hbase.client.HBaseAdmin) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) Connection(java.sql.Connection) PhoenixConnection(org.apache.phoenix.jdbc.PhoenixConnection) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

HBaseAdmin (org.apache.hadoop.hbase.client.HBaseAdmin)180 Test (org.junit.Test)93 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)76 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)72 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)70 Connection (java.sql.Connection)66 Properties (java.util.Properties)54 TableName (org.apache.hadoop.hbase.TableName)36 IOException (java.io.IOException)33 ResultSet (java.sql.ResultSet)27 BaseTest (org.apache.phoenix.query.BaseTest)27 HTable (org.apache.hadoop.hbase.client.HTable)26 SQLException (java.sql.SQLException)22 TestUtil.closeConnection (org.apache.phoenix.util.TestUtil.closeConnection)22 Put (org.apache.hadoop.hbase.client.Put)16 Configuration (org.apache.hadoop.conf.Configuration)13 HTableInterface (org.apache.hadoop.hbase.client.HTableInterface)13 PreparedStatement (java.sql.PreparedStatement)12 PhoenixIOException (org.apache.phoenix.exception.PhoenixIOException)12 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)9