@Test public void testTruncateTable() throws Exception { ValueFactory vf = SimpleValueFactory.getInstance(); Resource subj = vf.createIRI("http: IRI pred = vf.createIRI("http: Value expl = vf.createLiteral("explicit"); for (KeyValue kv : HalyardTableUtils.toKeyValues(subj, pred, expl, null, false, System.currentTimeMillis())) { table.put(new Put(kv.getRowArray(), kv.getRowOffset(), kv.getRowLength(), kv.getTimestamp()).add(kv)); } table.flushCommits(); try (ResultScanner rs = table.getScanner(HalyardTableUtils.scan(subj, pred, expl, null))) { assertNotNull(rs.next()); } table = HalyardTableUtils.truncateTable(table); try (ResultScanner rs = table.getScanner(HalyardTableUtils.scan(subj, pred, expl, null))) { assertNull(rs.next()); } }
public static HTable truncateTable(HTable table) throws IOException { Configuration conf = table.getConfiguration(); byte[][] presplits = table.getRegionLocator().getStartKeys(); if (presplits.length > 0 && presplits[0].length == 0) { presplits = Arrays.copyOfRange(presplits, 1, presplits.length); } HTableDescriptor desc = table.getTableDescriptor(); table.close(); try (Connection con = ConnectionFactory.createConnection(conf)) { try (Admin admin = con.getAdmin()) { admin.disableTable(desc.getTableName()); admin.deleteTable(desc.getTableName()); admin.createTable(desc, presplits); } } return HalyardTableUtils.getTable(conf, desc.getTableName().getNameAsString(), false, 0); }
HalyardTableUtils { public static HTable truncateTable(HTable table) throws IOException { Configuration conf = table.getConfiguration(); byte[][] presplits = table.getRegionLocator().getStartKeys(); if (presplits.length > 0 && presplits[0].length == 0) { presplits = Arrays.copyOfRange(presplits, 1, presplits.length); } HTableDescriptor desc = table.getTableDescriptor(); table.close(); try (Connection con = ConnectionFactory.createConnection(conf)) { try (Admin admin = con.getAdmin()) { admin.disableTable(desc.getTableName()); admin.deleteTable(desc.getTableName()); admin.createTable(desc, presplits); } } return HalyardTableUtils.getTable(conf, desc.getTableName().getNameAsString(), false, 0); } }
HalyardTableUtils { public static HTable truncateTable(HTable table) throws IOException { Configuration conf = table.getConfiguration(); byte[][] presplits = table.getRegionLocator().getStartKeys(); if (presplits.length > 0 && presplits[0].length == 0) { presplits = Arrays.copyOfRange(presplits, 1, presplits.length); } HTableDescriptor desc = table.getTableDescriptor(); table.close(); try (Connection con = ConnectionFactory.createConnection(conf)) { try (Admin admin = con.getAdmin()) { admin.disableTable(desc.getTableName()); admin.deleteTable(desc.getTableName()); admin.createTable(desc, presplits); } } return HalyardTableUtils.getTable(conf, desc.getTableName().getNameAsString(), false, 0); }  }
HalyardTableUtils { public static HTable truncateTable(HTable table) throws IOException { Configuration conf = table.getConfiguration(); byte[][] presplits = table.getRegionLocator().getStartKeys(); if (presplits.length > 0 && presplits[0].length == 0) { presplits = Arrays.copyOfRange(presplits, 1, presplits.length); } HTableDescriptor desc = table.getTableDescriptor(); table.close(); try (Connection con = ConnectionFactory.createConnection(conf)) { try (Admin admin = con.getAdmin()) { admin.disableTable(desc.getTableName()); admin.deleteTable(desc.getTableName()); admin.createTable(desc, presplits); } } return HalyardTableUtils.getTable(conf, desc.getTableName().getNameAsString(), false, 0); }  static HTable getTable(Configuration config, String tableName, boolean create, int splitBits); static HTable getTable(Configuration config, String tableName, boolean create, byte[][] splits); static HTable truncateTable(HTable table); static KeyValue[] toKeyValues(Resource subj, IRI pred, Value obj, Resource context, boolean delete, long timestamp); static Scan scan(Resource subj, IRI pred, Value obj, Resource ctx); static Scan scan(byte[] subjHash, byte[] predHash, byte[] objHash, byte[] ctxHash); static List<Statement> parseStatements(Result res, ValueFactory vf); static Statement parseStatement(Cell c, ValueFactory vf); static Scan scan(byte[] startRow, byte[] stopRow); static byte[] concat(byte prefix, boolean trailingZero, byte[]...fragments); static byte[] hashKey(byte[] key); static byte[] hashKey(Value v); static String encode(byte b[]); static byte[] writeBytes(Value v); static Value readValue(byte[] b, ValueFactory vf); static Resource readResource(byte[] b, ValueFactory vf); static IRI readIRI(byte[] b, ValueFactory vf); }
HalyardTableUtils { public static HTable truncateTable(HTable table) throws IOException { Configuration conf = table.getConfiguration(); byte[][] presplits = table.getRegionLocator().getStartKeys(); if (presplits.length > 0 && presplits[0].length == 0) { presplits = Arrays.copyOfRange(presplits, 1, presplits.length); } HTableDescriptor desc = table.getTableDescriptor(); table.close(); try (Connection con = ConnectionFactory.createConnection(conf)) { try (Admin admin = con.getAdmin()) { admin.disableTable(desc.getTableName()); admin.deleteTable(desc.getTableName()); admin.createTable(desc, presplits); } } return HalyardTableUtils.getTable(conf, desc.getTableName().getNameAsString(), false, 0); }  static HTable getTable(Configuration config, String tableName, boolean create, int splitBits); static HTable getTable(Configuration config, String tableName, boolean create, byte[][] splits); static HTable truncateTable(HTable table); static KeyValue[] toKeyValues(Resource subj, IRI pred, Value obj, Resource context, boolean delete, long timestamp); static Scan scan(Resource subj, IRI pred, Value obj, Resource ctx); static Scan scan(byte[] subjHash, byte[] predHash, byte[] objHash, byte[] ctxHash); static List<Statement> parseStatements(Result res, ValueFactory vf); static Statement parseStatement(Cell c, ValueFactory vf); static Scan scan(byte[] startRow, byte[] stopRow); static byte[] concat(byte prefix, boolean trailingZero, byte[]...fragments); static byte[] hashKey(byte[] key); static byte[] hashKey(Value v); static String encode(byte b[]); static byte[] writeBytes(Value v); static Value readValue(byte[] b, ValueFactory vf); static Resource readResource(byte[] b, ValueFactory vf); static IRI readIRI(byte[] b, ValueFactory vf); static final byte SPO_PREFIX; static final byte POS_PREFIX; static final byte OSP_PREFIX; static final byte CSPO_PREFIX; static final byte CPOS_PREFIX; static final byte COSP_PREFIX; static final byte KEY_SIZE; static final byte[] STOP_KEY; }