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

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


    public void createAsynExecutorPool() throws HBqlException {

        // START SNIPPET: create-async-executor

        HConnection conn = HConnectionManager.newConnection();

        // Create AsyncExecutor named asyncExec if it doesn't already exist.
        conn.execute("CREATE ASYNC EXECUTOR asyncExec (MAX_THREAD_COUNT: 10) IF NOT asyncExecutorExists('asyncExec')");

        // Or, using the API
        if (!AsyncExecutorManager.asyncExecutorExists("asyncExec"))
            AsyncExecutorManager.newAsyncExecutor("asyncExec", 5, 10, Long.MAX_VALUE);

        // Then assign the connection an AsyncExecutor name to use for queries
        conn.setAsyncExecutorName("asyncExec");

        // Now use connection in a query.

        // END SNIPPET: create-async-executor
    }
View Full Code Here


    public void dropQueryExecutorPool() throws HBqlException {

        // START SNIPPET: drop-query-executor-pool

        HConnection conn = HConnectionManager.newConnection();

        conn.execute("DROP QUERY EXECUTOR POOL execPool IF queryExecutorPoolExists('execPool')");

        // Or, using the API
        if (QueryExecutorPoolManager.queryExecutorPoolExists("execPool"))
            QueryExecutorPoolManager.dropQueryExecutorPool("execPool");
View Full Code Here

    public void dropAsyncExecutor() throws HBqlException {

        // START SNIPPET: drop-async-executor

        HConnection conn = HConnectionManager.newConnection();

        conn.execute("DROP ASYNC EXECUTOR asyncExec IF asyncExecutorExists('asyncExec')");

        // Or, using the API
        if (AsyncExecutorManager.asyncExecutorExists("asyncExec"))
            AsyncExecutorManager.dropAsyncExecutor("asyncExec");
View Full Code Here

    public void index1() throws HBqlException {

        // START SNIPPET: index1

        HConnection conn = HConnectionManager.newConnection();

        conn.execute("CREATE TEMP MAPPING tab1 FOR TABLE table1"
                     + "("
                     + "keyval KEY WIDTH 15, "
                     + "f1 INCLUDE UNMAPPED ("
                     + "  val1 STRING WIDTH 10 ALIAS val1, "
                     + "  val2 INT ALIAS val5"
                     + "),  "
                     + "f2 INCLUDE UNMAPPED, "
                     + "f3 INCLUDE UNMAPPED ("
                     + "  val2 INT ALIAS val6, "
                     + "  val3 INT ALIAS val7 "
                     + "))");

        conn.execute("CREATE INDEX val1idx ON tab1 (val1) INCLUDE (val5, val6) IF NOT indexExistsForTable('val1idx', 'tab1')");

        HPreparedStatement pstmt = conn.prepareStatement("SELECT keyval, f1:val1, val5 FROM tab1 "
                                                         + "WITH INDEX val1idx KEYS FIRST TO :endkey "
                                                         + "INDEX FILTER WHERE val5 < 8 "
                                                         + "CLIENT FILTER WHERE val6 > 4");

        pstmt.setParameter("endkey", Util.getZeroPaddedNonNegativeNumber(34, 10));
View Full Code Here

    public void selectAll() throws HBqlException {

        // START SNIPPET: select1

        HConnection conn = HConnectionManager.newConnection();

        conn.execute("CREATE TEMP MAPPING tab1 FOR TABLE table1"
                     + "("
                     + "keyval KEY, "
                     + "f1 INCLUDE UNMAPPED ("
                     + "  val1 STRING ALIAS val1, "
                     + "  val2 INT ALIAS val5"
                     + "),  "
                     + "f2 INCLUDE UNMAPPED, "
                     + "f3 INCLUDE UNMAPPED ("
                     + "  val2 INT ALIAS val6, "
                     + "  val3 INT ALIAS val7 "
                     + "))");

        HPreparedStatement pstmt = conn.prepareStatement("SELECT keyval, f1:val1, val5 FROM tab1 "
                                                         + "WITH KEYS FIRST TO :endkey "
                                                         + "VERSIONS 4 "
                                                         + "CLIENT FILTER WHERE val6 > 4");

        pstmt.setParameter("endkey", Util.getZeroPaddedNonNegativeNumber(34, 10));
View Full Code Here

    public void definedSelect() throws HBqlException {

        // START SNIPPET: definedExample1

        // Get a connection to HBase
        HConnection conn = HConnectionManager.newConnection();

        // CREATE TEMP MAPPING
        conn.execute("CREATE TEMP MAPPING demo1 FOR TABLE example1"
                     + "("
                     + "keyval KEY, "
                     + "f1 ("
                     + "  val1 STRING ALIAS val1, "
                     + "  val2 INT ALIAS val2, "
                     + "  val3 STRING DEFAULT 'This is a default value' "
                     + "))");

        // Clean up table
        if (!conn.tableExists("example1"))
            conn.execute("CREATE TABLE example1 (f1()) ");
        else
            conn.execute("DELETE FROM demo1");

        // Add some records using an INSERT stmt
        HPreparedStatement stmt = conn.prepareStatement("INSERT INTO demo1 " +
                                                        "(keyval, val1, val2, f1:val3) VALUES " +
                                                        "(ZEROPAD(:key, 10), :val1, :val2, DEFAULT)");

        for (int i = 0; i < 5; i++) {
            stmt.setParameter("key", i);
            stmt.setParameter("val1", "Value: " + i);
            stmt.setParameter("val2", i);
            stmt.execute();
        }

        // Add some other records using the Record interface
        final HBatch<HRecord> batch = conn.newHBatch();
        for (int i = 5; i < 10; i++) {
            HRecord rec = conn.getMapping("demo1").newHRecord();
            rec.setCurrentValue("keyval", Util.getZeroPaddedNonNegativeNumber(i, 10));
            rec.setCurrentValue("val1", "Value: " + i);
            rec.setCurrentValue("f1:val2", i);
            batch.insert(rec);
        }
        batch.apply();

        // Query the records just added
        HResultSet<HRecord> records = conn.executeQuery("SELECT * FROM demo1");

        for (HRecord rec : records) {
            System.out.println("Key = " + rec.getCurrentValue("keyval"));
            System.out.println("f1:val1 = " + rec.getCurrentValue("val1"));
            System.out.println("f1:val2 = " + rec.getCurrentValue("f1:val2"));
View Full Code Here

        // START SNIPPET: hbqlapi1

        // Get a connection with an HTablePool size of 10
        HConnectionManager.setMaxPoolReferencesPerTablePerConnection(10);
        HConnection conn = HConnectionManager.newConnection();

        HStatement stmt = conn.createStatement();
        stmt.execute("CREATE TABLE table12 (f1(), f3()) IF NOT tableexists('table12')");

        stmt.execute("CREATE TEMP MAPPING sch9 FOR TABLE table12"
                     + "("
                     + "keyval key, "
                     + "f1 ("
                     + "    val1 string alias val1, "
                     + "    val2 string alias val2 "
                     + "), "
                     + "f3 ("
                     + "    val1 int alias val5, "
                     + "    val2 int alias val6 "
                     + "))");

        HResultSet<HRecord> rs = stmt.executeQuery("select * from sch9");

        for (HRecord rec : rs) {
            int val5 = (Integer)rec.getCurrentValue("val5");
            int val6 = (Integer)rec.getCurrentValue("val6");
            String val1 = (String)rec.getCurrentValue("val1");
            String val2 = (String)rec.getCurrentValue("val2");

            System.out.print("val5: " + val5);
            System.out.print(", val6: " + val6);
            System.out.print(", val1: " + val1);
            System.out.println(", val2: " + val2);
        }

        stmt.execute("DISABLE TABLE table12");
        stmt.execute("DROP TABLE table12");
        stmt.close();

        conn.close();

        // END SNIPPET: hbqlapi1
    }
View Full Code Here

        // Create Query Executor Pool named execPool if it doesn't already exist.
        if (!QueryExecutorPoolManager.queryExecutorPoolExists("execPool"))
            QueryExecutorPoolManager.newQueryExecutorPool("execPool", 5, 5, 10, Long.MAX_VALUE, true, 100);

        // Take a connection from the connection pool
        HConnection conn = connectionPool.takeConnection();

        // Assign the connection a query executor pool name to use for queries
        conn.setQueryExecutorPoolName("execPool");

        // Do something with the connection

        // Close the connection to release it back to the connection pool
        conn.close();

        // END SNIPPET: hbqlapi2
    }
View Full Code Here

    public void hbqlapi3() throws HBqlException {

        // START SNIPPET: hbqlapi3

        HConnection conn = HConnectionManager.newConnection();

        HStatement stmt = conn.createStatement();
        stmt.execute("CREATE TABLE table12 (f1(), f3()) IF NOT tableexists('table12')");

        stmt.execute("CREATE TEMP MAPPING sch9 FOR TABLE table12"
                     + "("
                     + "keyval key, "
                     + "f1 ("
                     + "    val1 string alias val1, "
                     + "    val2 string alias val2 "
                     + "), "
                     + "f3 ("
                     + "    val1 int alias val5, "
                     + "    val2 int alias val6 "
                     + "))");

        if (!AsyncExecutorManager.asyncExecutorExists("async1"))
            AsyncExecutorManager.newAsyncExecutor("async1", 1, 10, Long.MAX_VALUE);

        conn.setAsyncExecutorName("async1");

        QueryFuture future = stmt.executeQueryAsync("select * from sch9",
                                                    new QueryListenerAdapter<HRecord>() {
                                                        public void onEachRow(final HRecord rec) throws HBqlException {
                                                            int val5 = (Integer)rec.getCurrentValue("val5");
                                                            int val6 = (Integer)rec.getCurrentValue("val6");
                                                            String val1 = (String)rec.getCurrentValue("val1");
                                                            String val2 = (String)rec.getCurrentValue("val2");

                                                            System.out.print("val5: " + val5);
                                                            System.out.print(", val6: " + val6);
                                                            System.out.print(", val1: " + val1);
                                                            System.out.println(", val2: " + val2);
                                                        }

                                                        public void onException(final ExceptionSource source,
                                                                                final HBqlException e) {
                                                            e.printStackTrace();
                                                        }
                                                    });

        try {
            future.await();
        }
        catch (InterruptedException e) {
            e.printStackTrace();
        }

        stmt.close();

        conn.close();

        // END SNIPPET: hbqlapi3
    }
View Full Code Here

    public void annotatedSelect() throws HBqlException {

        // START SNIPPET: annotatedExample2

        // Get a connection to HBase
        HConnection conn = HConnectionManager.newConnection();

        conn.execute("CREATE TEMP MAPPING demo2 FOR TABLE example2"
                     + "("
                     + "keyval KEY, "
                     + "f1 ("
                     + "  val1 STRING ALIAS val1, "
                     + "  val2 INT ALIAS val2, "
                     + "  val3 STRING ALIAS val3 DEFAULT 'This is a default value' "
                     + "))");

        // Clean up table
        if (!conn.tableExists("example2"))
            conn.execute("CREATE TABLE example2 (f1())");
        else
            conn.execute("DELETE FROM demo2");

        // Add some records using an INSERT stmt
        HPreparedStatement stmt = conn.prepareStatement("INSERT INTO demo2 " +
                                                        "(keyval, val1, val2, val3) VALUES " +
                                                        "(ZEROPAD(:key, 10), :val1, :val2, DEFAULT)");

        for (int i = 0; i < 5; i++) {
            stmt.setParameter("key", i);
            stmt.setParameter("val1", "Value: " + i);
            stmt.setParameter("val2", i);
            stmt.execute();
        }

        // Add some other records using an AnnotatedExample object
        final HBatch<AnnotatedExample> batch = conn.newHBatch();
        for (int i = 5; i < 10; i++) {
            AnnotatedExample obj = new AnnotatedExample();
            obj.keyval = Util.getZeroPaddedNonNegativeNumber(i, 10);
            obj.val1 = "Value: " + i;
            obj.val2 = i;
            batch.insert(obj);
        }
        batch.apply();

        // Query the records just added
        HResultSet<AnnotatedExample> records = conn.executeQuery("SELECT * FROM demo2", AnnotatedExample.class);

        for (AnnotatedExample rec : records) {
            System.out.println("Key = " + rec.keyval);
            System.out.println("f1:val1 = " + rec.val1);
            System.out.println("f1:val2 = " + rec.val2);
            System.out.println("f1:val3 = " + rec.val3);
        }

        conn.close();

        // END SNIPPET: annotatedExample2
    }
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.