Search in sources :

Example 41 with GenericRow

use of com.linkedin.pinot.core.data.GenericRow in project pinot by linkedin.

the class PinotSegmentRecordReaderTest method createTestData.

private List<GenericRow> createTestData() {
    List<GenericRow> rows = new ArrayList<>();
    Random random = new Random();
    Map<String, Object> fields;
    for (int i = 0; i < 10000; i++) {
        fields = new HashMap<>();
        fields.put(D_SV_1, D_SV_1 + "_" + RandomStringUtils.randomAlphabetic(2));
        Object[] d2Array = new Object[5];
        for (int j = 0; j < 5; j++) {
            d2Array[j] = D_MV_1 + "_" + j + "_" + RandomStringUtils.randomAlphabetic(2);
        }
        fields.put(D_MV_1, d2Array);
        fields.put(M1, Math.abs(random.nextInt()));
        fields.put(M2, Math.abs(random.nextFloat()));
        fields.put(TIME, Math.abs(random.nextLong()));
        GenericRow row = new GenericRow();
        row.init(fields);
        rows.add(row);
    }
    return rows;
}
Also used : GenericRow(com.linkedin.pinot.core.data.GenericRow) Random(java.util.Random) ArrayList(java.util.ArrayList)

Example 42 with GenericRow

use of com.linkedin.pinot.core.data.GenericRow in project pinot by linkedin.

the class TestRecordReader method next.

@Override
public GenericRow next() {
    GenericRow row = rows.get(recordNumber);
    recordNumber++;
    return row;
}
Also used : GenericRow(com.linkedin.pinot.core.data.GenericRow)

Example 43 with GenericRow

use of com.linkedin.pinot.core.data.GenericRow in project pinot by linkedin.

the class OffHeapStarTreeBuilder method toGenericRow.

public GenericRow toGenericRow(DimensionBuffer dimensionKey, MetricBuffer metricsHolder) {
    GenericRow row = new GenericRow();
    Map<String, Object> map = new HashMap<>();
    for (int i = 0; i < dimensionNames.size(); i++) {
        String dimName = dimensionNames.get(i);
        BiMap<Integer, Object> inverseDictionary = dictionaryMap.get(dimName).inverse();
        Object dimValue = inverseDictionary.get(dimensionKey.getDimension(i));
        if (dimValue == null) {
            dimValue = dimensionNameToStarValueMap.get(dimName);
        }
        map.put(dimName, dimValue);
    }
    for (int i = 0; i < numMetrics; i++) {
        String metName = metricNames.get(i);
        map.put(metName, metricsHolder.getValueConformToDataType(i));
    }
    row.init(map);
    return row;
}
Also used : GenericRow(com.linkedin.pinot.core.data.GenericRow) HashMap(java.util.HashMap) JSONObject(org.json.JSONObject)

Example 44 with GenericRow

use of com.linkedin.pinot.core.data.GenericRow in project pinot by linkedin.

the class PlainFieldExtractorTest method differentIncomingOutgoingTimeSpecTest.

@Test
public void differentIncomingOutgoingTimeSpecTest() {
    Schema schema = new Schema.SchemaBuilder().setSchemaName("testSchema").addTime("incoming", TimeUnit.DAYS, DataType.INT, "outgoing", TimeUnit.HOURS, DataType.LONG).build();
    PlainFieldExtractor plainFieldExtractor = new PlainFieldExtractor(schema);
    GenericRow row = new GenericRow();
    Map<String, Object> fieldMap = new HashMap<>();
    long currentDaysSinceEpoch = System.currentTimeMillis() / 1000 / 60 / 60 / 24;
    fieldMap.put("incoming", currentDaysSinceEpoch);
    row.init(fieldMap);
    row = plainFieldExtractor.transform(row);
    Assert.assertNull(row.getValue("incoming"));
    Assert.assertTrue(row.getValue("outgoing") instanceof Long);
    Assert.assertEquals(row.getValue("outgoing"), currentDaysSinceEpoch * 24);
}
Also used : GenericRow(com.linkedin.pinot.core.data.GenericRow) HashMap(java.util.HashMap) Schema(com.linkedin.pinot.common.data.Schema) Test(org.testng.annotations.Test)

Example 45 with GenericRow

use of com.linkedin.pinot.core.data.GenericRow in project pinot by linkedin.

the class PlainFieldExtractorTest method simpleTest.

