/** * Returns the user-defined split order, or dimensions in order of descending cardinality (removes * excludes too) */ private List<String> computeSplitOrder(final Map<String, ColumnIndexCreationInfo> columnInfo) { List<String> splitOrder; if (starTreeIndexSpec.getSplitOrder() == null) { splitOrder = new ArrayList<String>(schema.getDimensionNames()); Collections.sort( splitOrder, new Comparator<String>() { @Override public int compare(String o1, String o2) { Object[] o1UniqueElements = columnInfo.get(o1).getSortedUniqueElementsArray(); Object[] o2UniqueElements = columnInfo.get(o2).getSortedUniqueElementsArray(); return o2UniqueElements.length - o1UniqueElements.length; // descending } }); } else { splitOrder = new ArrayList<String>(starTreeIndexSpec.getSplitOrder()); } if (starTreeIndexSpec.getSplitExcludes() != null) { splitOrder.removeAll(starTreeIndexSpec.getSplitExcludes()); } return splitOrder; }
/** Constructs the segment metadata file, and writes in outputDir */ private void writeMetadata(File outputDir, int totalDocs) throws ConfigurationException { final PropertiesConfiguration properties = new PropertiesConfiguration( new File(outputDir, V1Constants.MetadataKeys.METADATA_FILE_NAME)); properties.setProperty(SEGMENT_NAME, segmentName); properties.setProperty(TABLE_NAME, config.getTableName()); properties.setProperty(DIMENSIONS, config.getDimensions()); properties.setProperty(METRICS, config.getMetrics()); properties.setProperty(TIME_COLUMN_NAME, config.getTimeColumnName()); properties.setProperty(TIME_INTERVAL, "not_there"); properties.setProperty(SEGMENT_TOTAL_DOCS, String.valueOf(totalDocs)); // StarTree Joiner csv = Joiner.on(","); properties.setProperty(SPLIT_ORDER, csv.join(splitOrder)); properties.setProperty(SPLIT_EXCLUDES, csv.join(starTreeIndexSpec.getSplitExcludes())); properties.setProperty(MAX_LEAF_RECORDS, starTreeIndexSpec.getMaxLeafRecords()); properties.setProperty( EXCLUDED_DIMENSIONS, csv.join(starTreeIndexSpec.getExcludedDimensions())); String timeColumn = config.getTimeColumnName(); if (columnInfo.get(timeColumn) != null) { properties.setProperty(SEGMENT_START_TIME, columnInfo.get(timeColumn).getMin()); properties.setProperty(SEGMENT_END_TIME, columnInfo.get(timeColumn).getMax()); properties.setProperty(TIME_UNIT, config.getTimeUnitForSegment()); } if (config.containsKey(SEGMENT_START_TIME)) { properties.setProperty(SEGMENT_START_TIME, config.getStartTime()); } if (config.containsKey(SEGMENT_END_TIME)) { properties.setProperty(SEGMENT_END_TIME, config.getStartTime()); } if (config.containsKey(TIME_UNIT)) { properties.setProperty(TIME_UNIT, config.getTimeUnitForSegment()); } for (final String key : config.getAllCustomKeyValuePair().keySet()) { properties.setProperty(key, config.getAllCustomKeyValuePair().get(key)); } for (final String column : columnInfo.keySet()) { properties.setProperty( V1Constants.MetadataKeys.Column.getKeyFor(column, CARDINALITY), String.valueOf(columnInfo.get(column).getSortedUniqueElementsArray().length)); properties.setProperty( V1Constants.MetadataKeys.Column.getKeyFor(column, TOTAL_DOCS), String.valueOf(totalDocs)); properties.setProperty( V1Constants.MetadataKeys.Column.getKeyFor(column, DATA_TYPE), schema.getFieldSpecFor(column).getDataType().toString()); properties.setProperty( V1Constants.MetadataKeys.Column.getKeyFor(column, BITS_PER_ELEMENT), String.valueOf( SingleValueUnsortedForwardIndexCreator.getNumOfBits( columnInfo.get(column).getSortedUniqueElementsArray().length))); properties.setProperty( V1Constants.MetadataKeys.Column.getKeyFor(column, DICTIONARY_ELEMENT_SIZE), String.valueOf(dictionaryCreatorMap.get(column).getStringColumnMaxLength())); properties.setProperty( V1Constants.MetadataKeys.Column.getKeyFor(column, COLUMN_TYPE), String.valueOf(schema.getFieldSpecFor(column).getFieldType().toString())); properties.setProperty( V1Constants.MetadataKeys.Column.getKeyFor(column, IS_SORTED), String.valueOf(columnInfo.get(column).isSorted())); properties.setProperty( V1Constants.MetadataKeys.Column.getKeyFor(column, HAS_NULL_VALUE), String.valueOf(columnInfo.get(column).hasNulls())); properties.setProperty( V1Constants.MetadataKeys.Column.getKeyFor( column, V1Constants.MetadataKeys.Column.HAS_DICTIONARY), String.valueOf(columnInfo.get(column).isCreateDictionary())); properties.setProperty( V1Constants.MetadataKeys.Column.getKeyFor(column, HAS_INVERTED_INDEX), String.valueOf(true)); properties.setProperty( V1Constants.MetadataKeys.Column.getKeyFor(column, IS_SINGLE_VALUED), String.valueOf(schema.getFieldSpecFor(column).isSingleValueField())); properties.setProperty( V1Constants.MetadataKeys.Column.getKeyFor(column, MAX_MULTI_VALUE_ELEMTS), String.valueOf(columnInfo.get(column).getMaxNumberOfMutiValueElements())); properties.setProperty( V1Constants.MetadataKeys.Column.getKeyFor(column, TOTAL_NUMBER_OF_ENTRIES), String.valueOf(columnInfo.get(column).getTotalNumberOfEntries())); } properties.save(); }