/** * Convert schema to binary */ public static byte[] convertSchemaToBinary(List<ColumnSchema> columnSchemas) throws IOException { ByteArrayOutputStream stream = new ByteArrayOutputStream(); DataOutput dataOutput = new DataOutputStream(stream); dataOutput.writeShort(columnSchemas.size()); for (ColumnSchema columnSchema : columnSchemas) { if (columnSchema.getColumnReferenceId() == null) { columnSchema.setColumnReferenceId(columnSchema.getColumnUniqueId()); } columnSchema.write(dataOutput); } byte[] byteArray = stream.toByteArray(); // Compress to reduce the size of schema return CompressorFactory.NativeSupportedCompressor.SNAPPY.getCompressor().compressByte( byteArray); }
public static CarbonTable buildTable( String tablePath, String tableName, Configuration configuration) throws IOException { TableInfo tableInfoInfer = CarbonUtil.buildDummyTableInfo(tablePath, "null", "null"); CarbonFile carbonFile = getFirstIndexFile(FileFactory.getCarbonFile(tablePath, configuration)); if (carbonFile == null) { throw new RuntimeException("Carbon index file not exists."); } org.apache.carbondata.format.TableInfo tableInfo = CarbonUtil .inferSchemaFromIndexFile(carbonFile.getPath(), tableName); List<ColumnSchema> columnSchemaList = new ArrayList<ColumnSchema>(); for (org.apache.carbondata.format.ColumnSchema thriftColumnSchema : tableInfo .getFact_table().getTable_columns()) { ColumnSchema columnSchema = thriftColumnSchemaToWrapperColumnSchema(thriftColumnSchema); if (columnSchema.getColumnReferenceId() == null) { columnSchema.setColumnReferenceId(columnSchema.getColumnUniqueId()); } columnSchemaList.add(columnSchema); } tableInfoInfer.getFactTable().setListOfColumns(columnSchemaList); return CarbonTable.buildFromTableInfo(tableInfoInfer); }
thriftColumnSchema.setColumnProperties(wrapperColumnSchema.getColumnProperties()); thriftColumnSchema.setInvisible(wrapperColumnSchema.isInvisible()); thriftColumnSchema.setColumnReferenceId(wrapperColumnSchema.getColumnReferenceId()); thriftColumnSchema.setSchemaOrdinal(wrapperColumnSchema.getSchemaOrdinal()); if (wrapperColumnSchema.isSortColumn()) {