@Test
public void simpleTest() {
    Schema schema = new Schema.SchemaBuilder().setSchemaName("testSchema").addSingleValueDimension("svDimensionInt", DataType.INT).addSingleValueDimension("svDimensionDouble", DataType.DOUBLE).addSingleValueDimension("svClassObject", DataType.STRING).addMultiValueDimension("mvDimensionLong", DataType.LONG).addMultiValueDimension("mvClassObject", DataType.STRING).addMetric("metricInt", DataType.INT).addTime("timeInt", TimeUnit.DAYS, DataType.INT).build();
    PlainFieldExtractor plainFieldExtractor = new PlainFieldExtractor(schema);
    GenericRow row = new GenericRow();
    Map<String, Object> fieldMap = new HashMap<>();
    fieldMap.put("svDimensionInt", (short) 5);
    fieldMap.put("svDimensionDouble", 3.2F);
    fieldMap.put("svClassObject", new AnyClassWithToString());
    fieldMap.put("mvDimensionLong", 13);
    fieldMap.put("mvClassObject", new Object[] { new AnyClassWithToString(), new AnyClassWithToString() });
    fieldMap.put("metricInt", 34.5);
    long currentDaysSinceEpoch = System.currentTimeMillis() / 1000 / 60 / 60 / 24;
    fieldMap.put("timeInt", currentDaysSinceEpoch);
    row.init(fieldMap);
    row = plainFieldExtractor.transform(row);
    Assert.assertTrue(row.getValue("svDimensionInt") instanceof Integer);
    Assert.assertEquals(row.getValue("svDimensionInt"), 5);
    Assert.assertTrue(row.getValue("svDimensionDouble") instanceof Double);
    Assert.assertEquals((double) row.getValue("svDimensionDouble"), 3.2, 0.1);
    Assert.assertTrue(row.getValue("svClassObject") instanceof String);
    Assert.assertEquals(row.getValue("svClassObject"), "AnyClass");
    Assert.assertTrue(row.getValue("mvDimensionLong") instanceof Object[]);
    Assert.assertTrue(((Object[]) row.getValue("mvDimensionLong"))[0] instanceof Long);
    Assert.assertEquals(((Object[]) row.getValue("mvDimensionLong"))[0], 13L);
    Assert.assertTrue(row.getValue("mvClassObject") instanceof Object[]);
    Assert.assertTrue(((Object[]) row.getValue("mvClassObject"))[0] instanceof String);
    Assert.assertTrue(((Object[]) row.getValue("mvClassObject"))[1] instanceof String);
    Assert.assertEquals(((Object[]) row.getValue("mvClassObject"))[0], "AnyClass");
    Assert.assertEquals(((Object[]) row.getValue("mvClassObject"))[1], "AnyClass");
    Assert.assertTrue(row.getValue("metricInt") instanceof Integer);
    Assert.assertEquals(row.getValue("metricInt"), 34);
    Assert.assertTrue(row.getValue("timeInt") instanceof Integer);
    Assert.assertEquals(row.getValue("timeInt"), (int) currentDaysSinceEpoch);
}
Also used : HashMap(java.util.HashMap) Schema(com.linkedin.pinot.common.data.Schema) GenericRow(com.linkedin.pinot.core.data.GenericRow) Test(org.testng.annotations.Test)

Aggregations

GenericRow (com.linkedin.pinot.core.data.GenericRow)45 HashMap (java.util.HashMap)24 File (java.io.File)17 Test (org.testng.annotations.Test)15 Schema (com.linkedin.pinot.common.data.Schema)14 SegmentGeneratorConfig (com.linkedin.pinot.core.indexsegment.generator.SegmentGeneratorConfig)14 ArrayList (java.util.ArrayList)13 SegmentIndexCreationDriverImpl (com.linkedin.pinot.core.segment.creator.impl.SegmentIndexCreationDriverImpl)11 DimensionFieldSpec (com.linkedin.pinot.common.data.DimensionFieldSpec)8 RecordReader (com.linkedin.pinot.core.data.readers.RecordReader)8 Random (java.util.Random)6 JSONObject (org.json.JSONObject)5 FieldSpec (com.linkedin.pinot.common.data.FieldSpec)4 ServerMetrics (com.linkedin.pinot.common.metrics.ServerMetrics)4 MetricFieldSpec (com.linkedin.pinot.common.data.MetricFieldSpec)3 AvroRecordReader (com.linkedin.pinot.core.data.readers.AvroRecordReader)3 PinotSegmentRecordReader (com.linkedin.pinot.core.data.readers.PinotSegmentRecordReader)3 TestRecordReader (com.linkedin.pinot.core.data.readers.TestRecordReader)3 MetricsRegistry (com.yammer.metrics.core.MetricsRegistry)3 BeforeClass (org.testng.annotations.BeforeClass)3