Github user xuchuanyin commented on a diff in the pull request:
https://github.com/apache/carbondata/pull/2254#discussion_r185231346
--- Diff:
core/src/main/java/org/apache/carbondata/core/datamap/dev/DataMapFactory.java
---
@@ -27,74 +29,124 @@
import org.apache.carbondata.core.features.TableOperation;
import org.apache.carbondata.core.metadata.schema.table.CarbonTable;
import org.apache.carbondata.core.metadata.schema.table.DataMapSchema;
+import
org.apache.carbondata.core.metadata.schema.table.column.CarbonColumn;
import org.apache.carbondata.events.Event;
+import org.apache.commons.lang.StringUtils;
+
/**
- * Interface for datamap factory, it is responsible for creating the
datamap.
+ * Interface for datamap of index type, it is responsible for creating the
datamap.
*/
-public interface DataMapFactory<T extends DataMap> {
+public abstract class DataMapFactory<T extends DataMap> {
+
+ public static final String INDEX_COLUMNS = "INDEX_COLUMNS";
+ protected CarbonTable carbonTable;
+
+ public DataMapFactory(CarbonTable carbonTable) {
+ this.carbonTable = carbonTable;
+ }
/**
* Initialization of Datamap factory with the carbonTable and datamap
name
*/
- void init(CarbonTable carbonTable, DataMapSchema dataMapSchema)
+ public abstract void init(DataMapSchema dataMapSchema)
throws IOException, MalformedDataMapCommandException;
/**
* Return a new write for this datamap
*/
- DataMapWriter createWriter(Segment segment, String writeDirectoryPath);
+ public abstract DataMapWriter createWriter(Segment segment, String
shardName)
+ throws IOException;
+
+ public abstract DataMapRefresher createRefresher(Segment segment, String
shardName)
+ throws IOException;
/**
* Get the datamap for segmentid
*/
- List<T> getDataMaps(Segment segment) throws IOException;
+ public abstract List<T> getDataMaps(Segment segment) throws IOException;
/**
* Get datamaps for distributable object.
*/
- List<T> getDataMaps(DataMapDistributable distributable)
+ public abstract List<T> getDataMaps(DataMapDistributable distributable)
throws IOException;
/**
* Get all distributable objects of a segmentid
* @return
*/
- List<DataMapDistributable> toDistributable(Segment segment);
+ public abstract List<DataMapDistributable> toDistributable(Segment
segment);
/**
*
* @param event
*/
- void fireEvent(Event event);
+ public abstract void fireEvent(Event event);
/**
* Clears datamap of the segment
*/
- void clear(Segment segment);
+ public abstract void clear(Segment segment);
/**
* Clear all datamaps from memory
*/
- void clear();
+ public abstract void clear();
/**
* Return metadata of this datamap
*/
- DataMapMeta getMeta();
+ public abstract DataMapMeta getMeta();
/**
* Type of datamap whether it is FG or CG
*/
- DataMapLevel getDataMapType();
+ public abstract DataMapLevel getDataMapLevel();
/**
* delete datamap data if any
*/
- void deleteDatamapData();
+ public abstract void deleteDatamapData();
/**
* This function should return true is the input operation enum will
make the datamap become stale
*/
- boolean willBecomeStale(TableOperation operation);
+ public abstract boolean willBecomeStale(TableOperation operation);
+
+ /**
+ * Validate INDEX_COLUMNS property and return a array containing index
column name
+ * Following will be validated
+ * 1. require INDEX_COLUMNS property
+ * 2. INDEX_COLUMNS can't contains illegal argument(empty, blank)
+ * 3. INDEX_COLUMNS can't contains duplicate same columns
+ * 4. INDEX_COLUMNS should be exists in table columns
+ */
+ public void validateIndexedColumns(DataMapSchema dataMapSchema,
+ CarbonTable carbonTable) throws MalformedDataMapCommandException {
+ List<CarbonColumn> indexColumns =
carbonTable.getIndexedColumns(dataMapSchema);
+ Set<String> unique = new HashSet<>();
+ for (CarbonColumn indexColumn : indexColumns) {
+ unique.add(indexColumn.getColName());
+ }
+ if (unique.size() != indexColumns.size()) {
+ throw new MalformedDataMapCommandException(INDEX_COLUMNS + " has
duplicate column");
+ }
+ }
+
+ public static String[] getIndexColumns(DataMapSchema dataMapSchema)
+ throws MalformedDataMapCommandException {
+ String columns = dataMapSchema.getProperties().get(INDEX_COLUMNS);
+ if (columns == null) {
+ columns =
dataMapSchema.getProperties().get(INDEX_COLUMNS.toLowerCase());
+ }
+ if (columns == null) {
+ throw new MalformedDataMapCommandException(INDEX_COLUMNS + "
DMPROPERTY is required");
+ } else if (StringUtils.isBlank(columns)) {
--- End diff --
So, if we have a datamap which will create index for all the columns, we
must specify the index_columns, right?
---