Search in sources :

Example 1 with MalformedDataMapCommandException

use of org.apache.carbondata.common.exceptions.sql.MalformedDataMapCommandException in project carbondata by apache.

the class LuceneDataMapFactoryBase method validateAndGetIndexedColumns.

/**
 * validate Lucene DataMap
 * 1. require TEXT_COLUMNS property
 * 2. TEXT_COLUMNS can't contains illegal argument(empty, blank)
 * 3. TEXT_COLUMNS can't contains duplicate same columns
 * 4. TEXT_COLUMNS should be exists in table columns
 * 5. TEXT_COLUMNS support only String DataType columns
 */
private List<String> validateAndGetIndexedColumns(DataMapSchema dataMapSchema, CarbonTable carbonTable) throws MalformedDataMapCommandException {
    String textColumnsStr = dataMapSchema.getProperties().get(TEXT_COLUMNS);
    if (textColumnsStr == null || StringUtils.isBlank(textColumnsStr)) {
        throw new MalformedDataMapCommandException("Lucene DataMap require proper TEXT_COLUMNS property.");
    }
    String[] textColumns = textColumnsStr.split(",", -1);
    for (int i = 0; i < textColumns.length; i++) {
        textColumns[i] = textColumns[i].trim().toLowerCase();
    }
    for (int i = 0; i < textColumns.length; i++) {
        if (textColumns[i].isEmpty()) {
            throw new MalformedDataMapCommandException("TEXT_COLUMNS contains illegal argument.");
        }
        for (int j = i + 1; j < textColumns.length; j++) {
            if (textColumns[i].equals(textColumns[j])) {
                throw new MalformedDataMapCommandException("TEXT_COLUMNS has duplicate columns :" + textColumns[i]);
            }
        }
    }
    List<String> textColumnList = new ArrayList<String>(textColumns.length);
    for (int i = 0; i < textColumns.length; i++) {
        CarbonColumn column = carbonTable.getColumnByName(carbonTable.getTableName(), textColumns[i]);
        if (null == column) {
            throw new MalformedDataMapCommandException("TEXT_COLUMNS: " + textColumns[i] + " does not exist in table. Please check create DataMap statement.");
        } else if (column.getDataType() != DataTypes.STRING) {
            throw new MalformedDataMapCommandException("TEXT_COLUMNS only supports String column. " + "Unsupported column: " + textColumns[i] + ", DataType: " + column.getDataType());
        }
        textColumnList.add(column.getColName());
    }
    return textColumnList;
}
Also used : CarbonColumn(org.apache.carbondata.core.metadata.schema.table.column.CarbonColumn) MalformedDataMapCommandException(org.apache.carbondata.common.exceptions.sql.MalformedDataMapCommandException) ArrayList(java.util.ArrayList)

Example 2 with MalformedDataMapCommandException

use of org.apache.carbondata.common.exceptions.sql.MalformedDataMapCommandException in project carbondata by apache.

the class DataMapStoreManager method createAndRegisterDataMap.

/**
 * Return a new datamap instance and registered in the store manager.
 * The datamap is created using datamap name, datamap factory class and table identifier.
 */
// TODO: make it private
public TableDataMap createAndRegisterDataMap(CarbonTable table, DataMapSchema dataMapSchema) throws MalformedDataMapCommandException, IOException {
    DataMapFactory dataMapFactory;
    try {
        // try to create datamap by reflection to test whether it is a valid DataMapFactory class
        Class<? extends DataMapFactory> factoryClass = (Class<? extends DataMapFactory>) Class.forName(dataMapSchema.getProviderName());
        dataMapFactory = factoryClass.newInstance();
    } catch (ClassNotFoundException e) {
        throw new MalformedDataMapCommandException("DataMap '" + dataMapSchema.getProviderName() + "' not found");
    } catch (Throwable e) {
        throw new MetadataProcessException("failed to create DataMap '" + dataMapSchema.getProviderName() + "'", e);
    }
    return registerDataMap(table, dataMapSchema, dataMapFactory);
}
Also used : MetadataProcessException(org.apache.carbondata.common.exceptions.MetadataProcessException) MalformedDataMapCommandException(org.apache.carbondata.common.exceptions.sql.MalformedDataMapCommandException) BlockletDataMapFactory(org.apache.carbondata.core.indexstore.blockletindex.BlockletDataMapFactory) DataMapFactory(org.apache.carbondata.core.datamap.dev.DataMapFactory)

