static public ATableDescriptor htdToATD(HTableDescriptor table) throws IOException { ATableDescriptor atd = new ATableDescriptor(); atd.name = ByteBuffer.wrap(table.getName()); Collection<HColumnDescriptor> families = table.getFamilies(); Schema afdSchema = Schema.createArray(AFamilyDescriptor.SCHEMA$); GenericData.Array<AFamilyDescriptor> afamilies = null; if (families.size() > 0) { afamilies = new GenericData.Array<AFamilyDescriptor>(families.size(), afdSchema); for (HColumnDescriptor hcd : families) { AFamilyDescriptor afamily = hcdToAFD(hcd); afamilies.add(afamily); } } else { afamilies = new GenericData.Array<AFamilyDescriptor>(0, afdSchema); } atd.families = afamilies; atd.maxFileSize = table.getMaxFileSize(); atd.memStoreFlushSize = table.getMemStoreFlushSize(); atd.rootRegion = table.isRootRegion(); atd.metaRegion = table.isMetaRegion(); atd.metaTable = table.isMetaTable(); atd.readOnly = table.isReadOnly(); atd.deferredLogFlush = table.isDeferredLogFlush(); return atd; }
static public HTableDescriptor atdToHTD(ATableDescriptor atd) throws IOException, AIllegalArgument { HTableDescriptor htd = new HTableDescriptor(Bytes.toBytes(atd.name)); if (atd.families != null && atd.families.size() > 0) { for (AFamilyDescriptor afd : atd.families) { htd.addFamily(afdToHCD(afd)); } } if (atd.maxFileSize != null) { htd.setMaxFileSize(atd.maxFileSize); } if (atd.memStoreFlushSize != null) { htd.setMemStoreFlushSize(atd.memStoreFlushSize); } if (atd.readOnly != null) { htd.setReadOnly(atd.readOnly); } if (atd.deferredLogFlush != null) { htd.setDeferredLogFlush(atd.deferredLogFlush); } if (atd.rootRegion != null || atd.metaRegion != null || atd.metaTable != null) { AIllegalArgument aie = new AIllegalArgument(); aie.message = new Utf8("Can't set root or meta flag on create table."); throw aie; } return htd; }
static public AFamilyDescriptor hcdToAFD(HColumnDescriptor hcd) throws IOException { AFamilyDescriptor afamily = new AFamilyDescriptor(); afamily.name = ByteBuffer.wrap(hcd.getName()); String compressionAlgorithm = hcd.getCompressionType().getName(); if (compressionAlgorithm == "LZO") { afamily.compression = ACompressionAlgorithm.LZO; } else if (compressionAlgorithm == "GZ") { afamily.compression = ACompressionAlgorithm.GZ; } else { afamily.compression = ACompressionAlgorithm.NONE; } afamily.maxVersions = hcd.getMaxVersions(); afamily.blocksize = hcd.getBlocksize(); afamily.inMemory = hcd.isInMemory(); afamily.timeToLive = hcd.getTimeToLive(); afamily.blockCacheEnabled = hcd.isBlockCacheEnabled(); return afamily; }
public AFamilyDescriptor describeFamily(ByteBuffer table, ByteBuffer family) throws AIOError { try { HTableDescriptor htd = admin.getTableDescriptor(Bytes.toBytes(table)); return AvroUtil.hcdToAFD(htd.getFamily(Bytes.toBytes(family))); } catch (IOException e) { AIOError ioe = new AIOError(); ioe.message = new Utf8(e.getMessage()); throw ioe; } }
public Void addFamily(ByteBuffer table, AFamilyDescriptor family) throws AIOError { try { admin.addColumn(Bytes.toBytes(table), AvroUtil.afdToHCD(family)); return null; } catch (IOException e) { AIOError ioe = new AIOError(); ioe.message = new Utf8(e.getMessage()); throw ioe; } }
public Void modifyFamily(ByteBuffer table, ByteBuffer familyName, AFamilyDescriptor familyDescriptor) throws AIOError { try { admin.modifyColumn(Bytes.toBytes(table), AvroUtil.afdToHCD(familyDescriptor)); return null; } catch (IOException e) { AIOError ioe = new AIOError(); ioe.message = new Utf8(e.getMessage()); throw ioe; } }
static public HColumnDescriptor afdToHCD(AFamilyDescriptor afd) throws IOException { HColumnDescriptor hcd = new HColumnDescriptor(Bytes.toBytes(afd.name)); ACompressionAlgorithm compressionAlgorithm = afd.compression; if (compressionAlgorithm == ACompressionAlgorithm.LZO) { hcd.setCompressionType(Compression.Algorithm.LZO); } else if (compressionAlgorithm == ACompressionAlgorithm.GZ) { hcd.setCompressionType(Compression.Algorithm.GZ); } else { hcd.setCompressionType(Compression.Algorithm.NONE); } if (afd.maxVersions != null) { hcd.setMaxVersions(afd.maxVersions); } if (afd.blocksize != null) { hcd.setBlocksize(afd.blocksize); } if (afd.inMemory != null) { hcd.setInMemory(afd.inMemory); } if (afd.timeToLive != null) { hcd.setTimeToLive(afd.timeToLive); } if (afd.blockCacheEnabled != null) { hcd.setBlockCacheEnabled(afd.blockCacheEnabled); } return hcd; }
/** * Tests for creating, modifying, and deleting column families. * * @throws Exception */ @Test public void testFamilyAdminAndMetadata() throws Exception { AvroServer.HBaseImpl impl = new AvroServer.HBaseImpl(TEST_UTIL.getConfiguration()); ATableDescriptor tableA = new ATableDescriptor(); tableA.name = tableAname; AFamilyDescriptor familyA = new AFamilyDescriptor(); familyA.name = familyAname; Schema familyArraySchema = Schema.createArray(AFamilyDescriptor.SCHEMA$); GenericArray<AFamilyDescriptor> families = new GenericData.Array<AFamilyDescriptor>(1, familyArraySchema); families.add(familyA); tableA.families = families; impl.createTable(tableA); assertEquals(impl.describeTable(tableAname).families.size(), 1); impl.disableTable(tableAname); assertFalse(impl.isTableEnabled(tableAname)); familyA.maxVersions = 123456; impl.modifyFamily(tableAname, familyAname, familyA); assertEquals((int) impl.describeFamily(tableAname, familyAname).maxVersions, 123456); impl.deleteFamily(tableAname, familyAname); assertEquals(impl.describeTable(tableAname).families.size(), 0); impl.deleteTable(tableAname); }