CarbonFooterWriter { public void writeFooter(FileFooter footer, long currentPosition) throws IOException { ThriftWriter thriftWriter = openThriftWriter(filePath); footer.setVersion(VERSION_NUMBER); try { thriftWriter.write(footer); thriftWriter.writeOffset(currentPosition); } catch (Exception e) { throw e; } finally { thriftWriter.close(); } } CarbonFooterWriter(String filePath); void writeFooter(FileFooter footer, long currentPosition);  }
@Test public void testWriteFactMetadata() throws IOException { deleteFile(); createFile(); CarbonFooterWriter writer = new CarbonFooterWriter(filePath); List<BlockletInfoColumnar> infoColumnars = getBlockletInfoColumnars(); int[] cardinalities = new int[] { 2, 4, 5, 7, 9, 10 }; List<ColumnSchema> columnSchema = Arrays.asList(new ColumnSchema[]{getDimensionColumn("IMEI1"), getDimensionColumn("IMEI2"), getDimensionColumn("IMEI3"), getDimensionColumn("IMEI4"), getDimensionColumn("IMEI5"), getDimensionColumn("IMEI6")}); List<org.apache.carbondata.core.carbon.metadata.schema.table.column.ColumnSchema> wrapperColumnSchema = Arrays.asList(new org.apache.carbondata.core.carbon.metadata.schema.table.column.ColumnSchema[]{getWrapperDimensionColumn("IMEI1"), getWrapperDimensionColumn("IMEI2"), getWrapperDimensionColumn("IMEI3"), getWrapperDimensionColumn("IMEI4"), getWrapperDimensionColumn("IMEI5"), getWrapperDimensionColumn("IMEI6")}); int[] colCardinality = CarbonUtil.getFormattedCardinality(cardinalities, wrapperColumnSchema); SegmentProperties segmentProperties = new SegmentProperties(wrapperColumnSchema, colCardinality); writer.writeFooter(CarbonMetadataUtil.convertFileFooter( infoColumnars, 6, cardinalities,columnSchema, segmentProperties ), 0); CarbonFooterReader metaDataReader = new CarbonFooterReader(filePath, 0); assertTrue(metaDataReader.readFooter() != null); }
@Test public void testReadFactMetadata() throws IOException { deleteFile(); createFile(); CarbonFooterWriter writer = new CarbonFooterWriter(filePath); List<BlockletInfoColumnar> infoColumnars = getBlockletInfoColumnars(); int[] cardinalities = new int[] { 2, 4, 5, 7, 9, 10}; List<ColumnSchema> columnSchema = Arrays.asList(new ColumnSchema[]{getDimensionColumn("IMEI1"), getDimensionColumn("IMEI2"), getDimensionColumn("IMEI3"), getDimensionColumn("IMEI4"), getDimensionColumn("IMEI5"), getDimensionColumn("IMEI6")}); List<org.apache.carbondata.core.carbon.metadata.schema.table.column.ColumnSchema> wrapperColumnSchema = Arrays.asList(new org.apache.carbondata.core.carbon.metadata.schema.table.column.ColumnSchema[]{getWrapperDimensionColumn("IMEI1"), getWrapperDimensionColumn("IMEI2"), getWrapperDimensionColumn("IMEI3"), getWrapperDimensionColumn("IMEI4"), getWrapperDimensionColumn("IMEI5"), getWrapperDimensionColumn("IMEI6")}); int[] colCardinality = CarbonUtil.getFormattedCardinality(cardinalities, wrapperColumnSchema); SegmentProperties segmentProperties = new SegmentProperties(wrapperColumnSchema, cardinalities); writer.writeFooter(CarbonMetadataUtil .convertFileFooter(infoColumnars, 6, colCardinality, columnSchema,segmentProperties), 0); CarbonFooterReader metaDataReader = new CarbonFooterReader(filePath, 0); List<BlockletInfoColumnar> nodeInfoColumnars = CarbonMetadataUtil.convertBlockletInfo(metaDataReader.readFooter()); assertTrue(nodeInfoColumnars.size() == infoColumnars.size()); }