use of org.apache.carbondata.core.metadata.schema.table.TableInfo in project carbondata by apache.
the class ThriftWrapperSchemaConverterImpl method fromExternalToWrapperTableInfo.
/* (non-Javadoc)
* convert from external to wrapper tableinfo
*/
@Override
public TableInfo fromExternalToWrapperTableInfo(org.apache.carbondata.format.TableInfo externalTableInfo, String dbName, String tableName, String storePath) {
TableInfo wrapperTableInfo = new TableInfo();
List<org.apache.carbondata.format.SchemaEvolutionEntry> schemaEvolutionList = externalTableInfo.getFact_table().getSchema_evolution().getSchema_evolution_history();
wrapperTableInfo.setLastUpdatedTime(schemaEvolutionList.get(schemaEvolutionList.size() - 1).getTime_stamp());
wrapperTableInfo.setDatabaseName(dbName);
wrapperTableInfo.setTableUniqueName(dbName + "_" + tableName);
wrapperTableInfo.setStorePath(storePath);
wrapperTableInfo.setFactTable(fromExternalToWrapperTableSchema(externalTableInfo.getFact_table(), tableName));
List<TableSchema> aggTablesList = new ArrayList<TableSchema>();
int index = 0;
for (org.apache.carbondata.format.TableSchema aggTable : externalTableInfo.getAggregate_table_list()) {
aggTablesList.add(fromExternalToWrapperTableSchema(aggTable, "agg_table_" + index));
index++;
}
return wrapperTableInfo;
}
use of org.apache.carbondata.core.metadata.schema.table.TableInfo in project carbondata by apache.
the class DictionaryClientTest method setUp.
@Before
public void setUp() throws Exception {
// enable lru cache by setting cache size
CarbonProperties.getInstance().addProperty(CarbonCommonConstants.CARBON_MAX_DRIVER_LRU_CACHE_SIZE, "10");
// Create two column schemas and dimensions for the table
empColumnSchema = new ColumnSchema();
empColumnSchema.setColumnName("empNameCol");
empColumnSchema.setColumnUniqueId("empNameCol");
empColumnSchema.setDimensionColumn(true);
empColumnSchema.setEncodingList(Arrays.asList(Encoding.DICTIONARY));
empDimension = new CarbonDimension(empColumnSchema, 0, 0, 0, 0, 0);
ageColumnSchema = new ColumnSchema();
ageColumnSchema.setColumnName("empNameCol");
ageColumnSchema.setColumnUniqueId("empNameCol");
ageColumnSchema.setDimensionColumn(true);
ageColumnSchema.setEncodingList(Arrays.asList(Encoding.DICTIONARY));
ageDimension = new CarbonDimension(ageColumnSchema, 0, 0, 0, 0, 0);
// Create a Table
tableSchema = new TableSchema();
tableSchema.setTableName("TestTable");
tableSchema.setListOfColumns(Arrays.asList(empColumnSchema, ageColumnSchema));
CarbonMetadata metadata = CarbonMetadata.getInstance();
tableInfo = new TableInfo();
tableInfo.setFactTable(tableSchema);
tableInfo.setTableUniqueName("TestTable");
tableInfo.setDatabaseName("test");
storePath = System.getProperty("java.io.tmpdir") + "/tmp";
tableInfo.setStorePath(storePath);
CarbonTable carbonTable = new CarbonTable();
carbonTable.loadCarbonTable(tableInfo);
// Add the created table to metadata
metadata.addCarbonTable(carbonTable);
// Start the server for testing the client
server = DictionaryServer.getInstance(5678);
}
use of org.apache.carbondata.core.metadata.schema.table.TableInfo in project carbondata by apache.
the class ThriftWrapperSchemaConverterImplTest method testFromWrapperToExternalTableInfo.
@Test
public void testFromWrapperToExternalTableInfo() {
TableInfo wrapperTableInfo = new TableInfo();
String dbName = "dbName";
String tableName = "TableName";
final TableSchema wrapperTableSchema = new TableSchema();
final List<TableSchema> tableSchemas = new ArrayList<>();
tableSchemas.add(wrapperTableSchema);
new MockUp<SchemaEvolutionEntry>() {
@Mock
public List<ColumnSchema> getAdded() {
return columnSchemas;
}
@Mock
public List<ColumnSchema> getRemoved() {
return columnSchemas;
}
};
new MockUp<ColumnSchema>() {
@Mock
public List<Encoding> getEncodingList() {
return encodings;
}
@Mock
public int getSchemaOrdinal() {
return 1;
}
@Mock
public DataType getDataType() {
return DataType.BOOLEAN;
}
@Mock
public String getColumnName() {
return "columnName";
}
@Mock
public String getColumnUniqueId() {
return "1";
}
@Mock
public boolean isColumnar() {
return true;
}
@Mock
public boolean isDimensionColumn() {
return true;
}
@Mock
public int getColumnGroupId() {
return 1;
}
@Mock
public int getScale() {
return 1;
}
@Mock
public int getPrecision() {
return 1;
}
@Mock
public int getNumberOfChild() {
return 1;
}
@Mock
public byte[] getDefaultValue() {
return new byte[] { 1, 2 };
}
@Mock
public Map<String, String> getColumnProperties() {
return columnPropertyMap;
}
@Mock
public boolean isInvisible() {
return true;
}
@Mock
public String getColumnReferenceId() {
return "1";
}
};
new MockUp<TableInfo>() {
@Mock
public TableSchema getFactTable() {
return wrapperTableSchema;
}
@Mock
public List<TableSchema> getAggregateTableList() {
return tableSchemas;
}
};
new MockUp<TableSchema>() {
@Mock
public List<ColumnSchema> getListOfColumns() {
return columnSchemas;
}
final SchemaEvolution schemaEvolution = new SchemaEvolution();
final Map mapTableProperties = new HashMap<String, String>();
@Mock
public SchemaEvolution getSchemaEvalution() {
return schemaEvolution;
}
@Mock
public String getTableId() {
return "tableId";
}
@Mock
public Map<String, String> getTableProperties() {
return mapTableProperties;
}
};
org.apache.carbondata.format.TableSchema thriftFactTable = new org.apache.carbondata.format.TableSchema("tableId", thriftColumnSchemas, schemaEvol);
List<org.apache.carbondata.format.TableSchema> thriftAggTables = new ArrayList<>();
thriftAggTables.add(thriftFactTable);
org.apache.carbondata.format.TableInfo actualResult = thriftWrapperSchemaConverter.fromWrapperToExternalTableInfo(wrapperTableInfo, dbName, tableName);
org.apache.carbondata.format.TableInfo expectedResult = new org.apache.carbondata.format.TableInfo(thriftFactTable, thriftAggTables);
assertEquals(expectedResult, actualResult);
}
use of org.apache.carbondata.core.metadata.schema.table.TableInfo in project carbondata by apache.
the class CarbonMetadataTest method getTableInfo.
private static TableInfo getTableInfo(long timeStamp) {
TableInfo info = new TableInfo();
info.setDatabaseName("carbonTestDatabase");
info.setLastUpdatedTime(timeStamp);
info.setTableUniqueName("carbonTestDatabase_carbonTestTable");
info.setFactTable(getTableSchema());
info.setStorePath("/test/store");
return info;
}
use of org.apache.carbondata.core.metadata.schema.table.TableInfo in project carbondata by apache.
the class SchemaReader method readCarbonTableFromStore.
public static CarbonTable readCarbonTableFromStore(AbsoluteTableIdentifier identifier) throws IOException {
CarbonTablePath carbonTablePath = CarbonStorePath.getCarbonTablePath(identifier);
String schemaFilePath = carbonTablePath.getSchemaFilePath();
if (FileFactory.isFileExist(schemaFilePath, FileFactory.FileType.LOCAL) || FileFactory.isFileExist(schemaFilePath, FileFactory.FileType.HDFS) || FileFactory.isFileExist(schemaFilePath, FileFactory.FileType.VIEWFS)) {
String tableName = identifier.getCarbonTableIdentifier().getTableName();
ThriftReader.TBaseCreator createTBase = new ThriftReader.TBaseCreator() {
public TBase create() {
return new org.apache.carbondata.format.TableInfo();
}
};
ThriftReader thriftReader = new ThriftReader(carbonTablePath.getSchemaFilePath(), createTBase);
thriftReader.open();
org.apache.carbondata.format.TableInfo tableInfo = (org.apache.carbondata.format.TableInfo) thriftReader.read();
thriftReader.close();
SchemaConverter schemaConverter = new ThriftWrapperSchemaConverterImpl();
TableInfo wrapperTableInfo = schemaConverter.fromExternalToWrapperTableInfo(tableInfo, identifier.getCarbonTableIdentifier().getDatabaseName(), tableName, identifier.getStorePath());
wrapperTableInfo.setMetaDataFilepath(CarbonTablePath.getFolderContainingFile(schemaFilePath));
CarbonMetadata.getInstance().loadTableMetadata(wrapperTableInfo);
return CarbonMetadata.getInstance().getCarbonTable(identifier.getCarbonTableIdentifier().getTableUniqueName());
} else {
throw new IOException("File does not exist: " + schemaFilePath);
}
}
Aggregations