Get the App
SLTechnology News&Howtos  ›  Database  › 

Query and delete data according to conditions-HBase (pseudo-distribution) learning notes

Shulou Source: shulou.com Published: 2022-06-01 17:35:20 10月03日 Update

/ * * Delete all lines of RowKey * non-null judgment √ * / public static void deleteRows (String tablename,String RowKey) {HTable hull; HBaseAdmin ha=null; Get get=new Get (Bytes.toBytes (RowKey)); try {ha=new HBaseAdmin (config); if (ha.tableExists (tablename)) {h=new HTable (config,tablename) Delete d=new Delete (Bytes.toBytes (RowKey)); if (h.exists (get)) {h.delete (d); System.out.println ("deleted successfully");} else {System.out.println ("piss off!") }} else {System.out.println ("table? Your watch! ") ;} catch (Exception e) {e.printStackTrace ();} finally {try {h.close ();} catch (IOException e) {e.printStackTrace () } / * * Delete the specified row of data * * / public static void deleteRow (String tablename,String RowKey,String family,String qualifier) {HTable hull; try {h=new HTable (config,tablename); Delete d=new Delete (Bytes.toBytes (RowKey)) D.deleteColumn (Bytes.toBytes (family), Bytes.toBytes (qualifier)); h.delete (d); System.out.println ("deleted successfully!");} catch (IOException e) {e.printStackTrace ();} finally {try {h.close () } catch (IOException e) {e.printStackTrace ();} / * * query by condition (apply filter) * / @ SuppressWarnings ("deprecation") public static void GetByParam (String tablename,String Family,String qualifier,String value) {HTable hull; ResultScanner rs=null Try {h=new HTable (config,tablename); Filter f=new SingleColumnValueFilter (Bytes.toBytes (Family), Bytes.toBytes (qualifier), CompareOp.EQUAL,Bytes.toBytes (value)); Scan scan=new Scan (); scan.setFilter (f); scan.addColumn (Bytes.toBytes (Family), Bytes.toBytes (qualifier)) Rs=h.getScanner (scan); System.out.println ("Row cluster name value timestamp") For (Result r: rs) {for (KeyValue kv: r.raw ()) {System.out.println (kv.getRowOffset () + "+ Family+"+ qualifier+"+ new String (kv.getValue ()) +" + kv.getTimestamp ()) } catch (IOException e) {e.printStackTrace ();} finally {try {rs.close (); h.close () } catch (Exception e) {e.printStackTrace () } / * * query value * parameters by criteria: table name, row, column cluster, column name * / public static void get (String tablename,String rowKey,String Family,String qualifier) throws Exception {HConnection connection = HConnectionManager.createConnection (config); HTableInterface table = connection.getTable (TableName.valueOf (tablename)) Try {System.out.println ("start getting-beep beep"); Get get=new Get (rowKey.getBytes ()); get.addColumn (Family.getBytes (), qualifier.getBytes ()); Result r=table.get (get) For (KeyValue kv:r.raw ()) {System.out.println ("the value you want to check is" + new String (kv.getValue ();}} finally {table.close (); connection.close () }}

Tags: Conditions queries success data one row parameters time calves applications notes learning Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Apple MariaDB Shulou Information Shulou Tech Info