Example 3 with MalformedDataMapCommandException

use of org.apache.carbondata.common.exceptions.sql.MalformedDataMapCommandException in project carbondata by apache.

the class IndexDataMapProvider method initMeta.

@Override
public void initMeta(CarbonTable mainTable, DataMapSchema dataMapSchema, String ctasSqlStatement) throws MalformedDataMapCommandException, IOException {
    if (mainTable == null) {
        throw new MalformedDataMapCommandException("Parent table is required to create index datamap");
    }
    ArrayList<RelationIdentifier> relationIdentifiers = new ArrayList<>();
    dataMapSchema.setParentTables(relationIdentifiers);
    relationIdentifiers.add(new RelationIdentifier(mainTable.getDatabaseName(), mainTable.getTableName(), mainTable.getTableInfo().getFactTable().getTableId()));
    DataMapFactory dataMapFactory = createIndexDataMapFactory(dataMapSchema);
    DataMapStoreManager.getInstance().registerDataMap(mainTable, dataMapSchema, dataMapFactory);
    storageProvider.saveSchema(dataMapSchema);
}
Also used : MalformedDataMapCommandException(org.apache.carbondata.common.exceptions.sql.MalformedDataMapCommandException) ArrayList(java.util.ArrayList) DataMapFactory(org.apache.carbondata.core.datamap.dev.DataMapFactory) RelationIdentifier(org.apache.carbondata.core.metadata.schema.table.RelationIdentifier)

Example 4 with MalformedDataMapCommandException

use of org.apache.carbondata.common.exceptions.sql.MalformedDataMapCommandException in project carbondata by apache.

the class IndexDataMapProvider method getDataMapFactoryByShortName.

private DataMapFactory getDataMapFactoryByShortName(String providerName) throws MalformedDataMapCommandException {
    DataMapFactory dataMapFactory;
    String className = DataMapRegistry.getDataMapClassName(providerName);
    if (className != null) {
        try {
            Class<? extends DataMapFactory> datamapClass = (Class<? extends DataMapFactory>) Class.forName(providerName);
            dataMapFactory = datamapClass.newInstance();
        } catch (ClassNotFoundException ex) {
            throw new MalformedDataMapCommandException("DataMap '" + providerName + "' not found", ex);
        } catch (Throwable ex) {
            throw new MetadataProcessException("failed to create DataMap '" + providerName + "'", ex);
        }
    } else {
        throw new MalformedDataMapCommandException("DataMap '" + providerName + "' not found");
    }
    return dataMapFactory;
}
Also used : MetadataProcessException(org.apache.carbondata.common.exceptions.MetadataProcessException) MalformedDataMapCommandException(org.apache.carbondata.common.exceptions.sql.MalformedDataMapCommandException) DataMapFactory(org.apache.carbondata.core.datamap.dev.DataMapFactory)

Aggregations

MalformedDataMapCommandException (org.apache.carbondata.common.exceptions.sql.MalformedDataMapCommandException)4 DataMapFactory (org.apache.carbondata.core.datamap.dev.DataMapFactory)3 ArrayList (java.util.ArrayList)2 MetadataProcessException (org.apache.carbondata.common.exceptions.MetadataProcessException)2 BlockletDataMapFactory (org.apache.carbondata.core.indexstore.blockletindex.BlockletDataMapFactory)1 RelationIdentifier (org.apache.carbondata.core.metadata.schema.table.RelationIdentifier)1 CarbonColumn (org.apache.carbondata.core.metadata.schema.table.column.CarbonColumn)1