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

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


        final byte[] family = Bytes.toBytes("family1");
        final byte[] author = Bytes.toBytes("author");
        final byte[] title = Bytes.toBytes("title");

        HConnection connection = HConnectionManager.newConnection();

        connection.execute("CREATE TEMP MAPPING testobjects alias testobjects2"
                           + "("
                           + "keyval key, "
                           + "family1 ("
                           + "  author string alias author, "
                           + "  title string  alias title"
                           + "))");

        HMapping mapping = connection.getMapping("testobjects");

        final RecordFilter filter = ((TableMapping)mapping)
                .newRecordFilter("title LIKE '.*3.*' OR family1:author LIKE '.*4.*'");

        Scan scan = new Scan();
View Full Code Here


        }
    }

    public static void main(String[] args) throws HBqlException {

        HConnection conn = HConnectionManager.newConnection();

        final HBatch<TestObject> batch = conn.newHBatch();
        for (int i = 0; i < 10; i++)
            batch.insert(new TestObject(i));

        batch.apply();

        final String query2 = "SELECT title, titles, author, authorVersions "
                              + "FROM TestObject "
                              + "WITH "
                              + "KEYS '0000000002' TO '0000000003', '0000000007' TO '0000000008' "
                              + "TIME RANGE NOW()-DAY(25) TO NOW()+DAY(1) "
                              + "VERSIONS 3 "
                              //+ "SERVER FILTER WHERE author LIKE '.*val.*' OR LENGTH(author) > 4 "
                              + "CLIENT FILTER WHERE author LIKE '.*val.*' OR LENGTH(author) > 4";

        HStatement stmt = conn.createStatement();
        HResultSet<TestObject> results2 = stmt.executeQuery(query2, TestObject.class);

        for (TestObject val2 : results2) {
            System.out.println("Current Values: " + val2.keyval + " - " + val2.author + " - " + val2.title);

View Full Code Here

                     + "    val4 int[] alias val8, "
                     + "    mapval1 object alias f3mapval1, "
                     + "    mapval2 object alias f3mapval2 "
                     + "))");

        HConnection conn = ((ConnectionImpl)connection).getHConnection();

        conn.execute("create table table2 (f1(), f2(), f3()) if not tableexists('table2')");
        conn.execute("delete from tab4");
    }
