Search in sources :

Example 1 with IndexTableInfo

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);
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) IOException(java.io.IOException) IndexTableInfo(org.apache.carbondata.core.metadata.schema.indextable.IndexTableInfo) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IndexMetadata(org.apache.carbondata.core.metadata.schema.indextable.IndexMetadata) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 2 with IndexTableInfo

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]));
}
Also used : IndexTableInfo(org.apache.carbondata.core.metadata.schema.indextable.IndexTableInfo) ArrayList(java.util.ArrayList) IndexTableExistException(org.apache.spark.sql.secondaryindex.exception.IndexTableExistException)

Example 3 with IndexTableInfo

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;
    }
}
Also used : IndexTableInfo(org.apache.carbondata.core.metadata.schema.indextable.IndexTableInfo) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

IndexTableInfo (org.apache.carbondata.core.metadata.schema.indextable.IndexTableInfo)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 IndexMetadata (org.apache.carbondata.core.metadata.schema.indextable.IndexMetadata)1 IndexTableExistException (org.apache.spark.sql.secondaryindex.exception.IndexTableExistException)1