Java Code Examples for com.facebook.presto.spi.type.Type#getTypeSignature()
The following examples show how to use
com.facebook.presto.spi.type.Type#getTypeSignature() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ElasticsearchPageSource.java From presto-connectors with Apache License 2.0 | 6 votes |
private void writeSlice(BlockBuilder output, Type type, Object value) { String base = type.getTypeSignature().getBase(); if (base.equals(StandardTypes.VARCHAR)) { type.writeSlice(output, utf8Slice(toVarcharValue(value))); } else if (type.equals(VARBINARY)) { if (value instanceof byte[]) { type.writeSlice(output, wrappedBuffer(((byte[]) value))); } else { output.appendNull(); } } else { throw new PrestoException(GENERIC_INTERNAL_ERROR, "Unhandled type for Slice: " + type.getTypeSignature()); } }
Example 2
Source File: ElasticsearchPageSource.java From presto-connectors with Apache License 2.0 | 4 votes |
private void appendTo(Type type, Object value, BlockBuilder output) { if (value == null) { output.appendNull(); return; } Class<?> javaType = type.getJavaType(); try { if (javaType == boolean.class) { type.writeBoolean(output, (Boolean) value); } else if (javaType == long.class) { if (type.equals(BIGINT)) { type.writeLong(output, ((Number) value).longValue()); } else if (type.equals(INTEGER)) { type.writeLong(output, ((Number) value).intValue()); } else if (type.equals(DATE)) { long millis = (Long) value; type.writeLong(output, TimeUnit.MILLISECONDS.toDays(millis)); } else if (type.equals(TIME)) { type.writeLong(output, (Long) value); } else if (type.equals(TIMESTAMP)) { type.writeLong(output, (Long) value); } else { throw new PrestoException(GENERIC_INTERNAL_ERROR, "Unhandled type for " + javaType.getSimpleName() + ":" + type.getTypeSignature()); } } else if (javaType == double.class) { type.writeDouble(output, ((Number) value).doubleValue()); } else if (javaType == Slice.class) { writeSlice(output, type, value); } else if (javaType == Block.class) { writeBlock(output, type, value); } else { throw new PrestoException(GENERIC_INTERNAL_ERROR, "Unhandled type for " + javaType.getSimpleName() + ":" + type.getTypeSignature()); } } catch (ClassCastException ignore) { // returns null instead of raising exception output.appendNull(); } }