View Full Code Here

        }
    }

    void doQuery(final String id, final int iteration) throws HBqlException {

        HConnection connection = connectionPool.takeConnection();
        connection.execute("CREATE TEMP MAPPING pool_test "
                           + "("
                           + "keyval key, "
                           + "f1 ("
                           + "  val1 string alias val1, "
                           + "  val2 string alias val2, "
                           + "  val3 string alias val3 "
                           + ") "
                           + ") if not mappingexists('pool_test')");

        String sql = "SELECT count() as cnt FROM pool_test WITH CLIENT FILTER WHERE definedinrow(f1:val1)";
        List<HRecord> recs = connection.executeQueryAndFetch(sql);
        HRecord rec = recs.get(0);
        long cnt = (Long)rec.getCurrentValue("cnt");
        assertTrue(cnt == count);

        connection.close();

        System.out.println("Completed: " + id + " - " + iteration);
        try {
            Thread.sleep(10);
        }
View Full Code Here

        assertEvalFalse("'a' NOT IN ('a', 'b')");
        assertEvalTrue("NOT 'a' NOT IN ('a', 'b')");
        assertEvalFalse("'a' IN ('d', 'b')");
        assertEvalTrue("'a' NOT IN ('d', 'b')");

        HConnection connection = HConnectionManager.newConnection();
        final ObjectAllTypes obj = new ObjectAllTypes("aaabbb", 3, "aaab");

        assertReflectionEvalTrue(obj, "keyval CONTAINS 'ab'");
        assertReflectionEvalFalse(obj, "keyval CONTAINS 'ba'");
        assertReflectionEvalFalse(obj, "'asasas' CONTAINS stringValue");
View Full Code Here

    }

    @Test
    public void booleanParamFunctions() throws HBqlException {

        HConnection connection = HConnectionManager.newConnection();
        ExpressionTree tree;

        tree = parseExpr(":a CONTAINS :b");
        tree.setParameter("a", "abc");
        tree.setParameter("b", "b");
View Full Code Here

    }

    @Test
    public void regexFunctions() throws HBqlException {

        HConnection connection = HConnectionManager.newConnection();
        AnnotationAllTypesTest.setupMapping(connection);
        final AnnotatedAllTypes obj = new AnnotatedAllTypes("aaa", 3, "aaab");

        assertEvalTrue("'abc' like 'abc'");
        assertEvalFalse("'abc' not like 'abc'");
View Full Code Here

    }

    @Test
    public void objectFunctions() throws HBqlException {

        HConnection connection = HConnectionManager.newConnection();
        AnnotationAllTypesTest.setupMapping(connection);
        final AnnotatedAllTypes obj = new AnnotatedAllTypes("aaa", 3, "bbb");

        assertAnnotationEvalTrue(connection, obj, "stringValue between 'aaa' AND 'ccc'");
        assertAnnotationEvalTrue(connection, obj, "stringValue between 'aaa' AND 'ccc' AND stringValue between 'aaa' AND 'ccc'");
View Full Code Here

public class TableTest extends TestSupport {

    @Test
    public void simpleTable() throws HBqlException {

        HConnection connection = HConnectionManager.newConnection();

        assertFalse(connection.tableExists("zzz"));

        String tableName = "tabletest1";
        if (connection.tableExists(tableName)) {
            connection.disableTable(tableName);
            connection.dropTable(tableName);
        }
        assertFalse(connection.tableExists(tableName));
        connection.execute("CREATE TABLE " + tableName + " (family1(), family2(), family3())");
        assertTrue(connection.tableExists(tableName));
        HTableDescriptor table = connection.getHTableDescriptor(tableName);
        HColumnDescriptor[] hcd = table.getColumnFamilies();
        assertTrue((hcd.length == 3));
        assertTrue(table.hasFamily("family1".getBytes()));
        assertTrue(table.hasFamily("family2".getBytes()));
        assertTrue(table.hasFamily("family3".getBytes()));

        assertTrue(table.getNameAsString().equals(tableName));

        connection.disableTable(tableName);
        connection.dropTable(tableName);

        assertFalse(connection.mappingExists(tableName));
    }
View Full Code Here

    }

    @Test
    public void fullTable() throws HBqlException {

        HConnection connection = HConnectionManager.newConnection();

        String tableName = "tabletest1";
        if (connection.tableExists(tableName)) {
            connection.disableTable(tableName);
            connection.dropTable(tableName);
        }
        assertFalse(connection.tableExists(tableName));
        connection.execute("CREATE TABLE " + tableName
                           + " (family1 ("
                           + "MAX_VERSIONS:  12, "
                           + "BLOOMFILTER_TYPE:  ROW, "
                           + "BLOCK_SIZE: 123, "
                           + "BLOCK_CACHE_ENABLED: TRUE, "
                           + "COMPRESSION_TYPE: GZ, "
                           + "IN_MEMORY: TRUE, "
                           + "TTL: 440"
                           + "))");
        assertTrue(connection.tableExists(tableName));
        HTableDescriptor table = connection.getHTableDescriptor(tableName);
        HColumnDescriptor[] hcd = table.getColumnFamilies();
        assertTrue((hcd.length == 1));
        assertTrue(table.hasFamily("family1".getBytes()));
        assertTrue(table.getNameAsString().equals(tableName));

        HColumnDescriptor family = table.getFamily("family1".getBytes());

        assertTrue(family.getNameAsString().equals("family1"));
        assertTrue(family.getMaxVersions() == 12);
        assertTrue(family.getBloomFilterType() == StoreFile.BloomType.ROW);
        assertTrue(family.getBlocksize() == 123);
        assertTrue(family.isBlockCacheEnabled());
        assertTrue(family.getCompressionType() == Compression.Algorithm.GZ);
        assertTrue(family.isInMemory());
        assertTrue(family.getTimeToLive() == 440);

        connection.disableTable(tableName);
        connection.dropTable(tableName);

        assertFalse(connection.mappingExists(tableName));
    }
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.