use of org.apache.carbondata.core.metadata.schema.indextable.IndexTableInfo in project carbondata by apache.
the class CarbonTableReader method refreshIndexInfo.
private void refreshIndexInfo(CarbonTable carbonTable, Configuration config) {
Map<String, Map<String, Map<String, String>>> indexTableMap = new ConcurrentHashMap<>();
String indexInfo = config.get("indexInfo", IndexTableInfo.toGson(new IndexTableInfo[0]));
String parentTableName = config.get("parentTableName", "");
String parentTableId = config.get("parentTableId", "");
String parentTablePath = config.get("parentTablePath", "");
boolean isIndexTable = Boolean.getBoolean(config.get("isIndexTable", "false"));
IndexTableInfo[] indexTableInfos = IndexTableInfo.fromGson(indexInfo);
for (IndexTableInfo indexTableInfo : indexTableInfos) {
Map<String, String> indexProperties = indexTableInfo.getIndexProperties();
String indexProvider;
if (indexProperties != null) {
indexProvider = indexProperties.get(CarbonCommonConstants.INDEX_PROVIDER);
} else {
// in case if SI table has been created before the change CARBONDATA-3765,
// indexProperties variable will not be present. On direct upgrade of SI store,
// indexProperties will be null, in that case, create indexProperties from indexCols
// For details, refer
// {@link org.apache.spark.sql.secondaryindex.hive.CarbonInternalMetastore#refreshIndexInfo}
indexProperties = new HashMap<>();
indexProperties.put(CarbonCommonConstants.INDEX_COLUMNS, String.join(",", indexTableInfo.getIndexCols()));
indexProvider = IndexType.SI.getIndexProviderName();
indexProperties.put(CarbonCommonConstants.INDEX_PROVIDER, indexProvider);
indexProperties.put(CarbonCommonConstants.INDEX_STATUS, IndexStatus.DISABLED.name());
}
if (indexTableMap.get(indexProvider) == null) {
Map<String, Map<String, String>> indexTableInfoMap = new HashMap<>();
indexTableInfoMap.put(indexTableInfo.getTableName(), indexProperties);
indexTableMap.put(indexProvider, indexTableInfoMap);
} else {
indexTableMap.get(indexProvider).put(indexTableInfo.getTableName(), indexProperties);
}
}
IndexMetadata indexMetadata = new IndexMetadata(indexTableMap, parentTableName, isIndexTable, parentTablePath, parentTableId);
try {
carbonTable.getTableInfo().getFactTable().getTableProperties().put(carbonTable.getCarbonTableIdentifier().getTableId(), indexMetadata.serialize());
} catch (IOException e) {
LOGGER.error("Error serializing index metadata", e);
}
}
use of org.apache.carbondata.core.metadata.schema.indextable.IndexTableInfo in project carbondata by apache.
the class IndexTableUtil method checkAndAddIndexTable.
/**
* adds index table info into parent table properties
*/
public static String checkAndAddIndexTable(String gsonData, IndexTableInfo newIndexTable, boolean isSecondaryIndex) throws IndexTableExistException {
IndexTableInfo[] indexTableInfos = IndexTableInfo.fromGson(gsonData);
if (null == indexTableInfos) {
indexTableInfos = new IndexTableInfo[0];
}
List<IndexTableInfo> indexTables = new ArrayList<>(Arrays.asList(indexTableInfos));
if (isSecondaryIndex) {
for (IndexTableInfo indexTable : indexTableInfos) {
if (indexTable.getIndexProperties().get(CarbonCommonConstants.INDEX_PROVIDER).equalsIgnoreCase(IndexType.SI.getIndexProviderName())) {
if (indexTable.getIndexCols().size() == newIndexTable.getIndexCols().size()) {
// If column order is not same, then also index table creation should be successful
// eg., index1 is a,b,d and index2 is a,d,b. Both table creation should be successful
boolean isColumnOrderSame = true;
for (int i = 0; i < indexTable.getIndexCols().size(); i++) {
if (!indexTable.getIndexCols().get(i).equalsIgnoreCase(newIndexTable.getIndexCols().get(i))) {
isColumnOrderSame = false;
break;
}
}
if (isColumnOrderSame) {
throw new IndexTableExistException("Index Table with selected columns already exist");
}
}
}
}
}
indexTables.add(newIndexTable);
return IndexTableInfo.toGson(indexTables.toArray(new IndexTableInfo[0]));
}
use of org.apache.carbondata.core.metadata.schema.indextable.IndexTableInfo in project carbondata by apache.
the class CarbonTable method getIndexInfo.
public String getIndexInfo(String indexProvider) throws IOException {
deserializeIndexMetadata();
if (null != indexMetadata) {
if (null != indexProvider) {
if (null != indexMetadata.getIndexesMap().get(indexProvider)) {
IndexTableInfo[] indexTableInfos = new IndexTableInfo[indexMetadata.getIndexesMap().get(indexProvider).entrySet().size()];
int index = 0;
// In case of secondary index child table, return empty list of IndexTableInfo
if (!isIndexTable()) {
for (Map.Entry<String, Map<String, String>> entry : indexMetadata.getIndexesMap().get(indexProvider).entrySet()) {
indexTableInfos[index] = new IndexTableInfo(getDatabaseName(), entry.getKey(), entry.getValue());
index++;
}
return IndexTableInfo.toGson(indexTableInfos);
} else {
return IndexTableInfo.toGson(new IndexTableInfo[] {});
}
} else {
return IndexTableInfo.toGson(new IndexTableInfo[] {});
}
} else {
IndexTableInfo[] indexTableInfos = new IndexTableInfo[indexMetadata.getIndexTables().size()];
int index = 0;
if (!isIndexTable()) {
for (Map.Entry<String, Map<String, Map<String, String>>> entry : indexMetadata.getIndexesMap().entrySet()) {
for (Map.Entry<String, Map<String, String>> indexEntry : entry.getValue().entrySet()) {
indexTableInfos[index] = new IndexTableInfo(getDatabaseName(), indexEntry.getKey(), indexEntry.getValue());
index++;
}
}
return IndexTableInfo.toGson(indexTableInfos);
} else {
return IndexTableInfo.toGson(new IndexTableInfo[] {});
}
}
} else {
return null;
}
}
Aggregations