use of org.apache.carbondata.core.metadata.schema.table.DataMapSchema in project carbondata by apache.
the class ThriftWrapperSchemaConverterImpl method fromWrapperToExternalChildSchemaList.
private List<org.apache.carbondata.format.DataMapSchema> fromWrapperToExternalChildSchemaList(List<DataMapSchema> wrapperChildSchemaList) {
List<org.apache.carbondata.format.DataMapSchema> thriftChildSchemas = new ArrayList<>();
for (DataMapSchema wrapperChildSchema : wrapperChildSchemaList) {
org.apache.carbondata.format.DataMapSchema thriftChildSchema = new org.apache.carbondata.format.DataMapSchema();
if (wrapperChildSchema.getRelationIdentifier() != null) {
org.apache.carbondata.format.RelationIdentifier relationIdentifier = new org.apache.carbondata.format.RelationIdentifier();
relationIdentifier.setDatabaseName(wrapperChildSchema.getRelationIdentifier().getDatabaseName());
relationIdentifier.setTableName(wrapperChildSchema.getRelationIdentifier().getTableName());
relationIdentifier.setTableId(wrapperChildSchema.getRelationIdentifier().getTableId());
thriftChildSchema.setChildTableIdentifier(relationIdentifier);
}
thriftChildSchema.setProperties(wrapperChildSchema.getProperties());
thriftChildSchema.setClassName(wrapperChildSchema.getProviderName());
thriftChildSchema.setDataMapName(wrapperChildSchema.getDataMapName());
if (wrapperChildSchema.getChildSchema() != null) {
thriftChildSchema.setChildTableSchema(fromWrapperToExternalTableSchema(wrapperChildSchema.getChildSchema()));
}
thriftChildSchemas.add(thriftChildSchema);
}
return thriftChildSchemas;
}
use of org.apache.carbondata.core.metadata.schema.table.DataMapSchema in project carbondata by apache.
the class DataMapStatusManager method dropDataMap.
public static void dropDataMap(String dataMapName) throws IOException {
DataMapSchema dataMapSchema = validateDataMap(dataMapName, false);
List<DataMapSchema> list = new ArrayList<>();
if (dataMapSchema != null) {
list.add(dataMapSchema);
}
storageProvider.updateDataMapStatus(list, DataMapStatus.DROPPED);
}
use of org.apache.carbondata.core.metadata.schema.table.DataMapSchema in project carbondata by apache.
the class DiskBasedDataMapStatusProvider method updateDataMapStatus.
/**
* Update or add the status of passed datamaps with the given datamapstatus. If the datamapstatus
* given is enabled/disabled then updates/adds the datamap, in case of drop it just removes it
* from the file.
* This method always overwrites the old file.
* @param dataMapSchemas schemas of which are need to be updated in datamap status
* @param dataMapStatus status to be updated for the datamap schemas
* @throws IOException
*/
@Override
public void updateDataMapStatus(List<DataMapSchema> dataMapSchemas, DataMapStatus dataMapStatus) throws IOException {
ICarbonLock carbonTableStatusLock = getDataMapStatusLock();
boolean locked = false;
try {
locked = carbonTableStatusLock.lockWithRetries();
if (locked) {
LOG.info("Datamap status lock has been successfully acquired.");
DataMapStatusDetail[] dataMapStatusDetails = getDataMapStatusDetails();
List<DataMapStatusDetail> dataMapStatusList = Arrays.asList(dataMapStatusDetails);
dataMapStatusList = new ArrayList<>(dataMapStatusList);
List<DataMapStatusDetail> changedStatusDetails = new ArrayList<>();
List<DataMapStatusDetail> newStatusDetails = new ArrayList<>();
for (DataMapSchema dataMapSchema : dataMapSchemas) {
boolean exists = false;
for (DataMapStatusDetail statusDetail : dataMapStatusList) {
if (statusDetail.getDataMapName().equals(dataMapSchema.getDataMapName())) {
statusDetail.setStatus(dataMapStatus);
changedStatusDetails.add(statusDetail);
exists = true;
}
}
if (!exists) {
newStatusDetails.add(new DataMapStatusDetail(dataMapSchema.getDataMapName(), dataMapStatus));
}
}
// Add the newly added datamaps to the list.
if (newStatusDetails.size() > 0 && dataMapStatus != DataMapStatus.DROPPED) {
dataMapStatusList.addAll(newStatusDetails);
}
// In case of dropped datamap, just remove from the list.
if (dataMapStatus == DataMapStatus.DROPPED) {
dataMapStatusList.removeAll(changedStatusDetails);
}
writeLoadDetailsIntoFile(CarbonProperties.getInstance().getSystemFolderLocation() + CarbonCommonConstants.FILE_SEPARATOR + DATAMAP_STATUS_FILE, dataMapStatusList.toArray(new DataMapStatusDetail[dataMapStatusList.size()]));
} else {
String errorMsg = "Upadating datamapstatus is failed due to another process taken the lock" + " for updating it";
LOG.audit(errorMsg);
LOG.error(errorMsg);
throw new IOException(errorMsg + " Please try after some time.");
}
} finally {
if (locked) {
CarbonLockUtil.fileUnlock(carbonTableStatusLock, LockUsage.DATAMAP_STATUS_LOCK);
}
}
}
use of org.apache.carbondata.core.metadata.schema.table.DataMapSchema in project carbondata by apache.
the class DataMapStoreManager method getAllDataMapSchemas.
public List<DataMapSchema> getAllDataMapSchemas() {
DataMapSchemaStorageProvider provider = new DiskBasedDMSchemaStorageProvider(CarbonProperties.getInstance().getSystemFolderLocation());
List<DataMapSchema> dataMapSchemas;
try {
dataMapSchemas = provider.retrieveAllSchemas();
} catch (IOException e) {
throw new RuntimeException(e);
}
return dataMapSchemas;
}
use of org.apache.carbondata.core.metadata.schema.table.DataMapSchema in project carbondata by apache.
the class DataMapStoreManager method getAllDataMapSchemas.
/**
* It gives all datamap schemas.
*
* @return
*/
public List<DataMapSchema> getAllDataMapSchemas(CarbonTable carbonTable) {
// TODO cache all schemas and update only when datamap status file updates
List<DataMapSchema> dataMapSchemas = getAllDataMapSchemas();
List<DataMapSchema> dataMaps = new ArrayList<>();
if (dataMapSchemas != null) {
for (DataMapSchema dataMapSchema : dataMapSchemas) {
RelationIdentifier identifier = dataMapSchema.getParentTables().get(0);
if (dataMapSchema.isIndexDataMap() && identifier.getTableName().equals(carbonTable.getTableName()) && identifier.getDatabaseName().equals(carbonTable.getDatabaseName())) {
dataMaps.add(dataMapSchema);
}
}
}
return dataMaps;
}
Aggregations