use of com.linkedin.pinot.common.data.MetricFieldSpec.DerivedMetricType in project pinot by linkedin.
the class ColumnMetadata method fromPropertiesConfiguration.
public static ColumnMetadata fromPropertiesConfiguration(String column, PropertiesConfiguration config) {
Builder builder = new Builder();
builder.setColumnName(column);
builder.setCardinality(config.getInt(getKeyFor(column, CARDINALITY)));
int totalDocs = config.getInt(getKeyFor(column, TOTAL_DOCS));
builder.setTotalDocs(totalDocs);
builder.setTotalRawDocs(config.getInt(getKeyFor(column, TOTAL_RAW_DOCS), totalDocs));
builder.setTotalAggDocs(config.getInt(getKeyFor(column, TOTAL_AGG_DOCS), 0));
DataType dataType = DataType.valueOf(config.getString(getKeyFor(column, DATA_TYPE)).toUpperCase());
builder.setDataType(dataType);
builder.setBitsPerElement(config.getInt(getKeyFor(column, BITS_PER_ELEMENT)));
builder.setStringColumnMaxLength(config.getInt(getKeyFor(column, DICTIONARY_ELEMENT_SIZE)));
builder.setFieldType(FieldType.valueOf(config.getString(getKeyFor(column, COLUMN_TYPE)).toUpperCase()));
builder.setIsSorted(config.getBoolean(getKeyFor(column, IS_SORTED)));
builder.setContainsNulls(config.getBoolean(getKeyFor(column, HAS_NULL_VALUE)));
builder.setHasDictionary(config.getBoolean(getKeyFor(column, HAS_DICTIONARY), true));
builder.setHasInvertedIndex(config.getBoolean(getKeyFor(column, HAS_INVERTED_INDEX)));
builder.setSingleValue(config.getBoolean(getKeyFor(column, IS_SINGLE_VALUED)));
builder.setMaxNumberOfMultiValues(config.getInt(getKeyFor(column, MAX_MULTI_VALUE_ELEMTS)));
builder.setTotalNumberOfEntries(config.getInt(getKeyFor(column, TOTAL_NUMBER_OF_ENTRIES)));
builder.setAutoGenerated(config.getBoolean(getKeyFor(column, IS_AUTO_GENERATED), false));
builder.setDefaultNullValueString(config.getString(getKeyFor(column, DEFAULT_NULL_VALUE), null));
builder.setTimeUnit(TimeUnit.valueOf(config.getString(TIME_UNIT, "DAYS").toUpperCase()));
char paddingCharacter = V1Constants.Str.LEGACY_STRING_PAD_CHAR;
if (config.containsKey(SEGMENT_PADDING_CHARACTER)) {
String padding = config.getString(SEGMENT_PADDING_CHARACTER);
paddingCharacter = StringEscapeUtils.unescapeJava(padding).charAt(0);
}
builder.setPaddingCharacter(paddingCharacter);
// DERIVED_METRIC_TYPE property is used to check whether this field is derived or not
// ORIGIN_COLUMN property is used to indicate the origin field of this derived metric
String typeStr = config.getString(getKeyFor(column, DERIVED_METRIC_TYPE), null);
DerivedMetricType derivedMetricType = (typeStr == null) ? null : DerivedMetricType.valueOf(typeStr.toUpperCase());
if (derivedMetricType != null) {
switch(derivedMetricType) {
case HLL:
try {
final int hllLog2m = config.getInt(V1Constants.MetadataKeys.Segment.SEGMENT_HLL_LOG2M);
builder.setFieldSize(HllUtil.getHllFieldSizeFromLog2m(hllLog2m));
final String originColumnName = config.getString(getKeyFor(column, ORIGIN_COLUMN));
builder.setOriginColumnName(originColumnName);
} catch (RuntimeException e) {
LOGGER.error("Column: " + column + " is HLL derived column, but missing log2m, fieldSize or originColumnName.");
throw e;
}
break;
default:
throw new IllegalArgumentException("Column: " + column + " with derived metric Type: " + derivedMetricType + " is not supported in building column metadata.");
}
builder.setDerivedMetricType(derivedMetricType);
}
// Set min/max value if available.
String minString = config.getString(getKeyFor(column, MIN_VALUE), null);
String maxString = config.getString(getKeyFor(column, MAX_VALUE), null);
if ((minString != null) && (maxString != null)) {
switch(dataType) {
case INT:
builder.setMinValue(Integer.valueOf(minString));
builder.setMaxValue(Integer.valueOf(maxString));
break;
case LONG:
builder.setMinValue(Long.valueOf(minString));
builder.setMaxValue(Long.valueOf(maxString));
break;
case FLOAT:
builder.setMinValue(Float.valueOf(minString));
builder.setMaxValue(Float.valueOf(maxString));
break;
case DOUBLE:
builder.setMinValue(Double.valueOf(minString));
builder.setMaxValue(Double.valueOf(maxString));
break;
case STRING:
builder.setMinValue(minString);
builder.setMaxValue(maxString);
break;
default:
throw new IllegalStateException("Unsupported data type: " + dataType + " for column: " + column);
}
}
return builder.build();
}
Aggregations