Search in sources :

Example 1 with TimeGranularitySpec

use of org.apache.pinot.spi.data.TimeGranularitySpec in project presto by prestodb.

the class TestPinotColumnMetadata method testTimeFieldInPinotSchemaToPinotColumns.

@Test
public void testTimeFieldInPinotSchemaToPinotColumns() {
    PinotConfig pinotConfig = new PinotConfig();
    pinotConfig.setInferDateTypeInSchema(true);
    pinotConfig.setInferTimestampTypeInSchema(true);
    // Test Date
    Schema testSchema = new Schema.SchemaBuilder().addTime(new TimeGranularitySpec(FieldSpec.DataType.INT, TimeUnit.DAYS, "daysSinceEpoch"), new TimeGranularitySpec(FieldSpec.DataType.INT, TimeUnit.DAYS, "daysSinceEpoch")).build();
    List<PinotColumn> pinotColumns = PinotColumnUtils.getPinotColumnsForPinotSchema(testSchema, pinotConfig.isInferDateTypeInSchema(), pinotConfig.isInferTimestampTypeInSchema());
    PinotColumn column = pinotColumns.get(0);
    assertEquals(column.getName(), "daysSinceEpoch");
    assertEquals(column.getType(), DateType.DATE);
    assertEquals(column.getComment(), FieldSpec.FieldType.TIME.name());
    testSchema = new Schema.SchemaBuilder().addTime(new TimeGranularitySpec(FieldSpec.DataType.LONG, TimeUnit.MILLISECONDS, "millisSinceEpoch"), new TimeGranularitySpec(FieldSpec.DataType.INT, TimeUnit.DAYS, "daysSinceEpoch")).build();
    pinotColumns = PinotColumnUtils.getPinotColumnsForPinotSchema(testSchema, pinotConfig.isInferDateTypeInSchema(), pinotConfig.isInferTimestampTypeInSchema());
    column = pinotColumns.get(0);
    assertEquals(column.getName(), "daysSinceEpoch");
    assertEquals(column.getType(), DateType.DATE);
    assertEquals(column.getComment(), FieldSpec.FieldType.TIME.name());
    // Test Timestamp
    testSchema = new Schema.SchemaBuilder().addTime(new TimeGranularitySpec(FieldSpec.DataType.LONG, TimeUnit.MILLISECONDS, "millisSinceEpoch"), new TimeGranularitySpec(FieldSpec.DataType.LONG, TimeUnit.MILLISECONDS, "millisSinceEpoch")).build();
    pinotColumns = PinotColumnUtils.getPinotColumnsForPinotSchema(testSchema, pinotConfig.isInferDateTypeInSchema(), pinotConfig.isInferTimestampTypeInSchema());
    column = pinotColumns.get(0);
    assertEquals(column.getName(), "millisSinceEpoch");
    assertEquals(column.getType(), TimestampType.TIMESTAMP);
    assertEquals(column.getComment(), FieldSpec.FieldType.TIME.name());
    testSchema = new Schema.SchemaBuilder().addTime(new TimeGranularitySpec(FieldSpec.DataType.INT, TimeUnit.DAYS, "daysSinceEpoch"), new TimeGranularitySpec(FieldSpec.DataType.LONG, TimeUnit.MILLISECONDS, "millisSinceEpoch")).build();
    pinotColumns = PinotColumnUtils.getPinotColumnsForPinotSchema(testSchema, pinotConfig.isInferDateTypeInSchema(), pinotConfig.isInferTimestampTypeInSchema());
    column = pinotColumns.get(0);
    assertEquals(column.getName(), "millisSinceEpoch");
    assertEquals(column.getType(), TimestampType.TIMESTAMP);
    assertEquals(column.getComment(), FieldSpec.FieldType.TIME.name());
    // Test fallback to BIGINT
    testSchema = new Schema.SchemaBuilder().addTime(new TimeGranularitySpec(FieldSpec.DataType.LONG, TimeUnit.SECONDS, "secondsSinceEpoch"), new TimeGranularitySpec(FieldSpec.DataType.LONG, TimeUnit.SECONDS, "secondsSinceEpoch")).build();
    pinotColumns = PinotColumnUtils.getPinotColumnsForPinotSchema(testSchema, pinotConfig.isInferDateTypeInSchema(), pinotConfig.isInferTimestampTypeInSchema());
    column = pinotColumns.get(0);
    assertEquals(column.getName(), "secondsSinceEpoch");
    assertEquals(column.getType(), BIGINT);
    assertEquals(column.getComment(), FieldSpec.FieldType.TIME.name());
    testSchema = new Schema.SchemaBuilder().addTime(new TimeGranularitySpec(FieldSpec.DataType.LONG, TimeUnit.MILLISECONDS, "millisSinceEpoch"), new TimeGranularitySpec(FieldSpec.DataType.LONG, TimeUnit.SECONDS, "secondsSinceEpoch")).build();
    pinotColumns = PinotColumnUtils.getPinotColumnsForPinotSchema(testSchema, pinotConfig.isInferDateTypeInSchema(), pinotConfig.isInferTimestampTypeInSchema());
    column = pinotColumns.get(0);
    assertEquals(column.getName(), "secondsSinceEpoch");
    assertEquals(column.getType(), BIGINT);
    assertEquals(column.getComment(), FieldSpec.FieldType.TIME.name());
    testSchema = new Schema.SchemaBuilder().addTime(new TimeGranularitySpec(FieldSpec.DataType.INT, TimeUnit.DAYS, "daysSinceEpoch"), new TimeGranularitySpec(FieldSpec.DataType.LONG, TimeUnit.SECONDS, "secondsSinceEpoch")).build();
    pinotColumns = PinotColumnUtils.getPinotColumnsForPinotSchema(testSchema, pinotConfig.isInferDateTypeInSchema(), pinotConfig.isInferTimestampTypeInSchema());
    column = pinotColumns.get(0);
    assertEquals(column.getName(), "secondsSinceEpoch");
    assertEquals(column.getType(), BIGINT);
    assertEquals(column.getComment(), FieldSpec.FieldType.TIME.name());
}
Also used : TimeGranularitySpec(org.apache.pinot.spi.data.TimeGranularitySpec) Schema(org.apache.pinot.spi.data.Schema) Test(org.testng.annotations.Test)

Example 2 with TimeGranularitySpec

use of org.apache.pinot.spi.data.TimeGranularitySpec in project presto by prestodb.

the class TestPinotColumnMetadata method testConversionWithoutConfigSwitchOn.

@Test
public void testConversionWithoutConfigSwitchOn() {
    PinotConfig pinotConfig = new PinotConfig();
    pinotConfig.setInferDateTypeInSchema(false);
    pinotConfig.setInferTimestampTypeInSchema(false);
    // Test Date
    Schema testSchema = new Schema.SchemaBuilder().addTime(new TimeGranularitySpec(FieldSpec.DataType.INT, TimeUnit.DAYS, "daysSinceEpoch"), new TimeGranularitySpec(FieldSpec.DataType.INT, TimeUnit.DAYS, "daysSinceEpoch")).build();
    List<PinotColumn> pinotColumns = PinotColumnUtils.getPinotColumnsForPinotSchema(testSchema, pinotConfig.isInferDateTypeInSchema(), pinotConfig.isInferTimestampTypeInSchema());
    PinotColumn column = pinotColumns.get(0);
    assertEquals(column.getName(), "daysSinceEpoch");
    assertEquals(column.getType(), INTEGER);
    assertEquals(column.getComment(), FieldSpec.FieldType.TIME.name());
    testSchema = new Schema.SchemaBuilder().addTime(new TimeGranularitySpec(FieldSpec.DataType.LONG, TimeUnit.MILLISECONDS, "millisSinceEpoch"), new TimeGranularitySpec(FieldSpec.DataType.INT, TimeUnit.DAYS, "daysSinceEpoch")).build();
    pinotColumns = PinotColumnUtils.getPinotColumnsForPinotSchema(testSchema, pinotConfig.isInferDateTypeInSchema(), pinotConfig.isInferTimestampTypeInSchema());
    column = pinotColumns.get(0);
    assertEquals(column.getName(), "daysSinceEpoch");
    assertEquals(column.getType(), INTEGER);
    assertEquals(column.getComment(), FieldSpec.FieldType.TIME.name());
    // Test Timestamp
    testSchema = new Schema.SchemaBuilder().addTime(new TimeGranularitySpec(FieldSpec.DataType.LONG, TimeUnit.MILLISECONDS, "millisSinceEpoch"), new TimeGranularitySpec(FieldSpec.DataType.LONG, TimeUnit.MILLISECONDS, "millisSinceEpoch")).build();
    pinotColumns = PinotColumnUtils.getPinotColumnsForPinotSchema(testSchema, pinotConfig.isInferDateTypeInSchema(), pinotConfig.isInferTimestampTypeInSchema());
    column = pinotColumns.get(0);
    assertEquals(column.getName(), "millisSinceEpoch");
    assertEquals(column.getType(), BIGINT);
    assertEquals(column.getComment(), FieldSpec.FieldType.TIME.name());
    testSchema = new Schema.SchemaBuilder().addTime(new TimeGranularitySpec(FieldSpec.DataType.INT, TimeUnit.DAYS, "daysSinceEpoch"), new TimeGranularitySpec(FieldSpec.DataType.LONG, TimeUnit.MILLISECONDS, "millisSinceEpoch")).build();
    pinotColumns = PinotColumnUtils.getPinotColumnsForPinotSchema(testSchema, pinotConfig.isInferDateTypeInSchema(), pinotConfig.isInferTimestampTypeInSchema());
    column = pinotColumns.get(0);
    assertEquals(column.getName(), "millisSinceEpoch");
    assertEquals(column.getType(), BIGINT);
    assertEquals(column.getComment(), FieldSpec.FieldType.TIME.name());
    // Test fallback to BIGINT
    testSchema = new Schema.SchemaBuilder().addTime(new TimeGranularitySpec(FieldSpec.DataType.LONG, TimeUnit.SECONDS, "secondsSinceEpoch"), new TimeGranularitySpec(FieldSpec.DataType.LONG, TimeUnit.SECONDS, "secondsSinceEpoch")).build();
    pinotColumns = PinotColumnUtils.getPinotColumnsForPinotSchema(testSchema, pinotConfig.isInferDateTypeInSchema(), pinotConfig.isInferTimestampTypeInSchema());
    column = pinotColumns.get(0);
    assertEquals(column.getName(), "secondsSinceEpoch");
    assertEquals(column.getType(), BIGINT);
    assertEquals(column.getComment(), FieldSpec.FieldType.TIME.name());
    testSchema = new Schema.SchemaBuilder().addTime(new TimeGranularitySpec(FieldSpec.DataType.LONG, TimeUnit.MILLISECONDS, "millisSinceEpoch"), new TimeGranularitySpec(FieldSpec.DataType.LONG, TimeUnit.SECONDS, "secondsSinceEpoch")).build();
    pinotColumns = PinotColumnUtils.getPinotColumnsForPinotSchema(testSchema, pinotConfig.isInferDateTypeInSchema(), pinotConfig.isInferTimestampTypeInSchema());
    column = pinotColumns.get(0);
    assertEquals(column.getName(), "secondsSinceEpoch");
    assertEquals(column.getType(), BIGINT);
    assertEquals(column.getComment(), FieldSpec.FieldType.TIME.name());
    testSchema = new Schema.SchemaBuilder().addTime(new TimeGranularitySpec(FieldSpec.DataType.INT, TimeUnit.DAYS, "daysSinceEpoch"), new TimeGranularitySpec(FieldSpec.DataType.LONG, TimeUnit.SECONDS, "secondsSinceEpoch")).build();
    pinotColumns = PinotColumnUtils.getPinotColumnsForPinotSchema(testSchema, pinotConfig.isInferDateTypeInSchema(), pinotConfig.isInferTimestampTypeInSchema());
    column = pinotColumns.get(0);
    assertEquals(column.getName(), "secondsSinceEpoch");
    assertEquals(column.getType(), BIGINT);
    assertEquals(column.getComment(), FieldSpec.FieldType.TIME.name());
}
Also used : TimeGranularitySpec(org.apache.pinot.spi.data.TimeGranularitySpec) Schema(org.apache.pinot.spi.data.Schema) Test(org.testng.annotations.Test)

Example 3 with TimeGranularitySpec

use of org.apache.pinot.spi.data.TimeGranularitySpec in project presto by prestodb.

the class TestPinotColumnMetadata method testParsePinotSchemaToPinotColumns.

@Test
public void testParsePinotSchemaToPinotColumns() {
    PinotConfig pinotConfig = new PinotConfig();
    pinotConfig.setInferDateTypeInSchema(true);
    pinotConfig.setInferTimestampTypeInSchema(true);
    Schema testPinotSchema = new Schema.SchemaBuilder().addSingleValueDimension("singleValueIntDimension", FieldSpec.DataType.INT).addSingleValueDimension("singleValueLongDimension", FieldSpec.DataType.LONG).addSingleValueDimension("singleValueFloatDimension", FieldSpec.DataType.FLOAT).addSingleValueDimension("singleValueDoubleDimension", FieldSpec.DataType.DOUBLE).addSingleValueDimension("singleValueBytesDimension", FieldSpec.DataType.BYTES).addSingleValueDimension("singleValueBooleanDimension", FieldSpec.DataType.BOOLEAN).addSingleValueDimension("singleValueStringDimension", FieldSpec.DataType.STRING).addMultiValueDimension("multiValueIntDimension", FieldSpec.DataType.INT).addMultiValueDimension("multiValueLongDimension", FieldSpec.DataType.LONG).addMultiValueDimension("multiValueFloatDimension", FieldSpec.DataType.FLOAT).addMultiValueDimension("multiValueDoubleDimension", FieldSpec.DataType.DOUBLE).addMultiValueDimension("multiValueBytesDimension", FieldSpec.DataType.BYTES).addMultiValueDimension("multiValueBooleanDimension", FieldSpec.DataType.BOOLEAN).addMultiValueDimension("multiValueStringDimension", FieldSpec.DataType.STRING).addMetric("intMetric", FieldSpec.DataType.INT).addMetric("longMetric", FieldSpec.DataType.LONG).addMetric("floatMetric", FieldSpec.DataType.FLOAT).addMetric("doubleMetric", FieldSpec.DataType.DOUBLE).addMetric("bytesMetric", FieldSpec.DataType.BYTES).addTime(new TimeGranularitySpec(FieldSpec.DataType.INT, TimeUnit.DAYS, "daysSinceEpoch"), new TimeGranularitySpec(FieldSpec.DataType.INT, TimeUnit.DAYS, "daysSinceEpoch")).addDateTime("epochDayDateTime", FieldSpec.DataType.INT, "1:DAYS:EPOCH", "1:DAYS").addDateTime("epochMillisDateTime", FieldSpec.DataType.LONG, "1:MILLISECONDS:EPOCH", "1:SECONDS").addDateTime("epochTenDayDateTime", FieldSpec.DataType.INT, "10:DAYS:EPOCH", "1:DAYS").addDateTime("epochSecondsDateTime", FieldSpec.DataType.LONG, "1:SECONDS:EPOCH", "1:SECONDS").build();
    Map<String, Type> expectedTypeMap = new ImmutableMap.Builder<String, Type>().put("singleValueIntDimension", INTEGER).put("singleValueLongDimension", BIGINT).put("singleValueFloatDimension", DOUBLE).put("singleValueDoubleDimension", DOUBLE).put("singleValueBytesDimension", VARBINARY).put("singleValueBooleanDimension", BOOLEAN).put("singleValueStringDimension", VARCHAR).put("multiValueIntDimension", new ArrayType(INTEGER)).put("multiValueLongDimension", new ArrayType(BIGINT)).put("multiValueFloatDimension", new ArrayType(DOUBLE)).put("multiValueDoubleDimension", new ArrayType(DOUBLE)).put("multiValueBytesDimension", new ArrayType(VARBINARY)).put("multiValueBooleanDimension", new ArrayType(BOOLEAN)).put("multiValueStringDimension", new ArrayType(VARCHAR)).put("intMetric", INTEGER).put("longMetric", BIGINT).put("floatMetric", DOUBLE).put("doubleMetric", DOUBLE).put("bytesMetric", VARBINARY).put("daysSinceEpoch", DateType.DATE).put("epochDayDateTime", DateType.DATE).put("epochMillisDateTime", TimestampType.TIMESTAMP).put("epochTenDayDateTime", INTEGER).put("epochSecondsDateTime", BIGINT).build();
    Map<String, String> expectedComment = new ImmutableMap.Builder<String, String>().put("sd1", FieldSpec.FieldType.DIMENSION.name()).put("singleValueIntDimension", FieldSpec.FieldType.DIMENSION.name()).put("singleValueLongDimension", FieldSpec.FieldType.DIMENSION.name()).put("singleValueFloatDimension", FieldSpec.FieldType.DIMENSION.name()).put("singleValueDoubleDimension", FieldSpec.FieldType.DIMENSION.name()).put("singleValueBytesDimension", FieldSpec.FieldType.DIMENSION.name()).put("singleValueBooleanDimension", FieldSpec.FieldType.DIMENSION.name()).put("singleValueStringDimension", FieldSpec.FieldType.DIMENSION.name()).put("multiValueIntDimension", FieldSpec.FieldType.DIMENSION.name()).put("multiValueLongDimension", FieldSpec.FieldType.DIMENSION.name()).put("multiValueFloatDimension", FieldSpec.FieldType.DIMENSION.name()).put("multiValueDoubleDimension", FieldSpec.FieldType.DIMENSION.name()).put("multiValueBytesDimension", FieldSpec.FieldType.DIMENSION.name()).put("multiValueBooleanDimension", FieldSpec.FieldType.DIMENSION.name()).put("multiValueStringDimension", FieldSpec.FieldType.DIMENSION.name()).put("intMetric", FieldSpec.FieldType.METRIC.name()).put("longMetric", FieldSpec.FieldType.METRIC.name()).put("floatMetric", FieldSpec.FieldType.METRIC.name()).put("doubleMetric", FieldSpec.FieldType.METRIC.name()).put("bytesMetric", FieldSpec.FieldType.METRIC.name()).put("daysSinceEpoch", FieldSpec.FieldType.TIME.name()).put("epochDayDateTime", FieldSpec.FieldType.DATE_TIME.name()).put("epochMillisDateTime", FieldSpec.FieldType.DATE_TIME.name()).put("epochTenDayDateTime", FieldSpec.FieldType.DATE_TIME.name()).put("epochSecondsDateTime", FieldSpec.FieldType.DATE_TIME.name()).build();
    List<PinotColumn> pinotColumns = PinotColumnUtils.getPinotColumnsForPinotSchema(testPinotSchema, pinotConfig.isInferDateTypeInSchema(), pinotConfig.isInferTimestampTypeInSchema());
    for (PinotColumn column : pinotColumns) {
        assertEquals(column.getType(), expectedTypeMap.get(column.getName()), "Failed to compare column type for field - " + column.getName());
        assertEquals(column.getComment(), expectedComment.get(column.getName()), "Failed to compare column comment for field - " + column.getName());
        assertEquals(column.isNullable(), false);
    }
}
Also used : TimeGranularitySpec(org.apache.pinot.spi.data.TimeGranularitySpec) Schema(org.apache.pinot.spi.data.Schema) ImmutableMap(com.google.common.collect.ImmutableMap) ArrayType(com.facebook.presto.common.type.ArrayType) ArrayType(com.facebook.presto.common.type.ArrayType) DateType(com.facebook.presto.common.type.DateType) Type(com.facebook.presto.common.type.Type) TimestampType(com.facebook.presto.common.type.TimestampType) Test(org.testng.annotations.Test)

Example 4 with TimeGranularitySpec

use of org.apache.pinot.spi.data.TimeGranularitySpec in project presto by prestodb.

the class PinotColumnUtils method getPrestoTypeFromPinotType.

public static Type getPrestoTypeFromPinotType(FieldSpec field, boolean inferDateType, boolean inferTimestampType) {
    if (field.isSingleValueField()) {
        switch(field.getFieldType()) {
            case TIME:
                TimeFieldSpec timeFieldSpec = (TimeFieldSpec) field;
                TimeGranularitySpec outSpec = timeFieldSpec.getOutgoingGranularitySpec();
                if (outSpec != null) {
                    if (outSpec.getTimeFormat().equalsIgnoreCase(EPOCH.name())) {
                        if (inferDateType && (DAYS == outSpec.getTimeType()) && (outSpec.getTimeUnitSize() == 1)) {
                            return DateType.DATE;
                        }
                        if (inferTimestampType && (MILLISECONDS == outSpec.getTimeType()) && (outSpec.getTimeUnitSize() == 1)) {
                            return TimestampType.TIMESTAMP;
                        }
                    }
                } else {
                    TimeGranularitySpec inSpec = timeFieldSpec.getIncomingGranularitySpec();
                    if (inferDateType && (DAYS == inSpec.getTimeType()) && (inSpec.getTimeUnitSize() == 1)) {
                        return DateType.DATE;
                    }
                    if (inferTimestampType && (MILLISECONDS == inSpec.getTimeType()) && (inSpec.getTimeUnitSize() == 1)) {
                        return TimestampType.TIMESTAMP;
                    }
                }
                return getPrestoTypeFromPinotType(field.getDataType());
            case DATE_TIME:
                DateTimeFieldSpec dateTimeFieldSpec = (DateTimeFieldSpec) field;
                if (inferDateType && dateTimeFieldSpec.getFormat().equalsIgnoreCase(DAYS_SINCE_EPOCH_TIME_FORMAT)) {
                    return DateType.DATE;
                }
                if (inferTimestampType && dateTimeFieldSpec.getFormat().equalsIgnoreCase(MILLISECONDS_SINCE_EPOCH_TIME_FORMAT)) {
                    return TimestampType.TIMESTAMP;
                }
        }
        return getPrestoTypeFromPinotType(field.getDataType());
    }
    return new ArrayType(getPrestoTypeFromPinotType(field.getDataType()));
}
Also used : ArrayType(com.facebook.presto.common.type.ArrayType) TimeGranularitySpec(org.apache.pinot.spi.data.TimeGranularitySpec) TimeFieldSpec(org.apache.pinot.spi.data.TimeFieldSpec) DateTimeFieldSpec(org.apache.pinot.spi.data.DateTimeFieldSpec) DateTimeFieldSpec(org.apache.pinot.spi.data.DateTimeFieldSpec)

Aggregations

TimeGranularitySpec (org.apache.pinot.spi.data.TimeGranularitySpec)4 Schema (org.apache.pinot.spi.data.Schema)3 Test (org.testng.annotations.Test)3 ArrayType (com.facebook.presto.common.type.ArrayType)2 DateType (com.facebook.presto.common.type.DateType)1 TimestampType (com.facebook.presto.common.type.TimestampType)1 Type (com.facebook.presto.common.type.Type)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 DateTimeFieldSpec (org.apache.pinot.spi.data.DateTimeFieldSpec)1 TimeFieldSpec (org.apache.pinot.spi.data.TimeFieldSpec)1