Java 类com.facebook.presto.spi.type.TimestampType 实例源码

项目:presto    文件:ShardPredicate.java   
public static JDBCType jdbcType(Type type)
{
    if (type.equals(BooleanType.BOOLEAN)) {
        return JDBCType.BOOLEAN;
    }
    if (type.equals(BigintType.BIGINT) || type.equals(TimestampType.TIMESTAMP)) {
        return JDBCType.BIGINT;
    }
    if (type.equals(DoubleType.DOUBLE)) {
        return JDBCType.DOUBLE;
    }
    if (type.equals(DateType.DATE)) {
        return JDBCType.INTEGER;
    }
    if (type.equals(VarcharType.VARCHAR)) {
        return JDBCType.VARBINARY;
    }
    return null;
}
项目:presto    文件:ShardStats.java   
private static ColumnStats doComputeColumnStats(OrcReader orcReader, long columnId, Type type)
        throws IOException
{
    int columnIndex = columnIndex(orcReader.getColumnNames(), columnId);
    OrcRecordReader reader = orcReader.createRecordReader(ImmutableMap.of(columnIndex, type), OrcPredicate.TRUE, UTC, new AggregatedMemoryContext());

    if (type.equals(BooleanType.BOOLEAN)) {
        return indexBoolean(type, reader, columnIndex, columnId);
    }
    if (type.equals(BigintType.BIGINT) ||
            type.equals(DateType.DATE) ||
            type.equals(TimestampType.TIMESTAMP)) {
        return indexLong(type, reader, columnIndex, columnId);
    }
    if (type.equals(DoubleType.DOUBLE)) {
        return indexDouble(type, reader, columnIndex, columnId);
    }
    if (type.equals(VarcharType.VARCHAR)) {
        return indexString(type, reader, columnIndex, columnId);
    }
    return null;
}
项目:presto    文件:TestDateTimeFunctions.java   
@Test
public void testAddFieldToTimestamp()
{
    assertFunction("date_add('millisecond', 3, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, toTimestamp(TIMESTAMP.plusMillis(3)));
    assertFunction("date_add('second', 3, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, toTimestamp(TIMESTAMP.plusSeconds(3)));
    assertFunction("date_add('minute', 3, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, toTimestamp(TIMESTAMP.plusMinutes(3)));
    assertFunction("date_add('hour', 3, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, toTimestamp(TIMESTAMP.plusHours(3)));
    assertFunction("date_add('day', 3, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, toTimestamp(TIMESTAMP.plusDays(3)));
    assertFunction("date_add('week', 3, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, toTimestamp(TIMESTAMP.plusWeeks(3)));
    assertFunction("date_add('month', 3, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, toTimestamp(TIMESTAMP.plusMonths(3)));
    assertFunction("date_add('quarter', 3, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, toTimestamp(TIMESTAMP.plusMonths(3 * 3)));
    assertFunction("date_add('year', 3, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, toTimestamp(TIMESTAMP.plusYears(3)));

    assertFunction("date_add('millisecond', 3, " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(WEIRD_TIMESTAMP.plusMillis(3)));
    assertFunction("date_add('second', 3, " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(WEIRD_TIMESTAMP.plusSeconds(3)));
    assertFunction("date_add('minute', 3, " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(WEIRD_TIMESTAMP.plusMinutes(3)));
    assertFunction("date_add('hour', 3, " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(WEIRD_TIMESTAMP.plusHours(3)));
    assertFunction("date_add('day', 3, " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(WEIRD_TIMESTAMP.plusDays(3)));
    assertFunction("date_add('week', 3, " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(WEIRD_TIMESTAMP.plusWeeks(3)));
    assertFunction("date_add('month', 3, " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(WEIRD_TIMESTAMP.plusMonths(3)));
    assertFunction("date_add('quarter', 3, " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(WEIRD_TIMESTAMP.plusMonths(3 * 3)));
    assertFunction("date_add('year', 3, " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(WEIRD_TIMESTAMP.plusYears(3)));
}
项目:presto    文件:JdbcRecordCursor.java   
@Override
public long getLong(int field)
{
    checkState(!closed, "cursor is closed");
    try {
        Type type = getType(field);
        if (type.equals(BigintType.BIGINT)) {
            return resultSet.getLong(field + 1);
        }
        if (type.equals(DateType.DATE)) {
            // JDBC returns a date using a timestamp at midnight in the JVM timezone
            long localMillis = resultSet.getDate(field + 1).getTime();
            // Convert it to a midnight in UTC
            long utcMillis = ISOChronology.getInstance().getZone().getMillisKeepLocal(UTC, localMillis);
            // convert to days
            return TimeUnit.MILLISECONDS.toDays(utcMillis);
        }
        if (type.equals(TimeType.TIME)) {
            Time time = resultSet.getTime(field + 1);
            return UTC_CHRONOLOGY.millisOfDay().get(time.getTime());
        }
        if (type.equals(TimestampType.TIMESTAMP)) {
            Timestamp timestamp = resultSet.getTimestamp(field + 1);
            return timestamp.getTime();
        }
        throw new PrestoException(INTERNAL_ERROR, "Unhandled type for long: " + type.getTypeSignature());
    }
    catch (SQLException e) {
        throw handleSqlException(e);
    }
}
项目:presto    文件:TestDateTimeFunctions.java   
@Test
public void testFromUnixTime()
{
    DateTime dateTime = new DateTime(2001, 1, 22, 3, 4, 5, 0, DATE_TIME_ZONE);
    double seconds = dateTime.getMillis() / 1000.0;
    assertFunction("from_unixtime(" + seconds + ")", TimestampType.TIMESTAMP, toTimestamp(dateTime));

    dateTime = new DateTime(2001, 1, 22, 3, 4, 5, 888, DATE_TIME_ZONE);
    seconds = dateTime.getMillis() / 1000.0;
    assertFunction("from_unixtime(" + seconds + ")", TimestampType.TIMESTAMP, toTimestamp(dateTime));
}
项目:presto    文件:TestDateTimeFunctions.java   
@Test
public void testLocale()
{
    Locale locale = Locale.JAPANESE;
    Session localeSession = testSessionBuilder()
            .setTimeZoneKey(TIME_ZONE_KEY)
            .setLocale(locale)
            .build();

    FunctionAssertions localeAssertions = new FunctionAssertions(localeSession);

    String dateTimeLiteral = "TIMESTAMP '2001-01-09 13:04:05.321'";

    localeAssertions.assertFunction("date_format(" + dateTimeLiteral + ", '%a')", VARCHAR, "火");
    localeAssertions.assertFunction("date_format(" + dateTimeLiteral + ", '%W')", VARCHAR, "火曜日");
    localeAssertions.assertFunction("date_format(" + dateTimeLiteral + ", '%p')", VARCHAR, "午後");
    localeAssertions.assertFunction("date_format(" + dateTimeLiteral + ", '%r')", VARCHAR, "01:04:05 午後");
    localeAssertions.assertFunction("date_format(" + dateTimeLiteral + ", '%b')", VARCHAR, "1");
    localeAssertions.assertFunction("date_format(" + dateTimeLiteral + ", '%M')", VARCHAR, "1月");

    localeAssertions.assertFunction("format_datetime(" + dateTimeLiteral + ", 'EEE')", VARCHAR, "火");
    localeAssertions.assertFunction("format_datetime(" + dateTimeLiteral + ", 'EEEE')", VARCHAR, "火曜日");
    localeAssertions.assertFunction("format_datetime(" + dateTimeLiteral + ", 'a')", VARCHAR, "午後");
    localeAssertions.assertFunction("format_datetime(" + dateTimeLiteral + ", 'MMM')", VARCHAR, "1");
    localeAssertions.assertFunction("format_datetime(" + dateTimeLiteral + ", 'MMMM')", VARCHAR, "1月");

    localeAssertions.assertFunction("date_parse('2013-05-17 12:35:10 午後', '%Y-%m-%d %h:%i:%s %p')",
            TimestampType.TIMESTAMP,
            toTimestamp(new DateTime(2013, 5, 17, 12, 35, 10, 0, DATE_TIME_ZONE), localeSession));
    localeAssertions.assertFunction("date_parse('2013-05-17 12:35:10 午前', '%Y-%m-%d %h:%i:%s %p')",
            TimestampType.TIMESTAMP,
            toTimestamp(new DateTime(2013, 5, 17, 0, 35, 10, 0, DATE_TIME_ZONE), localeSession));

    localeAssertions.assertFunction("parse_datetime('2013-05-17 12:35:10 午後', 'yyyy-MM-dd hh:mm:ss a')",
            TIMESTAMP_WITH_TIME_ZONE,
            toTimestampWithTimeZone(new DateTime(2013, 5, 17, 12, 35, 10, 0, DATE_TIME_ZONE)));
    localeAssertions.assertFunction("parse_datetime('2013-05-17 12:35:10 午前', 'yyyy-MM-dd hh:mm:ss aaa')",
            TIMESTAMP_WITH_TIME_ZONE,
            toTimestampWithTimeZone(new DateTime(2013, 5, 17, 0, 35, 10, 0, DATE_TIME_ZONE)));
}
项目:presto    文件:HiveWriteUtils.java   
public static ObjectInspector getRowColumnInspector(Type type)
{
    if (type.equals(BooleanType.BOOLEAN)) {
        return writableBooleanObjectInspector;
    }

    if (type.equals(BigintType.BIGINT)) {
        return writableLongObjectInspector;
    }

    if (type.equals(DoubleType.DOUBLE)) {
        return writableDoubleObjectInspector;
    }

    if (type.equals(VarcharType.VARCHAR)) {
        return writableStringObjectInspector;
    }

    if (type.equals(VarbinaryType.VARBINARY)) {
        return writableBinaryObjectInspector;
    }

    if (type.equals(DateType.DATE)) {
        return writableDateObjectInspector;
    }

    if (type.equals(TimestampType.TIMESTAMP)) {
        return writableTimestampObjectInspector;
    }

    if (isArrayType(type) || isMapType(type) || isRowType(type)) {
        return getJavaObjectInspector(type);
    }

    throw new IllegalArgumentException("unsupported type: " + type);
}
项目:presto    文件:HiveWriteUtils.java   
@Override
public void setField(Block block, int position)
{
    long millisUtc = TimestampType.TIMESTAMP.getLong(block, position);
    value.setTime(millisUtc);
    rowInspector.setStructFieldData(row, field, value);
}
项目:presto    文件:TestTeradataDateFunctions.java   
private void assertTimestamp(String projection, int year, int month, int day, int hour, int minutes, int seconds)
{
    FUNCTION_ASSERTIONS.assertFunction(
            projection,
            TimestampType.TIMESTAMP,
            toTimestamp(new DateTime(year, month, day, hour, minutes, seconds, DATE_TIME_ZONE)));
}
项目:paraflow    文件:MetaDataQuery.java   
private Type getType(String typeName)
{
    log.debug("Get type " + typeName);
    typeName = typeName.toLowerCase();
    // check if type is varchar(xx)
    Pattern vcpattern = Pattern.compile("varchar\\(\\s*(\\d+)\\s*\\)");
    Matcher vcmatcher = vcpattern.matcher(typeName);
    if (vcmatcher.find()) {
        String vlen = vcmatcher.group(1);
        if (!vlen.isEmpty()) {
            return VarcharType.createVarcharType(Integer.parseInt(vlen));
        }
        return UnknownType.UNKNOWN;
    }
    // check if type is char(xx)
    Pattern cpattern = Pattern.compile("char\\(\\s*(\\d+)\\s*\\)");
    Matcher cmatcher = cpattern.matcher(typeName);
    if (cmatcher.find()) {
        String clen = cmatcher.group(1);
        if (!clen.isEmpty()) {
            return CharType.createCharType(Integer.parseInt(clen));
        }
        return UnknownType.UNKNOWN;
    }
    // check if type is decimal(precision, scale)
    Pattern dpattern = Pattern.compile("decimal\\((\\d+)\\s*,?\\s*(\\d*)\\)");
    Matcher dmatcher = dpattern.matcher(typeName);
    if (dmatcher.find()) {
        String dprecision = dmatcher.group(1);
        String dscale = dmatcher.group(2);
        if (dprecision.isEmpty()) {
            return UnknownType.UNKNOWN;
        }
        if (dscale.isEmpty()) {
            return DecimalType.createDecimalType(Integer.parseInt(dprecision));
        }
        return DecimalType.createDecimalType(Integer.parseInt(dprecision), Integer.parseInt(dscale));
    }
    switch (typeName) {
        case "boolean": return BooleanType.BOOLEAN;
        case "tinyint": return TinyintType.TINYINT;
        case "smallint": return SmallintType.SMALLINT;
        case "integer": return IntegerType.INTEGER;
        case "bigint": return BigintType.BIGINT;
        case "real": return RealType.REAL;
        case "double": return DoubleType.DOUBLE;
        case "date": return DateType.DATE;
        case "time": return TimeType.TIME;
        case "timestamp": return TimestampType.TIMESTAMP;
        default: return UnknownType.UNKNOWN;
    }
}
项目:presto    文件:TestDateTimeFunctions.java   
@Test
public void testLocalTimestamp()
{
    functionAssertions.assertFunction("localtimestamp", TimestampType.TIMESTAMP, toTimestamp(session.getStartTime()));
}
项目:presto    文件:TestDateTimeFunctions.java   
@Test
public void testTruncateTimestamp()
{
    DateTime result = TIMESTAMP;
    result = result.withMillisOfSecond(0);
    assertFunction("date_trunc('second', " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, toTimestamp(result));

    result = result.withSecondOfMinute(0);
    assertFunction("date_trunc('minute', " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, toTimestamp(result));

    result = result.withMinuteOfHour(0);
    assertFunction("date_trunc('hour', " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, toTimestamp(result));

    result = result.withHourOfDay(0);
    assertFunction("date_trunc('day', " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, toTimestamp(result));

    result = result.withDayOfMonth(20);
    assertFunction("date_trunc('week', " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, toTimestamp(result));

    result = result.withDayOfMonth(1);
    assertFunction("date_trunc('month', " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, toTimestamp(result));

    result = result.withMonthOfYear(7);
    assertFunction("date_trunc('quarter', " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, toTimestamp(result));

    result = result.withMonthOfYear(1);
    assertFunction("date_trunc('year', " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, toTimestamp(result));

    result = WEIRD_TIMESTAMP;
    result = result.withMillisOfSecond(0);
    assertFunction("date_trunc('second', " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(result));

    result = result.withSecondOfMinute(0);
    assertFunction("date_trunc('minute', " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(result));

    result = result.withMinuteOfHour(0);
    assertFunction("date_trunc('hour', " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(result));

    result = result.withHourOfDay(0);
    assertFunction("date_trunc('day', " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(result));

    result = result.withDayOfMonth(20);
    assertFunction("date_trunc('week', " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(result));

    result = result.withDayOfMonth(1);
    assertFunction("date_trunc('month', " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(result));

    result = result.withMonthOfYear(7);
    assertFunction("date_trunc('quarter', " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(result));

    result = result.withMonthOfYear(1);
    assertFunction("date_trunc('year', " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(result));
}
项目:presto    文件:TestDateTimeFunctions.java   
@Test
public void testDateParse()
{
    assertFunction("date_parse('2013', '%Y')",
            TimestampType.TIMESTAMP,
            toTimestamp(new DateTime(2013, 1, 1, 0, 0, 0, 0, DATE_TIME_ZONE)));
    assertFunction("date_parse('2013-05', '%Y-%m')",
            TimestampType.TIMESTAMP,
            toTimestamp(new DateTime(2013, 5, 1, 0, 0, 0, 0, DATE_TIME_ZONE)));
    assertFunction("date_parse('2013-05-17', '%Y-%m-%d')",
            TimestampType.TIMESTAMP,
            toTimestamp(new DateTime(2013, 5, 17, 0, 0, 0, 0, DATE_TIME_ZONE)));
    assertFunction("date_parse('2013-05-17 12:35:10', '%Y-%m-%d %h:%i:%s')",
            TimestampType.TIMESTAMP,
            toTimestamp(new DateTime(2013, 5, 17, 0, 35, 10, 0, DATE_TIME_ZONE)));
    assertFunction("date_parse('2013-05-17 12:35:10 PM', '%Y-%m-%d %h:%i:%s %p')",
            TimestampType.TIMESTAMP,
            toTimestamp(new DateTime(2013, 5, 17, 12, 35, 10, 0, DATE_TIME_ZONE)));
    assertFunction("date_parse('2013-05-17 12:35:10 AM', '%Y-%m-%d %h:%i:%s %p')",
            TimestampType.TIMESTAMP,
            toTimestamp(new DateTime(2013, 5, 17, 0, 35, 10, 0, DATE_TIME_ZONE)));

    assertFunction("date_parse('2013-05-17 00:35:10', '%Y-%m-%d %H:%i:%s')",
            TimestampType.TIMESTAMP,
            toTimestamp(new DateTime(2013, 5, 17, 0, 35, 10, 0, DATE_TIME_ZONE)));
    assertFunction("date_parse('2013-05-17 23:35:10', '%Y-%m-%d %H:%i:%s')",
            TimestampType.TIMESTAMP,
            toTimestamp(new DateTime(2013, 5, 17, 23, 35, 10, 0, DATE_TIME_ZONE)));
    assertFunction("date_parse('abc 2013-05-17 fff 23:35:10 xyz', 'abc %Y-%m-%d fff %H:%i:%s xyz')",
            TimestampType.TIMESTAMP,
            toTimestamp(new DateTime(2013, 5, 17, 23, 35, 10, 0, DATE_TIME_ZONE)));

    assertFunction("date_parse('2013 14', '%Y %y')",
            TimestampType.TIMESTAMP,
            toTimestamp(new DateTime(2014, 1, 1, 0, 0, 0, 0, DATE_TIME_ZONE)));

    assertFunction("date_parse('1998 53', '%x %v')",
            TimestampType.TIMESTAMP,
            toTimestamp(new DateTime(1998, 12, 28, 0, 0, 0, 0, DATE_TIME_ZONE)));

    assertFunction("date_parse('1.1', '%s.%f')",
            TimestampType.TIMESTAMP,
            toTimestamp(new DateTime(1970, 1, 1, 0, 0, 1, 100, DATE_TIME_ZONE)));
    assertFunction("date_parse('1.01', '%s.%f')",
            TimestampType.TIMESTAMP,
            toTimestamp(new DateTime(1970, 1, 1, 0, 0, 1, 10, DATE_TIME_ZONE)));
    assertFunction("date_parse('1.2006', '%s.%f')",
            TimestampType.TIMESTAMP,
            toTimestamp(new DateTime(1970, 1, 1, 0, 0, 1, 200, DATE_TIME_ZONE)));

    assertFunction("date_parse('0', '%k')",
            TimestampType.TIMESTAMP,
            toTimestamp(new DateTime(1970, 1, 1, 0, 0, 0, 0, DATE_TIME_ZONE)));
}
项目:presto    文件:HiveWriteUtils.java   
public static ObjectInspector getJavaObjectInspector(Type type)
{
    if (type.equals(BooleanType.BOOLEAN)) {
        return javaBooleanObjectInspector;
    }
    else if (type.equals(BigintType.BIGINT)) {
        return javaLongObjectInspector;
    }
    else if (type.equals(DoubleType.DOUBLE)) {
        return javaDoubleObjectInspector;
    }
    else if (type.equals(VarcharType.VARCHAR)) {
        return writableStringObjectInspector;
    }
    else if (type.equals(VarbinaryType.VARBINARY)) {
        return javaByteArrayObjectInspector;
    }
    else if (type.equals(DateType.DATE)) {
        return javaDateObjectInspector;
    }
    else if (type.equals(TimestampType.TIMESTAMP)) {
        return javaTimestampObjectInspector;
    }
    else if (isArrayType(type)) {
        return ObjectInspectorFactory.getStandardListObjectInspector(getJavaObjectInspector(type.getTypeParameters().get(0)));
    }
    else if (isMapType(type)) {
        ObjectInspector keyObjectInspector = getJavaObjectInspector(type.getTypeParameters().get(0));
        ObjectInspector valueObjectInspector = getJavaObjectInspector(type.getTypeParameters().get(1));
        return ObjectInspectorFactory.getStandardMapObjectInspector(keyObjectInspector, valueObjectInspector);
    }
    else if (isRowType(type)) {
        return ObjectInspectorFactory.getStandardStructObjectInspector(
                type.getTypeSignature().getParameters().stream()
                        .map(parameter -> parameter.getNamedTypeSignature().getName())
                        .collect(toList()),
                type.getTypeParameters().stream()
                        .map(HiveWriteUtils::getJavaObjectInspector)
                        .collect(toList()));
    }
    throw new IllegalArgumentException("unsupported type: " + type);
}
项目:presto    文件:HiveWriteUtils.java   
public static FieldSetter createFieldSetter(SettableStructObjectInspector rowInspector, Object row, StructField field, Type type)
{
    if (type.equals(BooleanType.BOOLEAN)) {
        return new BooleanFieldSetter(rowInspector, row, field);
    }

    if (type.equals(BigintType.BIGINT)) {
        return new BigintFieldBuilder(rowInspector, row, field);
    }

    if (type.equals(DoubleType.DOUBLE)) {
        return new DoubleFieldSetter(rowInspector, row, field);
    }

    if (type.equals(VarcharType.VARCHAR)) {
        return new VarcharFieldSetter(rowInspector, row, field);
    }

    if (type.equals(VarbinaryType.VARBINARY)) {
        return new BinaryFieldSetter(rowInspector, row, field);
    }

    if (type.equals(DateType.DATE)) {
        return new DateFieldSetter(rowInspector, row, field);
    }

    if (type.equals(TimestampType.TIMESTAMP)) {
        return new TimestampFieldSetter(rowInspector, row, field);
    }

    if (isArrayType(type)) {
        return new ArrayFieldSetter(rowInspector, row, field, type.getTypeParameters().get(0));
    }

    if (isMapType(type)) {
        return new MapFieldSetter(rowInspector, row, field, type.getTypeParameters().get(0), type.getTypeParameters().get(1));
    }

    if (isRowType(type)) {
        return new RowFieldSetter(rowInspector, row, field, type.getTypeParameters());
    }

    throw new IllegalArgumentException("unsupported type: " + type);
}
项目:presto    文件:SerDeUtils.java   
private static void serializePrimitive(BlockBuilder builder, Object object, PrimitiveObjectInspector inspector)
{
    requireNonNull(builder, "parent builder is null");

    if (object == null) {
        builder.appendNull();
        return;
    }

    switch (inspector.getPrimitiveCategory()) {
        case BOOLEAN:
            BooleanType.BOOLEAN.writeBoolean(builder, ((BooleanObjectInspector) inspector).get(object));
            return;
        case BYTE:
            BigintType.BIGINT.writeLong(builder, ((ByteObjectInspector) inspector).get(object));
            return;
        case SHORT:
            BigintType.BIGINT.writeLong(builder, ((ShortObjectInspector) inspector).get(object));
            return;
        case INT:
            BigintType.BIGINT.writeLong(builder, ((IntObjectInspector) inspector).get(object));
            return;
        case LONG:
            BigintType.BIGINT.writeLong(builder, ((LongObjectInspector) inspector).get(object));
            return;
        case FLOAT:
            DoubleType.DOUBLE.writeDouble(builder, ((FloatObjectInspector) inspector).get(object));
            return;
        case DOUBLE:
            DoubleType.DOUBLE.writeDouble(builder, ((DoubleObjectInspector) inspector).get(object));
            return;
        case STRING:
            VarcharType.VARCHAR.writeSlice(builder, Slices.utf8Slice(((StringObjectInspector) inspector).getPrimitiveJavaObject(object)));
            return;
        case DATE:
            DateType.DATE.writeLong(builder, formatDateAsLong(object, (DateObjectInspector) inspector));
            return;
        case TIMESTAMP:
            TimestampType.TIMESTAMP.writeLong(builder, formatTimestampAsLong(object, (TimestampObjectInspector) inspector));
            return;
        case BINARY:
            VARBINARY.writeSlice(builder, Slices.wrappedBuffer(((BinaryObjectInspector) inspector).getPrimitiveJavaObject(object)));
            return;
    }
    throw new RuntimeException("Unknown primitive type: " + inspector.getPrimitiveCategory());
}
项目:presto    文件:AbstractTestHiveFileFormats.java   
protected void checkCursor(RecordCursor cursor, List<TestColumn> testColumns, int numRows)
        throws IOException
{
    for (int row = 0; row < numRows; row++) {
        assertTrue(cursor.advanceNextPosition());
        for (int i = 0, testColumnsSize = testColumns.size(); i < testColumnsSize; i++) {
            TestColumn testColumn = testColumns.get(i);

            Object fieldFromCursor;
            Type type = HiveType.valueOf(testColumn.getObjectInspector().getTypeName()).getType(TYPE_MANAGER);
            if (cursor.isNull(i)) {
                fieldFromCursor = null;
            }
            else if (BOOLEAN.equals(type)) {
                fieldFromCursor = cursor.getBoolean(i);
            }
            else if (BIGINT.equals(type)) {
                fieldFromCursor = cursor.getLong(i);
            }
            else if (DOUBLE.equals(type)) {
                fieldFromCursor = cursor.getDouble(i);
            }
            else if (VARCHAR.equals(type)) {
                fieldFromCursor = cursor.getSlice(i);
            }
            else if (VARBINARY.equals(type)) {
                fieldFromCursor = cursor.getSlice(i);
            }
            else if (DateType.DATE.equals(type)) {
                fieldFromCursor = cursor.getLong(i);
            }
            else if (TimestampType.TIMESTAMP.equals(type)) {
                fieldFromCursor = cursor.getLong(i);
            }
            else if (isStructuralType(type)) {
                fieldFromCursor = cursor.getObject(i);
            }
            else {
                throw new RuntimeException("unknown type");
            }

            if (fieldFromCursor == null) {
                assertEquals(null, testColumn.getExpectedValue(), String.format("Expected null for column %s", testColumn.getName()));
            }
            else if (testColumn.getObjectInspector().getTypeName().equals("float") ||
                    testColumn.getObjectInspector().getTypeName().equals("double")) {
                assertEquals((double) fieldFromCursor, (double) testColumn.getExpectedValue(), EPSILON);
            }
            else if (testColumn.getObjectInspector().getCategory() == Category.PRIMITIVE) {
                assertEquals(fieldFromCursor, testColumn.getExpectedValue(), String.format("Wrong value for column %s", testColumn.getName()));
            }
            else {
                Block expected = (Block) testColumn.getExpectedValue();
                Block actual = (Block) fieldFromCursor;
                assertBlockEquals(actual, expected, String.format("Wrong value for column %s", testColumn.getName()));
            }
        }
    }
}