use of com.linkedin.pinot.common.data.TimeFieldSpec in project pinot by linkedin.
the class PinotSegmentRecordReader method getSchema.
@Override
public Schema getSchema() {
Schema schema = new Schema();
schema.setSchemaName(segmentMetadata.getName());
for (String column : columns) {
ColumnMetadata columnMetadata = segmentMetadata.getColumnMetadataFor(column);
String columnName = columnMetadata.getColumnName();
DataType dataType = columnMetadata.getDataType();
FieldType fieldType = columnMetadata.getFieldType();
FieldSpec fieldSpec = null;
switch(fieldType) {
case DIMENSION:
boolean isSingleValue = columnMetadata.isSingleValue();
fieldSpec = new DimensionFieldSpec(columnName, dataType, isSingleValue);
break;
case METRIC:
fieldSpec = new MetricFieldSpec(columnName, dataType);
break;
case TIME:
TimeUnit timeType = columnMetadata.getTimeUnit();
TimeGranularitySpec incomingGranularitySpec = new TimeGranularitySpec(dataType, timeType, columnName);
fieldSpec = new TimeFieldSpec(incomingGranularitySpec);
break;
default:
break;
}
schema.addField(fieldSpec);
}
return schema;
}
use of com.linkedin.pinot.common.data.TimeFieldSpec in project pinot by linkedin.
the class SegmentGeneratorConfig method loadConfigFiles.
/**
* @deprecated Load outside the class and use the setter for schema setting.
* @throws IOException
*/
@Deprecated
public void loadConfigFiles() throws IOException {
ObjectMapper objectMapper = new ObjectMapper();
Schema schema;
if (_schemaFile != null) {
schema = Schema.fromFile(new File(_schemaFile));
setSchema(schema);
} else if (_format == FileFormat.AVRO) {
schema = AvroUtils.extractSchemaFromAvro(new File(_inputFilePath));
setSchema(schema);
} else {
throw new RuntimeException("Input format " + _format + " requires schema.");
}
setTimeColumnName(schema.getTimeColumnName());
TimeFieldSpec timeFieldSpec = schema.getTimeFieldSpec();
if (timeFieldSpec != null) {
setSegmentTimeUnit(timeFieldSpec.getIncomingGranularitySpec().getTimeType());
} else {
setSegmentTimeUnit(TimeUnit.DAYS);
}
if (_readerConfigFile != null) {
setReaderConfig(objectMapper.readValue(new File(_readerConfigFile), CSVRecordReaderConfig.class));
}
if (_starTreeIndexSpecFile != null) {
setStarTreeIndexSpec(objectMapper.readValue(new File(_starTreeIndexSpecFile), StarTreeIndexSpec.class));
}
}
use of com.linkedin.pinot.common.data.TimeFieldSpec in project pinot by linkedin.
the class SegmentTestUtils method extractSchemaFromAvro.
public static Schema extractSchemaFromAvro(File avroFile, Map<String, FieldType> fieldTypeMap, TimeUnit granularity) throws IOException {
DataFileStream<GenericRecord> dataStream = new DataFileStream<>(new FileInputStream(avroFile), new GenericDatumReader<GenericRecord>());
Schema schema = new Schema();
for (final Field field : dataStream.getSchema().getFields()) {
final String columnName = field.name();
FieldType fieldType = fieldTypeMap.get(columnName);
Preconditions.checkNotNull(fieldType);
switch(fieldType) {
case TIME:
final TimeGranularitySpec gSpec = new TimeGranularitySpec(getColumnType(field), granularity, columnName);
final TimeFieldSpec fSpec = new TimeFieldSpec(gSpec);
schema.addField(fSpec);
continue;
case DIMENSION:
final FieldSpec dimensionFieldSpec = new DimensionFieldSpec(columnName, getColumnType(field), isSingleValueField(field));
schema.addField(dimensionFieldSpec);
continue;
case METRIC:
final FieldSpec metricFieldSpec = new MetricFieldSpec(columnName, getColumnType(field));
schema.addField(metricFieldSpec);
continue;
default:
throw new UnsupportedOperationException("Unsupported field type: " + fieldType);
}
}
dataStream.close();
return schema;
}
use of com.linkedin.pinot.common.data.TimeFieldSpec in project pinot by linkedin.
the class TransformGroupByTest method buildSchema.
/**
* Helper method to build a schema with one string dimension, and one double metric columns.
*/
private static Schema buildSchema() {
Schema schema = new Schema();
DimensionFieldSpec dimensionFieldSpec = new DimensionFieldSpec(DIMENSION_NAME, FieldSpec.DataType.STRING, true);
schema.addField(dimensionFieldSpec);
MetricFieldSpec metricFieldSpec = new MetricFieldSpec(METRIC_NAME, FieldSpec.DataType.DOUBLE);
schema.addField(metricFieldSpec);
TimeFieldSpec timeFieldSpec = new TimeFieldSpec(TIME_COLUMN_NAME, FieldSpec.DataType.LONG, TimeUnit.MILLISECONDS);
schema.setTimeFieldSpec(timeFieldSpec);
return schema;
}
use of com.linkedin.pinot.common.data.TimeFieldSpec in project pinot by linkedin.
the class TestOffheapStarTreeBuilder method testRandom.
@Test
public void testRandom() throws Exception {
int ROWS = 100;
int numDimensions = 6;
int numMetrics = 6;
StarTreeBuilderConfig builderConfig = new StarTreeBuilderConfig();
Schema schema = new Schema();
builderConfig.dimensionsSplitOrder = new ArrayList<>();
for (int i = 0; i < numDimensions; i++) {
String dimName = "d" + (i + 1);
DimensionFieldSpec dimensionFieldSpec = new DimensionFieldSpec(dimName, DataType.INT, true);
schema.addField(dimensionFieldSpec);
builderConfig.dimensionsSplitOrder.add(dimName);
}
schema.setTimeFieldSpec(new TimeFieldSpec("daysSinceEpoch", DataType.INT, TimeUnit.DAYS));
for (int i = 0; i < numMetrics; i++) {
String metricName = "n" + (i + 1);
MetricFieldSpec metricFieldSpec = new MetricFieldSpec(metricName, DataType.INT);
schema.addField(metricFieldSpec);
}
builderConfig.maxLeafRecords = 10;
builderConfig.schema = schema;
builderConfig.outDir = new File("/tmp/startree");
OffHeapStarTreeBuilder builder = new OffHeapStarTreeBuilder();
builder.init(builderConfig);
Random r = new Random();
HashMap<String, Object> map = new HashMap<>();
for (int row = 0; row < ROWS; row++) {
for (int i = 0; i < numDimensions; i++) {
String dimName = schema.getDimensionFieldSpecs().get(i).getName();
map.put(dimName, dimName + "-v" + r.nextInt((numDimensions - i + 2)));
}
//time
map.put("daysSinceEpoch", r.nextInt(1000));
for (int i = 0; i < numMetrics; i++) {
String metName = schema.getMetricFieldSpecs().get(i).getName();
map.put(metName, r.nextInt((numDimensions - i + 2)));
}
GenericRow genericRow = new GenericRow();
genericRow.init(map);
builder.append(genericRow);
}
builder.build();
FileUtils.deleteDirectory(builderConfig.outDir);
}
Aggregations