Package org.apache.hadoop.hbase.hbql.client

Examples of org.apache.hadoop.hbase.hbql.client.HConnection


public class MappingTest extends TestSupport {

    @Test
    public void createMapping() throws HBqlException {

        HConnection connection = HConnectionManager.newConnection();

        assertFalse(connection.mappingExists("zzz"));
        assertTrue(connection.mappingExists("system_mappings"));

        String mappingName = "test1";
        connection.dropMapping(mappingName);
        assertFalse(connection.mappingExists(mappingName));
        connection.execute("CREATE MAPPING " + mappingName + " (keyval key, f1 (val2 object alias val3))");
        assertTrue(connection.mappingExists(mappingName));
        HMapping mapping = connection.getMapping(mappingName);
        assertTrue(mapping.getMappingName().equals(mappingName) && mapping.getTableName().equals(mappingName));
        assertTrue(!mapping.isTempMapping());
        connection.dropMapping(mappingName);
        assertFalse(connection.mappingExists(mappingName));

        mappingName = "test2";
        connection.dropMapping(mappingName);
        assertFalse(connection.mappingExists(mappingName));
        connection.execute("CREATE TEMP MAPPING " + mappingName + " (keyval key, f1(val2 object alias val3))");
        assertTrue(connection.mappingExists(mappingName));
        mapping = connection.getMapping(mappingName);
        assertTrue(mapping.getMappingName().equals(mappingName) && mapping.getTableName().equals(mappingName));
        assertTrue(mapping.isTempMapping());
        connection.dropMapping(mappingName);
        assertFalse(connection.mappingExists(mappingName));

        mappingName = "test3";
        connection.dropMapping(mappingName);
        assertFalse(connection.mappingExists(mappingName));
        connection.execute("CREATE TEMP MAPPING " + mappingName + " for table unknown_table"
                           + " (keyval key, "
                           + "f1 (val1 int[] , val2 object[] alias val3),"
                           + "f2 include unmapped(val1 int[] , val2 string alias val4 default 'test val'))");
        assertTrue(connection.mappingExists(mappingName));
        mapping = connection.getMapping(mappingName);
        assertTrue(mapping.getMappingName().equals(mappingName) && !mapping.getTableName().equals(mappingName));
        assertTrue(mapping.isTempMapping());

        mapping = connection.getMapping(mappingName);
        System.out.print(mapping.asString());

        connection.dropMapping(mappingName);
        assertFalse(connection.mappingExists(mappingName));

        Set<HMapping> mappings = connection.getAllMappings();
    }
View Full Code Here


    public void showTables() throws HBqlException {

        // START SNIPPET: show-tables

        // Using the API
        HConnection conn = HConnectionManager.newConnection();
        Set<String> tableNames = conn.getTableNames();

        // END SNIPPET: show-tables
    }
View Full Code Here

    public void showMappings() throws HBqlException {

        // START SNIPPET: show-mappings

        // Using the API
        HConnection conn = HConnectionManager.newConnection();
        Set<HMapping> mappings = conn.getAllMappings();
        for (HMapping mapping : mappings)
            System.out.println(mapping.getMappingName());

        // END SNIPPET: show-mappings
    }
View Full Code Here

    public void describeTable() throws HBqlException {

        // START SNIPPET: describe-table

        HConnection conn = HConnectionManager.newConnection();
        System.out.println(conn.execute("DESCRIBE TABLE foo"));

        // END SNIPPET: describe-table

    }
View Full Code Here

    public void describeMapping() throws HBqlException {

        // START SNIPPET: describe-mapping

        HConnection conn = HConnectionManager.newConnection();
        System.out.println(conn.execute("DESCRIBE MAPPING fooMapping"));

        // END SNIPPET: describe-mapping

    }
View Full Code Here

    public void enableTable() throws HBqlException {

        // START SNIPPET: enable-table

        HConnection conn = HConnectionManager.newConnection();
        System.out.println(conn.execute("ENABLE TABLE foo"));

        // Or using the API
        conn.enableTable("foo");

        // END SNIPPET: enable-table

    }
View Full Code Here

    public void disableTable() throws HBqlException {

        // START SNIPPET: disable-table

        HConnection conn = HConnectionManager.newConnection();
        conn.execute("DISABLE TABLE foo");

        // Or using the API
        conn.disableTable("foo");

        // END SNIPPET: disable-table

    }
View Full Code Here

    public void dropMapping() throws HBqlException {

        // START SNIPPET: drop-mapping

        HConnection conn = HConnectionManager.newConnection();

        conn.execute("DROP MAPPING fooMapping");

        // Or using the API
        conn.dropMapping("fooMapping");

        // END SNIPPET: drop-mapping

    }
View Full Code Here

    public void createTable() throws HBqlException {

        // START SNIPPET: create-table

        HConnection conn = HConnectionManager.newConnection();
        conn.execute("CREATE TABLE foo (family1 (MAX_VERSIONS: 10), family2(), family3 (MAX_VERSIONS: 15))");

        // END SNIPPET: create-table

    }
View Full Code Here

    public void createIndex() throws HBqlException {

        // START SNIPPET: create-index

        HConnection conn = HConnectionManager.newConnection();
        conn.execute("CREATE INDEX fooidx ON fooMapping (family1:col1) INCLUDE (family1:col2, family1:col3)");

        // END SNIPPET: create-index

    }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hbase.hbql.client.HConnection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.