当前位置: 首页 > 工具软件 > Hypertable > 使用案例 >

hypertable java_Hypertable Java ThriftAPI 使用笔记(1)

柳胜
2023-12-01

row_predicate --> RowInterval

//select x2 from tab_cdr_mini where row='ba10027296931352435797';

@Test

public void test1() {

Utils.print("test1");

IThriftClient client = ThriftClientPool.getInstance().getResource();

client.create(host, port);

ScanSpec scanSpec = new ScanSpec();

scanSpec.addToColumns("x2");

RowInterval ri = new RowInterval();

ri.setStart_row("ba10027296931352435797");

ri.setStart_inclusive(true);

ri.setEnd_row("ba10027296931352435797");

ri.setEnd_inclusive(true);

scanSpec.addToRow_intervals(ri);

try {

client.open_namespace(NAMESPACE);

client.open_scanner(TABLENAME, scanSpec);

client.scanner_handle_rowentry(new DLConsumer());

} catch (Exception e) {

e.printStackTrace();

Assert.assertFalse(true);

} finally {

ThriftClientPool.getInstance().freeResouce(client);

}

}

| row_predicate --> RowInterval

| column_value_predicate --> ColumnPredicate     //1. select x2 from tab_cdr_mini where x2="201209120100" and row='ba10027296931352435797';

//2. select x2 from tab_cdr_mini where x2=^"2012091201" and row='ba10027296931352435797';

@Test

public void test2() {

Utils.print("test2");

IThriftClient client = ThriftClientPool.getInstance().getResource();

client.create(host, port);

ScanSpec scanSpec = new ScanSpec();

scanSpec.addToColumns("x2");

ColumnPredicate cp = new ColumnPredicate();

cp.setColumn_family("x2");

//1.

//        cp.setOperation(ColumnPredicateOperation.EXACT_MATCH);

//        cp.setValue("201209120100");

//2.

cp.setOperation(ColumnPredicateOperation.PREFIX_MATCH);

cp.setValue("2012091201");

scanSpec.addToColumn_predicates(cp);

RowInterval ri = new RowInterval();

ri.setStart_row("ba10027296931352435797");

ri.setStart_inclusive(true);

ri.setEnd_row("ba10027296931352435797");

ri.setEnd_inclusive(true);

scanSpec.addToRow_intervals(ri);

try {

client.open_namespace(NAMESPACE);

client.open_scanner(TABLENAME, scanSpec);

client.scanner_handle_rowentry(new DLConsumer());

} catch (Exception e) {

e.printStackTrace();

Assert.assertFalse(true);

} finally {

ThriftClientPool.getInstance().freeResouce(client);

}

}

cell_predicate --> CellInterval     //select * from tab_cdr_mini where "ba10027296931352435797","x2:end_time_s"<=CELL<="ba10027296931352435797","f1:called_number_str";

@Test

public void test3() {

Utils.print("test3");

IThriftClient client = ThriftClientPool.getInstance().getResource();

client.create(host, port);

ScanSpec scanSpec = new ScanSpec();

CellInterval ci = new CellInterval();

ci.setStart_row("ba10027296931352435797");

ci.setStart_column("x2:end_time_s");

ci.setStart_inclusive(true);

ci.setEnd_row("ba10027296931352435797");

ci.setEnd_column("f1:called_number_str");

ci.setEnd_inclusive(true);

scanSpec.addToCell_intervals(ci);

try {

client.open_namespace(NAMESPACE);

client.open_scanner(TABLENAME, scanSpec);

client.scanner_handle_rowentry(new DLConsumer());

} catch (Exception e) {

e.printStackTrace();

Assert.assertFalse(true);

} finally {

ThriftClientPool.getInstance().freeResouce(client);

}

}

| row_predicate --> RowInterval

| timestamp_predicate --> setStart_time & setEnd_time     //select x2 from tab_cdr_mini where ('ba10027296931352435821'>row>='ba10027296931352435797') and "2012-09-11 17:00:36.320858936"<=TIMESTAMP<="2012-09-11 17:00:36.320858938";

@Test

public void test4() {

Utils.print("test4");

IThriftClient client = ThriftClientPool.getInstance().getResource();

client.create(host, port);

ScanSpec scanSpec = new ScanSpec();

scanSpec.addToColumns("x2");

RowInterval ri = new RowInterval();

ri.setStart_row("ba10027296931352435797");

ri.setStart_inclusive(true);

ri.setEnd_row("ba10027296931352435821");

ri.setEnd_inclusive(false);

scanSpec.addToRow_intervals(ri);

scanSpec.setStart_time(Long.valueOf("1347382836320858936"));

scanSpec.setEnd_time(Long.valueOf("1347382836320858938"));

try {

client.open_namespace(NAMESPACE);

client.open_scanner(TABLENAME, scanSpec);

client.scanner_handle_rowentry(new DLConsumer());

} catch (Exception e) {

e.printStackTrace();

Assert.assertFalse(true);

} finally {

ThriftClientPool.getInstance().freeResouce(client);

}

}

ROW REGEXP --> setRow_regexp     //select x2 from tab_cdr_mini where row regexp "^ba.*97$";

@Test

public void test5() {

Utils.print("test5");

IThriftClient client = ThriftClientPool.getInstance().getResource();

client.create(host, port);

ScanSpec scanSpec = new ScanSpec();

scanSpec.addToColumns("x2");

scanSpec.setRow_regexp("^ba.*97$");

try {

client.open_namespace(NAMESPACE);

client.open_scanner(TABLENAME, scanSpec);

client.scanner_handle_rowentry(new DLConsumer());

} catch (Exception e) {

e.printStackTrace();

Assert.assertFalse(true);

} finally {

ThriftClientPool.getInstance().freeResouce(client);

}

}

1.setColumn_family只能设置CF,不能设置为CF:CQ

2.如果设置了ColumnPredicate条件,那么addToColumns必须设置CF,且与ColumnPredicate设置保持一致。否者如果不设置,那么就是全表查询,返回全表数据。

 类似资料: