hbase各种遍历查询shell语句 包含过滤组合条件
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- import org.apache.hadoop.conf.Configuration;
- import org.apache.hadoop.hbase.Cell;
- import org.apache.hadoop.hbase.CellUtil;
- import org.apache.hadoop.hbase.HBaseConfiguration;
- import org.apache.hadoop.hbase.TableName;
- import org.apache.hadoop.hbase.client.Admin;
- import org.apache.hadoop.hbase.client.Connection;
- import org.apache.hadoop.hbase.client.ConnectionFactory;
- import org.apache.hadoop.hbase.client.Get;
- import org.apache.hadoop.hbase.client.Result;
- import org.apache.hadoop.hbase.client.ResultScanner;
- import org.apache.hadoop.hbase.client.Scan;
- import org.apache.hadoop.hbase.client.Table;
- import org.apache.hadoop.hbase.filter.BinaryComparator;
- import org.apache.hadoop.hbase.filter.ColumnCountGetFilter;
- import org.apache.hadoop.hbase.filter.ColumnPaginationFilter;
- import org.apache.hadoop.hbase.filter.ColumnPrefixFilter;
- import org.apache.hadoop.hbase.filter.ColumnRangeFilter;
- import org.apache.hadoop.hbase.filter.DependentColumnFilter;
- import org.apache.hadoop.hbase.filter.FamilyFilter;
- import org.apache.hadoop.hbase.filter.Filter;
- import org.apache.hadoop.hbase.filter.FilterList;
- import org.apache.hadoop.hbase.filter.FirstKeyOnlyFilter;
- import org.apache.hadoop.hbase.filter.FuzzyRowFilter;
- import org.apache.hadoop.hbase.filter.InclusiveStopFilter;
- import org.apache.hadoop.hbase.filter.KeyOnlyFilter;
- import org.apache.hadoop.hbase.filter.MultipleColumnPrefixFilter;
- import org.apache.hadoop.hbase.filter.PageFilter;
- import org.apache.hadoop.hbase.filter.PrefixFilter;
- import org.apache.hadoop.hbase.filter.QualifierFilter;
- import org.apache.hadoop.hbase.filter.RandomRowFilter;
- import org.apache.hadoop.hbase.filter.RegexStringComparator;
- import org.apache.hadoop.hbase.filter.RowFilter;
- import org.apache.hadoop.hbase.filter.SingleColumnValueExcludeFilter;
- import org.apache.hadoop.hbase.filter.SingleColumnValueFilter;
- import org.apache.hadoop.hbase.filter.SkipFilter;
- import org.apache.hadoop.hbase.filter.SubstringComparator;
- import org.apache.hadoop.hbase.filter.TimestampsFilter;
- import org.apache.hadoop.hbase.filter.ValueFilter;
- import org.apache.hadoop.hbase.filter.WhileMatchFilter;
- import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
- import org.apache.hadoop.hbase.util.Bytes;
- import org.apache.hadoop.hbase.util.Pair;
- public class HbaseUtils {
- public static Admin admin = null;
- public static Connection conn = null;
- public HbaseUtils() {
- Configuration conf = HBaseConfiguration.create();
- conf.set("hbase.zookeeper.quorum", "h71:2181");
- conf.set("hbase.rootdir", "hdfs://h71:9000/hbase");
- try {
- conn = ConnectionFactory.createConnection(conf);
- admin = conn.getAdmin();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- public static void main(String[] args) throws Exception {
- HbaseUtils hbase = new HbaseUtils();
- //1,FamilyFilter:基于“列族”来过滤数据;
- // hbase.FamilyFilter("scores");
- //2,QualifierFilter:基于“列名”来过滤数据;
- // hbase.QualifierFilter("scores");
- //3.RowFilter:基于rowkey来过滤数据;
- // hbase.RowFilter("scores","zhangsan01");
- //4.PrefixFilter:基于rowkey前缀来过滤数据;
- // hbase.PrefixFilter("scores","zhang");
- //后缀过滤数据
- // hbase.HouZui("scores");
- //5,ColumnPrefixFilter:基于列名前缀来过滤数据;
- // hbase.ColumnPrefixFilter("scores");
- //6,MultipleColumnPrefixFilter:ColumnPrefixFilter的加强版;
- // hbase.MultipleColumnPrefixFilter("scores");
- //7,ColumnCountGetFilter:限制每行返回多少列;
- // hbase.columnCountGetFilter();
- //8,ColumnPaginationFilter:对一行的所有列分页,只返回[limit, offset]范围内的列;
- // hbase.ColumnPaginationFilter("scores");
- //9,ColumnRangeFilter:可用于获得一个范围的列
- // hbase.ColumnRangeFilter("scores");
- //10,DependentColumnFilter:返回(与(符合条件[列族,列名]或[列族,列名,值]的参考列)具有相同的时间戳)的所有列,即:基于比较器过滤参考列,基于参考列的时间戳过滤其他列;
- // hbase.DependentColumnFilter("scores");
- //11,FirstKeyOnlyFilter:结果只返回每行的第一个值对;
- // hbase.FirstKeyOnlyFilter("scores");
- //12,FuzzyRowFilter:模糊row查询;
- // hbase.FuzzyRowFilter("scores");
- //13,InclusiveStopFilter:将stoprow也一起返回;
- // hbase.InclusiveStopFilter("scores");
- //14,KeyOnlyFilter:只返回行键;
- // hbase.KeyOnlyFilter("scores");
- //15,PageFilter: 取回XX条数据 ;
- // hbase.PageFilter("scores");
- //16,RandomRowFilter:随机获取一定比例(比例为参数)的数据;
- // hbase.RandomRowFilter("scores");
- //17,SingleColumnValueFilter:基于参考列的值来过滤数据;
- // hbase.SingleColumnValueFilter("scores");
- //18,ValueFilter:基于值来过滤数据;
- // hbase.ValueFilter("scores");
- //19,SkipFilter:当过滤器发现某一行中的一列要过滤时,就将整行数据都过滤掉;
- // hbase.SkipFilter("scores");
- //20,TimestampsFilter:基于时间戳来过滤数据;
- // hbase.TimestampsFilter("scores");
- //21,WhileMatchFilter:一旦遇到一条符合过滤条件的数据,就停止扫描;
- // hbase.WhileMatchFilter("scores");
- //22,FilterList:多个过滤器组合过滤。
- // hbase.FilterList("scores");
- }
- /**
- 1,FamilyFilter
- a,按family(列族)查找,取回所有符合条件的“family”
- b,构造方法第一个参数为compareOp
- c,第二个参数为WritableByteArrayComparable,有BinaryComparator, BinaryPrefixComparator,
- BitComparator, NullComparator, RegexStringComparator, SubstringComparator这些类,
- 最常用的为BinaryComparator
- */
- public void FamilyFilter(String tableName) throws Exception {
- Table table = conn.getTable(TableName.valueOf(tableName));
- Scan scan = new Scan();
- Filter filter = new FamilyFilter(CompareOp.LESS_OR_EQUAL, new BinaryComparator(Bytes.toBytes("grc")));
- scan.setFilter(filter);
- ResultScanner scanner = table.getScanner(scan);
- for (Result r : scanner) {
- for (Cell cell : r.rawCells()) {
- System.out.println(
- "Rowkey-->"+Bytes.toString(r.getRow())+" "+
- "Familiy:Quilifier-->"+Bytes.toString(CellUtil.cloneQualifier(cell))+" "+
- "Value-->"+Bytes.toString(CellUtil.cloneValue(cell)));
- }
- }
- }
- /*
- hbase(main):224:0> scan 'scores', {FILTER => "FamilyFilter(<=,'binary:grc')"}
- 或者
- hbase(main):011:0> scan 'scores', FILTER => "FamilyFilter(<=,'binary:grc')"
- ROW COLUMN+CELL
- lisi01 column=course:art, timestamp=1498003655021, value=89
- lisi01 column=course:math, timestamp=1498003561726, value=89
- lisi01 column=grade:, timestamp=1498003561726, value=201
- zhangsan01 column=course:art, timestamp=1498003561726, value=90
- zhangsan01 column=course:math, timestamp=1498003561726, value=99
- zhangsan01 column=grade:, timestamp=1498003593575, value=101
- zhangsan02 column=course:art, timestamp=1498003601365, value=90
- zhangsan02 column=course:math, timestamp=1498003561726, value=66
- zhangsan02 column=grade:, timestamp=1498003601365, value=102
- 3 row(s) in 0.0220 seconds
- */
- /**
- 2,QualifierFilter
- 类似于FamilyFilter,取回所有符合条件的“列”
- 构造方法第一个参数 compareOp
- 第二个参数为WritableByteArrayComparable
- */
- public void QualifierFilter(String tableName) throws Exception {
- Table table = conn.getTable(TableName.valueOf(tableName));
- Scan scan = new Scan();
- Filter filter = new QualifierFilter(CompareOp.LESS_OR_EQUAL, new BinaryComparator(Bytes.toBytes("grc")));
- //这里输的参数是相应位置比大小,及当输入ms的时候,所有列名的第一位小于等于m,如果第一位相等则比较第二位的大小。一开始没理解,所以一开始参数输入math或course的时候把我整懵了。
- scan.setFilter(filter);
- ResultScanner scanner = table.getScanner(scan);
- for (Result r : scanner) {
- for (Cell cell : r.rawCells()) {
- System.out.println(
- "Rowkey-->"+Bytes.toString(r.getRow())+" "+
- "Familiy:Quilifier-->"+Bytes.toString(CellUtil.cloneQualifier(cell))+" "+
- "Value-->"+Bytes.toString(CellUtil.cloneValue(cell)));
- }
- }
- }
- /*
- hbase(main):221:0> scan 'scores', {FILTER => "QualifierFilter(<=,'binary:b')"}
- ROW COLUMN+CELL
- lisi01 column=course:art, timestamp=1498003655021, value=89
- lisi01 column=grade:, timestamp=1498003561726, value=201
- zhangsan01 column=course:art, timestamp=1498003561726, value=90
- zhangsan01 column=grade:, timestamp=1498003593575, value=101
- zhangsan02 column=course:art, timestamp=1498003601365, value=90
- zhangsan02 column=grade:, timestamp=1498003601365, value=102
- 3 row(s) in 0.0470 seconds
- */
- /**
- 3,RowFilter
- 构造方法参数设置类似于FamilyFilter,符合条件的row都返回
- 但是通过row查询时,如果知道开始结束的row,还是用scan的start和end方法更直接并且经测试速度快一半以上
- */
- public void RowFilter(String tableName, String reg) throws Exception {
- Table table = conn.getTable(TableName.valueOf(tableName));
- Scan scan = new Scan();
- //这个参数EQUAL很重要,如果参数不同,查询的结果也会不同
- // RowFilter filter = new RowFilter(CompareOp.EQUAL, new BinaryComparator(Bytes.toBytes(reg)));//这样写也行
- // Filter filter = new RowFilter(CompareOp.EQUAL, new BinaryComparator(Bytes.toBytes(reg)));
- Filter filter = new RowFilter(CompareOp.LESS_OR_EQUAL, new BinaryComparator(Bytes.toBytes(reg)));
- scan.setFilter(filter);
- ResultScanner scanner = table.getScanner(scan);
- for (Result r : scanner) {
- for (Cell cell : r.rawCells()) {
- System.out.println(
- "Rowkey-->"+Bytes.toString(r.getRow())+" "+
- "Familiy:Quilifier-->"+Bytes.toString(CellUtil.cloneQualifier(cell))+" "+
- "Value-->"+Bytes.toString(CellUtil.cloneValue(cell)));
- }
- }
- /**
- * 更推荐用下面的方法直接指定起止行,因为filter本质上还是会遍历全部数据,而设定起止行后会直接从指定行开始,指定行结束,效率高很多。
- */
- // scan.setStartRow(Bytes.toBytes("AAAAAAAAAAAA"));
- // scan.setStopRow(Bytes.toBytes( "AAAAAAAAABBB"));
- }
- /*
- hbase(main):004:0> scan 'scores', {FILTER => "RowFilter(<=,'binary:zhangsan01')"}
- ROW COLUMN+CELL
- lisi01 column=course:art, timestamp=1498003655021, value=89
- lisi01 column=course:math, timestamp=1498003561726, value=89
- lisi01 column=grade:, timestamp=1498003561726, value=201
- zhangsan01 column=course:art, timestamp=1498003561726, value=90
- zhangsan01 column=course:math, timestamp=1498003561726, value=99
- zhangsan01 column=grade:, timestamp=1498003593575, value=101
- 2 row(s) in 0.0210 seconds
- */
- /**
- 4,PrefixFilter
- 取回rowkey以指定prefix开头的所有行
- */
- public void PrefixFilter(String tableName, String reg) throws Exception {
- Table table = conn.getTable(TableName.valueOf(tableName));
- Scan scan = new Scan();
- Filter filter = new PrefixFilter(Bytes.toBytes("zhang"));
- scan.setFilter(filter);
- ResultScanner scanner = table.getScanner(scan);
- for (Result r : scanner) {
- for (Cell cell : r.rawCells()) {
- System.out.println(
- "Rowkey-->"+Bytes.toString(r.getRow())+" "+
- "Familiy:Quilifier-->"+Bytes.toString(CellUtil.cloneQualifier(cell))+" "+
- "Value-->"+Bytes.toString(CellUtil.cloneValue(cell)));
- }
- }
- }
- /*
- hbase(main):022:0> scan 'scores', {FILTER => org.apache.hadoop.hbase.filter.PrefixFilter.new(org.apache.hadoop.hbase.util.Bytes.toBytes('li'))}
- 或者
- hbase(main):004:0> scan 'scores', {FILTER => "PrefixFilter('li')"}
- ROW COLUMN+CELL
- lisi01 column=course:art, timestamp=1489747672249, value=89
- lisi01 column=course:math, timestamp=1489747666861, value=89
- lisi01 column=grade:, timestamp=1489747677402, value=201
- 1 row(s) in 0.0110 seconds
- */
- /**
- 由于其原生带有PrefixFilter这种对ROWKEY的前缀过滤查询,因此想着实现的后缀查询的过程中,发现这一方面相对来说还是空白。
- 因此,只能采用一些策略来实现,主要还是采用正则表达式的方式。
- */
- public void HouZui(String tableName) throws Exception {
- Table table = conn.getTable(TableName.valueOf(tableName));
- Scan scan = new Scan();
- Filter filter = new RowFilter(CompareOp.EQUAL,new RegexStringComparator(".*n01"));
- scan.setFilter(filter);
- ResultScanner scanner = table.getScanner(scan);
- for (Result r : scanner) {
- for (Cell cell : r.rawCells()) {
- System.out.println(
- "Rowkey-->"+Bytes.toString(r.getRow())+" "+
- "Familiy:Quilifier-->"+Bytes.toString(CellUtil.cloneQualifier(cell))+" "+
- "Value-->"+Bytes.toString(CellUtil.cloneValue(cell)));
- }
- }
- }
- /*
- hbase(main):020:0> scan 'scores', {FILTER => "RowFilter(=,'regexstring:.*n01')"}
- ROW COLUMN+CELL
- zhangsan01 column=course:art, timestamp=1498003561726, value=90
- zhangsan01 column=course:math, timestamp=1498003561726, value=99
- zhangsan01 column=grade:, timestamp=1498003593575, value=101
- 1 row(s) in 0.0080 seconds
- */
- /**
- 5,ColumnPrefixFilter
- */
- public void ColumnPrefixFilter(String tableName) throws Exception {
- Table table = conn.getTable(TableName.valueOf(tableName));
- Scan scan = new Scan();
- byte[] prefix = Bytes.toBytes("ar");
- Filter filter = new ColumnPrefixFilter(prefix);
- scan.setFilter(filter);
- ResultScanner scanner = table.getScanner(scan);
- for (Result r : scanner) {
- for (Cell cell : r.rawCells()) {
- System.out.println(
- "Rowkey-->"+Bytes.toString(r.getRow())+" "+
- "Familiy:Quilifier-->"+Bytes.toString(CellUtil.cloneQualifier(cell))+" "+
- "Value-->"+Bytes.toString(CellUtil.cloneValue(cell)));
- }
- }
- }
- /*
- hbase(main):021:0> scan 'scores', {FILTER => "ColumnPrefixFilter('ar')"}
- 或者
- hbase(main):022:0> scan 'scores', {FILTER => org.apache.hadoop.hbase.filter.ColumnPrefixFilter.new(org.apache.hadoop.hbase.util.Bytes.toBytes('ar'))}
- ROW COLUMN+CELL
- lisi01 column=course:art, timestamp=1498003655021, value=89
- zhangsan01 column=course:art, timestamp=1498003561726, value=90
- zhangsan02 column=course:art, timestamp=1498003601365, value=90
- 3 row(s) in 0.0140 seconds
- */
- /**
- 6,MultipleColumnPrefixFilter
- a,返回有此前缀的所有列,
- b,在byte[][]中定义所有需要的列前缀,只要满足其中一条约束就会被返回(ColumnPrefixFilter的加强版),
- */
- public void MultipleColumnPrefixFilter(String tableName) throws Exception {
- Table table = conn.getTable(TableName.valueOf(tableName));
- Scan scan = new Scan();
- byte[][] prefix = {Bytes.toBytes("ar"),Bytes.toBytes("ma")};
- Filter filter = new MultipleColumnPrefixFilter(prefix);
- scan.setFilter(filter);
- ResultScanner scanner = table.getScanner(scan);
- for (Result r : scanner) {
- for (Cell cell : r.rawCells()) {
- System.out.println(
- "Rowkey-->"+Bytes.toString(r.getRow())+" "+
- "Familiy:Quilifier-->"+Bytes.toString(CellUtil.cloneQualifier(cell))+" "+
- "Value-->"+Bytes.toString(CellUtil.cloneValue(cell)));
- }
- }
- }
- /*
- hbase(main):023:0> scan 'scores', {FILTER => "MultipleColumnPrefixFilter('ar','ma')"}
- ROW COLUMN+CELL
- lisi01 column=course:art, timestamp=1498003655021, value=89
- lisi01 column=course:math, timestamp=1498003561726, value=89
- zhangsan01 column=course:art, timestamp=1498003561726, value=90
- zhangsan01 column=course:math, timestamp=1498003561726, value=99
- zhangsan02 column=course:art, timestamp=1498003601365, value=90
- zhangsan02 column=course:math, timestamp=1498003561726, value=66
- 3 row(s) in 0.0290 seconds
- */
- /**
- 7,ColumnCountGetFilter
- a,无法再scan中使用,只能在Get中
- b,若设为0,则无法返回数据,设为几就按服务器中存储位置取回几列
- c,可用size()取到列数,观察效果
- */
- public void columnCountGetFilter() throws Exception {
- Table table = conn.getTable(TableName.valueOf("scores"));
- Get get = new Get(Bytes.toBytes("zhangsan01"));
- get.setFilter(new ColumnCountGetFilter(2));
- Result result = table.get(get);
- //输出结果size,观察效果
- System.out.println(result.size());
- // byte[] value1 = result.getValue("course".getBytes(), "art".getBytes());
- // byte[] value2 = result.getValue("course".getBytes(), "math".getBytes());
- // System.out.println("course:art"+"-->"+new String(value1)+" "
- // +"course:math"+"-->"+new String(value2));
- }
- /*
- hbase(main):026:0> scan 'scores', {FILTER => "ColumnCountGetFilter(2)"}
- ROW COLUMN+CELL
- lisi01 column=course:art, timestamp=1498003655021, value=89
- lisi01 column=course:math, timestamp=1498003561726, value=89
- zhangsan01 column=course:art, timestamp=1498003561726, value=90
- zhangsan01 column=course:math, timestamp=1498003561726, value=99
- zhangsan02 column=course:art, timestamp=1498003601365, value=90
- zhangsan02 column=course:math, timestamp=1498003561726, value=66
- 3 row(s) in 0.0120 seconds
- */
- /**
- 8,ColumnPaginationFilter
- a,limit 表示返回列数
- b,offset 表示返回列的偏移量,如果为0,则全部取出,如果为1,则返回第二列及以后
- */
- public void ColumnPaginationFilter(String tableName) throws Exception {
- Table table = conn.getTable(TableName.valueOf(tableName));
- Scan scan = new Scan();
- Filter filter = new ColumnPaginationFilter(2,1);
- scan.setFilter(filter);
- // 用addFamily增加列族后,会只返回指定列族的数据
- scan.addFamily(Bytes.toBytes("course"));
- ResultScanner scanner = table.getScanner(scan);
- for (Result r : scanner) {
- for (Cell cell : r.rawCells()) {
- System.out.println(
- "Rowkey-->"+Bytes.toString(r.getRow())+" "+
- "Familiy:Quilifier-->"+Bytes.toString(CellUtil.cloneQualifier(cell))+" "+
- "Value-->"+Bytes.toString(CellUtil.cloneValue(cell)));
- }
- }
- }
- /*
- hbase(main):031:0> scan 'scores',{FILTER=>org.apache.hadoop.hbase.filter.ColumnPaginationFilter.new(2,1)}
- 或者
- hbase(main):030:0> scan 'scores',{FILTER=> "ColumnPaginationFilter(2,1)"}
- ROW COLUMN+CELL
- lisi01 column=course:math, timestamp=1498003561726, value=89
- lisi01 column=grade:, timestamp=1498003561726, value=201
- zhangsan01 column=course:math, timestamp=1498003561726, value=99
- zhangsan01 column=grade:, timestamp=1498003593575, value=101
- zhangsan02 column=course:math, timestamp=1498003561726, value=66
- zhangsan02 column=grade:, timestamp=1498003601365, value=102
- 3 row(s) in 0.0100 seconds
- */
- /**
- 9,ColumnRangeFilter
- 构造函数:
- ColumnRangeFilter(byte[] minColumn, boolean minColumnInclusive, byte[] maxColumn, boolean maxColumnInclusive)
- *可用于获得一个范围的列,例如,如果你的一行中有百万个列,但是你只希望查看列名为bbbb到dddd的范围
- *该过滤器可以进行高效的列名内部扫描。(为何是高效呢???因为列名是已经按字典排序好的)HBase-0.9.2 版本引入该功能。
- *一个列名是可以出现在多个列族中的,该过滤器将返回所有列族中匹配的列
- */
- public void ColumnRangeFilter(String tableName) throws Exception {
- Table table = conn.getTable(TableName.valueOf(tableName));
- Scan scan = new Scan();
- Filter filter = new ColumnRangeFilter(Bytes.toBytes("a"),true, Bytes.toBytes("n"),true);
- scan.setFilter(filter);
- ResultScanner scanner = table.getScanner(scan);
- for (Result r : scanner) {
- for (Cell cell : r.rawCells()) {
- System.out.println(
- "Rowkey-->"+Bytes.toString(r.getRow())+" "+
- "Familiy:Quilifier-->"+Bytes.toString(CellUtil.cloneQualifier(cell))+" "+
- "Value-->"+Bytes.toString(CellUtil.cloneValue(cell)));
- }
- }
- }
- /*
- hbase(main):032:0> scan 'scores',{FILTER=> "ColumnRangeFilter('a',true,'n',true)"}
- ROW COLUMN+CELL
- lisi01 column=course:art, timestamp=1498003655021, value=89
- lisi01 column=course:math, timestamp=1498003561726, value=89
- zhangsan01 column=course:art, timestamp=1498003561726, value=90
- zhangsan01 column=course:math, timestamp=1498003561726, value=99
- zhangsan02 column=course:art, timestamp=1498003601365, value=90
- zhangsan02 column=course:math, timestamp=1498003561726, value=66
- 3 row(s) in 0.0140 seconds
- */
- /**
- 10, DependentColumnFilter (该过滤器有两个参数:family和Qualifier,尝试找到该列所在的每一行,
- 并返回该行具有相同时间戳的全部键值对。如果某一行不包含指定的列,则该行的任何键值对都不返回,
- 该过滤器还可以有一个可选的布尔参数-如果为true,从属的列不返回;
- 该过滤器还可以有两个可选的参数--一个比较操作符和一个值比较器,用于family和Qualifier
- 的进一步检查,如果从属的列找到,其值还必须通过值检查,然后就是时间戳必须考虑)
- */
- public void DependentColumnFilter(String tableName) throws Exception {
- Table table = conn.getTable(TableName.valueOf(tableName));
- Scan scan = new Scan();
- // Filter filter = new DependentColumnFilter(Bytes.toBytes("course"), Bytes.toBytes("art"),false);
- // Filter filter = new DependentColumnFilter(Bytes.toBytes("course"), Bytes.toBytes("art"),true);
- Filter filter = new DependentColumnFilter(Bytes.toBytes("course"), Bytes.toBytes("art"),false,CompareOp.EQUAL,new BinaryComparator(Bytes.toBytes("90")));
- // Filter filter = new DependentColumnFilter(Bytes.toBytes("course"), Bytes.toBytes("art"),true,CompareOp.EQUAL,new BinaryComparator(Bytes.toBytes("90")));
- //上面这四种情况输出的for循环中的内容也不一样,要做相应的修改,否则会报java.lang.NullPointerException
- scan.setFilter(filter);
- ResultScanner scanner = table.getScanner(scan);
- for (Result r : scanner) {
- for (Cell cell : r.rawCells()) {
- System.out.println(
- "Rowkey-->"+Bytes.toString(r.getRow())+" "+
- "Familiy:Quilifier-->"+Bytes.toString(CellUtil.cloneQualifier(cell))+" "+
- "Value-->"+Bytes.toString(CellUtil.cloneValue(cell)));
- }
- }
- }
- /*
- hbase(main):036:0> scan 'scores',{FILTER=> "DependentColumnFilter('course','art',false,=,'binary:90')"}
- ROW COLUMN+CELL
- zhangsan01 column=course:art, timestamp=1498003561726, value=90
- zhangsan01 column=course:math, timestamp=1498003561726, value=99
- zhangsan02 column=course:art, timestamp=1498003601365, value=90
- zhangsan02 column=grade:, timestamp=1498003601365, value=102
- 2 row(s) in 0.0160 seconds
- */
- /**
- 11,FirstKeyOnlyFilter
- 如名字所示,结果只返回每行的第一个值对
- */
- public void FirstKeyOnlyFilter(String tableName) throws Exception {
- Table table = conn.getTable(TableName.valueOf(tableName));
- Scan scan = new Scan();
- Filter filter = new FirstKeyOnlyFilter();
- scan.setFilter(filter);
- ResultScanner scanner = table.getScanner(scan);
- for (Result r : scanner) {
- for (Cell cell : r.rawCells()) {
- System.out.println(
- "Rowkey-->"+Bytes.toString(r.getRow())+" "+
- "Familiy:Quilifier-->"+Bytes.toString(CellUtil.cloneQualifier(cell))+" "+
- "Value-->"+Bytes.toString(CellUtil.cloneValue(cell)));
- }
- }
- }
- /*
- hbase(main):037:0> scan 'scores',{FILTER=> "FirstKeyOnlyFilter()"}
- ROW COLUMN+CELL
- lisi01 column=course:art, timestamp=1498003655021, value=89
- zhangsan01 column=course:art, timestamp=1498003561726, value=90
- zhangsan02 column=course:art, timestamp=1498003601365, value=90
- 3 row(s) in 0.0160 seconds
- */
- /**
- 12,FuzzyRowFilter
- 模糊row查询
- pair中第一个参数为模糊查询的string
- 第二个参数为byte[]其中装与string位数相同的数值0或1,0表示该位必须与string中值相同,1表示可以不同
- */
- public void FuzzyRowFilter(String tableName) throws Exception {
- Table table = conn.getTable(TableName.valueOf(tableName));
- Scan scan = new Scan();
- Filter filter = new FuzzyRowFilter( Arrays.asList(new Pair<byte[], byte[]>(Bytes.toBytes("zhangsan01"),
- new byte[] {0, 0, 0, 0 , 0, 0, 0, 0, 0, 1})));
- scan.setFilter(filter);
- ResultScanner scanner = table.getScanner(scan);
- for (Result r : scanner) {
- for (Cell cell : r.rawCells()) {
- System.out.println(
- "Rowkey-->"+Bytes.toString(r.getRow())+" "+
- "Familiy:Quilifier-->"+Bytes.toString(CellUtil.cloneQualifier(cell))+" "+
- "Value-->"+Bytes.toString(CellUtil.cloneValue(cell)));
- }
- }
- }
- /*
- 。。。。。
- */
- /**
- 13,InclusiveStopFilter
- 指定stopRow,程序在scan时从头扫描全部返回,直到stopRow停止(stopRow这行也会返回,然后scan停止)
- */
- public void InclusiveStopFilter(String tableName) throws Exception {
- Table table = conn.getTable(TableName.valueOf(tableName));
- Scan scan = new Scan();
- Filter filter = new InclusiveStopFilter(Bytes.toBytes("zhangsan01"));
- scan.setFilter(filter);
- ResultScanner scanner = table.getScanner(scan);
- for (Result r : scanner) {
- for (Cell cell : r.rawCells()) {
- System.out.println(
- "Rowkey-->"+Bytes.toString(r.getRow())+" "+
- "Familiy:Quilifier-->"+Bytes.toString(CellUtil.cloneQualifier(cell))+" "+
- "Value-->"+Bytes.toString(CellUtil.cloneValue(cell)));
- }
- }
- }
- /*
- hbase(main):012:0> scan 'scores', {FILTER => "InclusiveStopFilter('zhangsan01')"}
- ROW COLUMN+CELL
- lisi01 column=course:art, timestamp=1498003655021, value=89
- lisi01 column=course:math, timestamp=1498003561726, value=89
- lisi01 column=grade:, timestamp=1498003561726, value=201
- zhangsan01 column=course:art, timestamp=1498003561726, value=90
- zhangsan01 column=course:math, timestamp=1498003561726, value=99
- zhangsan01 column=grade:, timestamp=1498003593575, value=101
- 2 row(s) in 0.0170 seconds
- */
- /**
- 14,KeyOnlyFilter
- 只取key值,size正常,说明value不是没取而是在取的时候被重写为空(能打印,不是null)
- lenAsVal这个值没大搞明白,当设为false时打印为空,如果设为true时打印的将会是“口口口口”
- */
- public void KeyOnlyFilter(String tableName) throws Exception {
- Table table = conn.getTable(TableName.valueOf(tableName));
- Scan scan = new Scan();
- Filter filter = new KeyOnlyFilter(true);
- scan.setFilter(filter);
- ResultScanner scanner = table.getScanner(scan);
- for (Result r : scanner) {
- for (Cell cell : r.rawCells()) {
- System.out.println(
- "Rowkey-->"+Bytes.toString(r.getRow())+" "+
- "Familiy:Quilifier-->"+Bytes.toString(CellUtil.cloneQualifier(cell))+" "+
- "Value-->"+Bytes.toString(CellUtil.cloneValue(cell)));
- }
- }
- }
- /*
- hbase(main):016:0> scan 'scores', {FILTER => "KeyOnlyFilter(true)"}
- ROW COLUMN+CELL
- lisi01 column=course:art, timestamp=1498003655021, value=\x00\x00\x00\x02
- lisi01 column=course:math, timestamp=1498003561726, value=\x00\x00\x00\x02
- lisi01 column=grade:, timestamp=1498003561726, value=\x00\x00\x00\x03
- zhangsan01 column=course:art, timestamp=1498003561726, value=\x00\x00\x00\x02
- zhangsan01 column=course:math, timestamp=1498003561726, value=\x00\x00\x00\x02
- zhangsan01 column=grade:, timestamp=1498003593575, value=\x00\x00\x00\x03
- zhangsan02 column=course:art, timestamp=1498003601365, value=\x00\x00\x00\x02
- zhangsan02 column=course:math, timestamp=1498003561726, value=\x00\x00\x00\x02
- zhangsan02 column=grade:, timestamp=1498003601365, value=\x00\x00\x00\x03
- 3 row(s) in 0.0320 seconds
- hbase(main):015:0> scan 'scores', {FILTER => "KeyOnlyFilter(false)"}
- ROW COLUMN+CELL
- lisi01 column=course:art, timestamp=1498003655021, value=
- lisi01 column=course:math, timestamp=1498003561726, value=
- lisi01 column=grade:, timestamp=1498003561726, value=
- zhangsan01 column=course:art, timestamp=1498003561726, value=
- zhangsan01 column=course:math, timestamp=1498003561726, value=
- zhangsan01 column=grade:, timestamp=1498003593575, value=
- zhangsan02 column=course:art, timestamp=1498003601365, value=
- zhangsan02 column=course:math, timestamp=1498003561726, value=
- zhangsan02 column=grade:, timestamp=1498003601365, value=
- 3 row(s) in 0.0190 seconds
- */
- /**
- 15,PageFilter
- 取回XX条数据
- */
- public void PageFilter(String tableName) throws Exception {
- Table table = conn.getTable(TableName.valueOf(tableName));
- Scan scan = new Scan();
- Filter filter = new PageFilter(2);
- scan.setFilter(filter);
- ResultScanner scanner = table.getScanner(scan);
- for (Result r : scanner) {
- for (Cell cell : r.rawCells()) {
- System.out.println(
- "Rowkey-->"+Bytes.toString(r.getRow())+" "+
- "Familiy:Quilifier-->"+Bytes.toString(CellUtil.cloneQualifier(cell))+" "+
- "Value-->"+Bytes.toString(CellUtil.cloneValue(cell)));
- }
- }
- }
- /*
- hbase(main):017:0> scan 'scores', {FILTER => "PageFilter(2)"}
- ROW COLUMN+CELL
- lisi01 column=course:art, timestamp=1498003655021, value=89
- lisi01 column=course:math, timestamp=1498003561726, value=89
- lisi01 column=grade:, timestamp=1498003561726, value=201
- zhangsan01 column=course:art, timestamp=1498003561726, value=90
- zhangsan01 column=course:math, timestamp=1498003561726, value=99
- zhangsan01 column=grade:, timestamp=1498003593575, value=101
- 2 row(s) in 0.0130 seconds
- */
- /**
- 16,RandomRowFilter
- 参数小于0时一条查不出大于1值会返回所有,而想取随机行的话有效区间为0~1,值代表取到的几率
- */
- public void RandomRowFilter(String tableName) throws Exception {
- Table table = conn.getTable(TableName.valueOf(tableName));
- Scan scan = new Scan();
- Filter filter = new RandomRowFilter((float)0.5);
- //即使是0.5有时候也一条查不出来,有时候却全出来了,是几率并不是一定,那我就不知道这个具体有什么实际运用了。。。根据rowkey随机而不是根据列随机
- scan.setFilter(filter);
- ResultScanner scanner = table.getScanner(scan);
- for (Result r : scanner) {
- for (Cell cell : r.rawCells()) {
- System.out.println(
- "Rowkey-->"+Bytes.toString(r.getRow())+" "+
- "Familiy:Quilifier-->"+Bytes.toString(CellUtil.cloneQualifier(cell))+" "+
- "Value-->"+Bytes.toString(CellUtil.cloneValue(cell)));
- }
- }
- }
- /*
- 。。。。。
- */
- /**
- 17,SingleColumnValueFilter和SingleColumnValueExcludeFilter
- 用来查找并返回指定条件的列的数据
- a,如果查找时没有该列,两种filter都会把该行所有数据返回
- b,如果查找时有该列,但是不符合条件,则该行所有列都不返回
- c,如果找到该列,并且符合条件,前者返回所有列,后者返回除该列以外的所有列
- */
- public void SingleColumnValueFilter(String tableName) throws Exception {
- Table table = conn.getTable(TableName.valueOf(tableName));
- Scan scan = new Scan();
- //完整匹配字节数组
- // Filter filter = new SingleColumnValueFilter(Bytes.toBytes("course"), Bytes.toBytes("art"),CompareOp.EQUAL,new BinaryComparator(Bytes.toBytes("90")));
- //匹配正则表达式
- // Filter filter = new SingleColumnValueFilter(Bytes.toBytes("course"), Bytes.toBytes("art"),CompareOp.EQUAL,new RegexStringComparator("8"));
- //匹配是否包含子串,大小写不敏感
- // Filter filter = new SingleColumnValueFilter(Bytes.toBytes("course"), Bytes.toBytes("art"),CompareOp.EQUAL,new SubstringComparator("9"));
- Filter filter = new SingleColumnValueExcludeFilter(Bytes.toBytes("course"), Bytes.toBytes("art"), CompareOp.EQUAL,new SubstringComparator("9"));
- scan.setFilter(filter);
- ResultScanner scanner = table.getScanner(scan);
- for (Result r : scanner) {
- for (Cell cell : r.rawCells()) {
- System.out.println(
- "Rowkey-->"+Bytes.toString(r.getRow())+" "+
- "Familiy:Quilifier-->"+Bytes.toString(CellUtil.cloneQualifier(cell))+" "+
- "Value-->"+Bytes.toString(CellUtil.cloneValue(cell)));
- }
- }
- }
- /*
- hbase(main):032:0> scan 'scores', {FILTER => "SingleColumnValueExcludeFilter('course','art',=,'substring:9')"}
- ROW COLUMN+CELL
- lisi01 column=course:math, timestamp=1498003561726, value=89
- lisi01 column=grade:, timestamp=1498003561726, value=201
- zhangsan01 column=course:math, timestamp=1498003561726, value=99
- zhangsan01 column=grade:, timestamp=1498003593575, value=101
- zhangsan02 column=course:math, timestamp=1498003561726, value=66
- zhangsan02 column=grade:, timestamp=1498003601365, value=102
- 3 row(s) in 0.0150 seconds
- */
- /**
- 18,ValueFilter
- 按value全数据库搜索(全部列的value均会被检索)
- */
- public void ValueFilter(String tableName) throws Exception {
- Table table = conn.getTable(TableName.valueOf(tableName));
- Scan scan = new Scan();
- Filter filter = new ValueFilter(CompareOp.NOT_EQUAL,new BinaryComparator(Bytes.toBytes("102")));
- scan.setFilter(filter);
- ResultScanner scanner = table.getScanner(scan);
- for (Result r : scanner) {
- for (Cell cell : r.rawCells()) {
- System.out.println(
- "Rowkey-->"+Bytes.toString(r.getRow())+" "+
- "Familiy:Quilifier-->"+Bytes.toString(CellUtil.cloneQualifier(cell))+" "+
- "Value-->"+Bytes.toString(CellUtil.cloneValue(cell)));
- }
- }
- }
- /*
- NOT_EQUAL不知道该咋么表示。。。。。
- */
- /**
- 19,SkipFilter
- 根据整行中的每个列来做过滤,只要存在一列不满足条件,整行都被过滤掉。
- 例如,如果一行中的所有列代表的是不同物品的重量,则真实场景下这些数值都必须大于零,我们希望将那些包含任意列值为0的行都过滤掉。
- 在这个情况下,我们结合ValueFilter和SkipFilter共同实现该目的:
- scan.setFilter(new SkipFilter(new ValueFilter(CompareOp.NOT_EQUAL,new BinaryComparator(Bytes.toBytes(0))));
- */
- public void SkipFilter(String tableName) throws Exception {
- Table table = conn.getTable(TableName.valueOf(tableName));
- Scan scan = new Scan();
- Filter filter = new SkipFilter(new ValueFilter(CompareOp.NOT_EQUAL,new BinaryComparator(Bytes.toBytes("102"))));
- // Filter filter = new SkipFilter(new DependentColumnFilter(Bytes.toBytes("course"), Bytes.toBytes("art"),false,CompareOp.NOT_EQUAL,new BinaryComparator(Bytes.toBytes("90"))));
- //该过滤器需要配合其他过滤器来使用
- scan.setFilter(filter);
- ResultScanner scanner = table.getScanner(scan);
- for (Result r : scanner) {
- for (Cell cell : r.rawCells()) {
- System.out.println(
- "Rowkey-->"+Bytes.toString(r.getRow())+" "+
- "Familiy:Quilifier-->"+Bytes.toString(CellUtil.cloneQualifier(cell))+" "+
- "Value-->"+Bytes.toString(CellUtil.cloneValue(cell)));
- }
- }
- }
- /*
- 不知道咋么把两个过滤器嵌套使用。。。。。
- */
- /**
- 20,TimestampsFilter
- a,按时间戳搜索数据库
- b,需设定List<Long> 存放所有需要检索的时间戳,
- */
- public void TimestampsFilter(String tableName) throws Exception {
- Table table = conn.getTable(TableName.valueOf(tableName));
- Scan scan = new Scan();
- //ls中存放所有需要查找匹配的时间戳
- List<Long> ls = new ArrayList<Long>();
- ls.add((long)1498003561726L);
- ls.add((long)1498003601365L);
- //java语言的整型常量默认为int型,声明long型常量可以后加”l“或”L“
- Filter filter = new TimestampsFilter(ls);
- scan.setFilter(filter);
- ResultScanner scanner = table.getScanner(scan);
- // for (Result result : scanner) {
- // if(new String(result.getRow()).equals("zhangsan01")){
- // System.out.println(new String(result.getRow())+" "
- // +"course:art"+"-->"+new String(result.getValue(Bytes.toBytes("course"), Bytes.toBytes("art")))+" "
- // +"course:math"+"-->"+new String(result.getValue(Bytes.toBytes("course"), Bytes.toBytes("math"))));
- // }else if(new String(result.getRow()).equals("zhangsan02")){
- // System.out.println(new String(result.getRow())+" "
- // +"course:art"+"-->"+new String(result.getValue(Bytes.toBytes("course"), Bytes.toBytes("art")))+" "
- // +"course:math"+"-->"+new String(result.getValue(Bytes.toBytes("course"), Bytes.toBytes("math")))+" "
- // +"grade:"+"-->"+new String(result.getValue(Bytes.toBytes("grade"), Bytes.toBytes(""))));
- // }else{
- // System.out.println(new String(result.getRow())+" "
- // +"course:math"+"-->"+new String(result.getValue(Bytes.toBytes("course"), Bytes.toBytes("math")))+" "
- // +"grade:"+"-->"+new String(result.getValue(Bytes.toBytes("grade"), Bytes.toBytes(""))));
- // }
- // }
- for (Result r : scanner) {
- for (Cell cell : r.rawCells()) {
- System.out.println(
- "Rowkey-->"+Bytes.toString(r.getRow())+" "+
- "Familiy:Quilifier-->"+Bytes.toString(CellUtil.cloneQualifier(cell))+" "+
- "Value-->"+Bytes.toString(CellUtil.cloneValue(cell)));
- }
- }
- }
- /*
- hbase(main):039:0> scan 'scores', {FILTER => "TimestampsFilter(1498003561726,1498003601365)"}
- ROW COLUMN+CELL
- lisi01 column=course:math, timestamp=1498003561726, value=89
- lisi01 column=grade:, timestamp=1498003561726, value=201
- zhangsan01 column=course:art, timestamp=1498003561726, value=90
- zhangsan01 column=course:math, timestamp=1498003561726, value=99
- zhangsan02 column=course:art, timestamp=1498003601365, value=90
- zhangsan02 column=course:math, timestamp=1498003561726, value=66
- zhangsan02 column=grade:, timestamp=1498003601365, value=102
- 3 row(s) in 0.0160 seconds
- */
- /**
- 21,WhileMatchFilter
- 相当于while执行,直到不match就break了返回了。
- */
- public void WhileMatchFilter(String tableName) throws Exception {
- Table table = conn.getTable(TableName.valueOf(tableName));
- Scan scan = new Scan();
- Filter filter = new WhileMatchFilter(new ValueFilter(CompareOp.NOT_EQUAL,new BinaryComparator(Bytes.toBytes("101"))));
- scan.setFilter(filter);
- ResultScanner scanner = table.getScanner(scan);
- for (Result r : scanner) {
- for (Cell cell : r.rawCells()) {
- System.out.println(
- "Rowkey-->"+Bytes.toString(r.getRow())+" "+
- "Familiy:Quilifier-->"+Bytes.toString(CellUtil.cloneQualifier(cell))+" "+
- "Value-->"+Bytes.toString(CellUtil.cloneValue(cell)));
- }
- }
- }
- /*
- 。。。。。
- */
- /**
- 22,FilterList
- 代表一个过滤器链,它可以包含一组即将应用于目标数据集的过滤器,过滤器间具有“与”FilterList.Operator.MUST_PASS_ALL和“或”FilterList.Operator.MUST_PASS_ONE关系。
- 官网实例代码,两个“或”关系的过滤器的写法:
- */
- public void FilterList(String tableName) throws Exception {
- Table table = conn.getTable(TableName.valueOf(tableName));
- FilterList list = new FilterList(FilterList.Operator.MUST_PASS_ONE); //数据只要满足一组过滤器中的一个就可以
- SingleColumnValueFilter filter1 = new SingleColumnValueFilter(Bytes.toBytes("course"), Bytes.toBytes("math"),CompareOp.EQUAL,new BinaryComparator(Bytes.toBytes("89")));
- list.addFilter(filter1);
- SingleColumnValueFilter filter2 = new SingleColumnValueFilter(Bytes.toBytes("course"), Bytes.toBytes("math"),CompareOp.EQUAL,new BinaryComparator(Bytes.toBytes("66")));
- list.addFilter(filter2);
- Scan scan = new Scan();
- scan.setFilter(list);
- ResultScanner scanner = table.getScanner(scan);
- for (Result r : scanner) {
- for (Cell cell : r.rawCells()) {
- System.out.println(
- "Rowkey-->"+Bytes.toString(r.getRow())+" "+
- "Familiy:Quilifier-->"+Bytes.toString(CellUtil.cloneQualifier(cell))+" "+
- "Value-->"+Bytes.toString(CellUtil.cloneValue(cell)));
- }
- }
- }
- /*
- hbase(main):009:0> scan 'scores', {FILTER => "PrefixFilter('zhang') OR QualifierFilter(>=,'binary:b')"}
- ROW COLUMN+CELL
- lisi01 column=course:math, timestamp=1489747666861, value=89
- lisi01 column=grade:, timestamp=1489747677402, value=201
- zhangsan01 column=course:art, timestamp=1489747593360, value=90
- zhangsan01 column=course:math, timestamp=1489747589255, value=99
- zhangsan01 column=grade:, timestamp=1489747598001, value=101
- zhangsan02 column=course:art, timestamp=1489747607561, value=60
- zhangsan02 column=course:math, timestamp=1489747602883, value=66
- zhangsan02 column=grade:, timestamp=1489747614601, value=102
- 3 row(s) in 0.0180 seconds
- */
- }
上面有几个过滤器在hbase shell中没有找出,如果大家有找到的告诉我一声,一起进步。
参考:
http://blog.csdn.net/blue__yeah/article/details/41040399
http://blog.csdn.net/liangtingac/article/details/40078637
http://blog.csdn.net/u010967382/article/details/37653177
http://blog.csdn.net/sparkexpert/article/details/51942354
from:https://blog.csdn.net/m0_37739193/article/details/73615016
hbase各种遍历查询shell语句 包含过滤组合条件的更多相关文章
- mysq查询语句包含中文以及中文乱码,字符集 GBK、GB2312、UTF8的区别
一.查看mysql 字符集设置情况 使用Navicat for Mysql查看工具,打开命令列界面,输入show variables like '%char%';如下图,查看当前mysql字符集设置情 ...
- Kali学习笔记31:目录遍历漏洞、文件包含漏洞
文章的格式也许不是很好看,也没有什么合理的顺序 完全是想到什么写一些什么,但各个方面都涵盖到了 能耐下心看的朋友欢迎一起学习,大牛和杠精们请绕道 目录遍历漏洞: 应用程序如果有操作文件的功能,限制不严 ...
- CASE函数 sql server——分组查询(方法和思想) ref和out 一般处理程序结合反射技术统一执行客户端请求 遍历查询结果集,update数据 HBuilder设置APP状态栏
CASE函数 作用: 可以将查询结果集的某一列的字段值进行替换 它可以生成一个新列 相当于switch...case和 if..else 使用语法: case 表达式/字段 when 值 then ...
- Oracle 查询(SELECT)语句(一)
Ø 简介 本文介绍 Oracle 中查询(SELECT)语句的使用,在 SQL 中 SELECT 语句是相对内容较多的,也是相对比较复杂一点的,所以这里拿出来单独学习. 首先,我们先来理一下思路,我 ...
- 《Entity Framework 6 Recipes》中文翻译系列 (17) -----第三章 查询之分页、过滤和使用DateTime中的日期部分分组
翻译的初衷以及为什么选择<Entity Framework 6 Recipes>来学习,请看本系列开篇 3-12 分页和过滤 问题 你想使用分页和过滤来创建查询. 解决方案 假设你有如图3 ...
- {MySQL的逻辑查询语句的执行顺序}一 SELECT语句关键字的定义顺序 二 SELECT语句关键字的执行顺序 三 准备表和数据 四 准备SQL逻辑查询测试语句 五 执行顺序分析
MySQL的逻辑查询语句的执行顺序 阅读目录 一 SELECT语句关键字的定义顺序 二 SELECT语句关键字的执行顺序 三 准备表和数据 四 准备SQL逻辑查询测试语句 五 执行顺序分析 一 SEL ...
- 数组方法map(映射),reduce(规约),foreach(遍历),filter(过滤)
数组方法map(映射),reduce(规约),foreach(遍历),filter(过滤) map()方法返回一个由原数组中每一个元素调用一个指定方法后返回的新数组 reduce()方法接受一个函数作 ...
- 多表查询sql语句
多表查询sql语句 1 --解锁SCOTT用户 2 alter user scott account unlock 3 --检索指定的列 4 select job,ename,empno from e ...
- Entity Framework Code First 在Object Join Linq查询时出现全表查询的语句。
最近一个项目,使用微软的Entity Framework的ORM框架的项目,部署到现场后,出现了系统缓慢,多个客户端的内存溢出崩溃的问题. 打开了SQL Server Profiler(SQL Ser ...
随机推荐
- HTTPS协议原理透析
1.HTTPS本身并非协议,而是标准的HTTP协议架在SSL/TLS协议之上的一种结构.(一种不太合适的说法可以认为是两种协议的叠加).HTTP是工作在OSI7层模型的最上层,就是第7层:Applic ...
- 正确认识 DIV+CSS 概念
今天看到神采飞扬发表于前端观察的<DIV+CSS 请不要再忽悠人了>,讲的挺有深意的,尤其对于新手如何正确认识div,学习web标准,使用web标准建站应该有很大帮助.转载过来,共同分享. ...
- Linux电源管理(5)_Hibernate和Sleep功能介绍【转】
本文转载自:http://www.wowotech.net/pm_subsystem/std_str_func.html 1. 前言 Hibernate和Sleep两个功能是Linux Generic ...
- python_unittest详解
一 整体结构概览 unittest原名为PyUnit,是由java的JUnit衍生而来.对于单元测试,需要设置预先条件,对比预期结果和实际结果. 整体结构:unittest库提供了test cases ...
- JS高阶函数的理解(函数作为参数传递)
JS高阶函数的理解 高阶函数是指至少满足下列条件之一的函数. · 函数可以作为参数被传递 · 函数可以作为返回值输出 一个例子,我们想在页面中创建100个div节点,这是一种写法.我们发现并不是所有用 ...
- Codeforces 294B Shaass and Bookshelf:dp
题目链接:http://codeforces.com/problemset/problem/294/B 题意: 有n本书,每本书的厚度为t[i],宽度为w[i] (1<=t[i]<=2, ...
- tomcat警告:Setting property 'source' to 'org.eclipse.jst.j2ee.server:ServletPro' did not find a matching property
警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclips ...
- Twitter的流处理器系统Heron——升级的storm,可以利用mesos来进行资源调度
2011年,Twitter发布了开源的分布式流计算系统Storm.四年后,随着用户数量的急剧增加,Twitter每天要处理的事件已经增加到十亿以上.Storm系统应对如此庞大而复杂多样的流数据变得十分 ...
- 关于c++中的全局变量(不赋值的全局变量算定义)
定义有三种: 1.不赋值的定义:int a; 2.赋值的定义:int a=5; 或者 int a;a=5; 3.加extern的定义:extern int a=5;//其实和不加是一样的. 声明只有一 ...
- 第十七章-异步IO
异步IO的出现源自于CPU速度与IO速度完全不匹配 一般的可以采用多线程或者多进程的方式来解决IO等待的问题 同样异步IO也可以解决同步IO所带来的问题 常见的异步IO的实现方式是使用一个消息循环, ...