Hbase(补充)

1、用sqoop 从mysql数据库导入数据到hbase时:

    可以用    sqoop list-databases --connect jdbc:mysql://192.168.1.152:3306/ --username sqoop --password sqoop      测试是否可以连接到mysql数据库

2、hbase 命令时,无法删除打错的命令,解决办法:option——session options——Terminal——Enulation——选择Linux。       可以按住Ctrl +回车键删除

3、CRT 修改字体大小:option——session options——Terminal——Appearance——Front (修改背景颜色是current color scheme)

4、sqoop导入数据从mysql到hbase时,mysql中的数据类型可以使基本数据类型,不能是二进制类型的,导入hbase后,都以字节数组 存储

5、创建一个列簇压缩格式为snappy的表:  create 'CarData', { NAME => 'car', COMPRESSION => 'SNAPPY' }

6、如果修改表压缩格式为snappy:

     disable 'test'

     alter 'test', NAME => 'f', COMPRESSION => 'snappy'       

   NAME即column family,列族。HBase修改压缩格式,需要一个列族一个列族的修改。而且这个地方要小心,别将列族名字写错,或者大小写错误。因为这个地方任何错误,都会创建一个新的列族,且压缩格式为snappy。当然,假如你还是不小心创建了一个新列族的话,可以通过以下方式删除:

   alter 'test', {NAME=>'f', METHOD=>'delete'}

   enable 'test'

   major_compact 'test'

  describe 该表,验证是否生效

7、hbase 过滤时:

     scan.setTimeRange()      方法是左闭右开,根据数据的入库时间过滤

8、spark 从hbase 根据列值过滤器过滤出数据形成RDD:

    

   val conf = new SparkConf().setAppName("daycount")
//      .setMaster("local")
    val sc = new SparkContext(conf)
    val hbaseConf = HBaseConfiguration.create()
    val tablename = " "
    val sca=new Scan()
    val filter1=new SingleColumnValueFilter(Bytes.toBytes("gps"),
      Bytes.toBytes("GPSTime"),
      CompareOp.LESS,
      new BinaryComparator(Bytes.toBytes(getTodayZero_time)))
    filter1.setFilterIfMissing(true)
    val filter2=new SingleColumnValueFilter(Bytes.toBytes("gps"),
      Bytes.toBytes("GPSTime"),
      CompareOp.GREATER_OR_EQUAL,
      new BinaryComparator(Bytes.toBytes(getYesTZero_time)))
    filter2.setFilterIfMissing(true)
    val filterArr=new util.ArrayList[Filter]()
    filterArr.add(filter1)
    filterArr.add(filter2)
    val filterlist=new FilterList(FilterList.Operator.MUST_PASS_ALL,filterArr)
    sca.setFilter(filterlist)
 hbaseConf.set("hbase.zookeeper.quorum", "        ")
    hbaseConf.set("hbase.zookeeper.property.clientPort", "2181")
//    hbaseConf.set("hbase.zookeep.znode.parent", "/hbase")
//    hbaseConf.set("hbase.master", "   ")
    hbaseConf.set(TableInputFormat.INPUT_TABLE, tablename)
    hbaseConf.set(TableInputFormat.SCAN,convertScanToString(sca))
    val hBaseRDD = sc.newAPIHadoopRDD(hbaseConf, classOf[TableInputFormat],
      classOf[org.apache.hadoop.hbase.io.ImmutableBytesWritable],
      classOf[org.apache.hadoop.hbase.client.Result])

  

       

原文地址:https://www.cnblogs.com/liuwei6/p/6829992.html