public AvroColumnDecoder(DecoderColumnHandle columnHandle) { try { requireNonNull(columnHandle, "columnHandle is null"); this.columnType = columnHandle.getType(); this.columnMapping = columnHandle.getMapping(); this.columnName = columnHandle.getName(); checkArgument(!columnHandle.isInternal(), "unexpected internal column '%s'", columnName); checkArgument(columnHandle.getFormatHint() == null, "unexpected format hint '%s' defined for column '%s'", columnHandle.getFormatHint(), columnName); checkArgument(columnHandle.getDataFormat() == null, "unexpected data format '%s' defined for column '%s'", columnHandle.getDataFormat(), columnName); checkArgument(columnHandle.getMapping() != null, "mapping not defined for column '%s'", columnName); checkArgument(isSupportedType(columnType), "Unsupported column type '%s' for column '%s'", columnType, columnName); } catch (IllegalArgumentException e) { throw new PrestoException(GENERIC_USER_ERROR, e); } }
public static JsonFieldDecoder throwUnsupportedColumnType(DecoderColumnHandle column) { if (column.getDataFormat() == null) { throw new IllegalArgumentException(format("unsupported column type '%s' for column '%s'", column.getType().getDisplayName(), column.getName())); } throw new IllegalArgumentException(format("unsupported column type '%s' for column '%s' with data format '%s'", column.getType(), column.getName(), column.getDataFormat())); } }
private RedisFieldDecoder<String> chooseFieldDecoder(DecoderColumnHandle column) { checkArgument(!column.isInternal(), "unexpected internal column '%s'", column.getName()); if (column.getDataFormat() == null) { return new HashRedisFieldDecoder(); } if (column.getType().getJavaType() == long.class && "iso8601".equals(column.getDataFormat())) { return new ISO8601HashRedisFieldDecoder(); } throw new IllegalArgumentException(format("unknown data format '%s' for column '%s'", column.getDataFormat(), column.getName())); } }
private JsonFieldDecoder chooseFieldDecoder(DecoderColumnHandle column) { try { requireNonNull(column); checkArgument(!column.isInternal(), "unexpected internal column '%s'", column.getName()); String dataFormat = Optional.ofNullable(column.getDataFormat()).orElse(""); switch (dataFormat) { case "custom-date-time": return new CustomDateTimeJsonFieldDecoder(column); case "iso8601": return new ISO8601JsonFieldDecoder(column); case "seconds-since-epoch": return new SecondsSinceEpochJsonFieldDecoder(column); case "milliseconds-since-epoch": return new MillisecondsSinceEpochJsonFieldDecoder(column); case "rfc2822": return new RFC2822JsonFieldDecoder(column); case "": return new DefaultJsonFieldDecoder(column); default: throw new IllegalArgumentException(format("unknown data format '%s' used for column '%s'", column.getDataFormat(), column.getName())); } } catch (IllegalArgumentException e) { throw new PrestoException(GENERIC_USER_ERROR, e); } }
public RFC2822JsonFieldDecoder(DecoderColumnHandle columnHandle) { this.columnHandle = requireNonNull(columnHandle, "columnHandle is null"); if (!SUPPORTED_TYPES.contains(columnHandle.getType())) { throwUnsupportedColumnType(columnHandle); } }
public CustomDateTimeJsonFieldDecoder(DecoderColumnHandle columnHandle) { this.columnHandle = requireNonNull(columnHandle, "columnHandle is null"); if (!SUPPORTED_TYPES.contains(columnHandle.getType())) { throwUnsupportedColumnType(columnHandle); } checkArgument(columnHandle.getFormatHint() != null, "format hint not defined for column '%s'", columnHandle.getName()); try { formatter = DateTimeFormat.forPattern(columnHandle.getFormatHint()).withLocale(Locale.ENGLISH).withZoneUTC(); } catch (IllegalArgumentException e) { throw new PrestoException( GENERIC_USER_ERROR, format("invalid joda pattern '%s' passed as format hint for column '%s'", columnHandle.getFormatHint(), columnHandle.getName())); } }
if (columnHandle.isInternal()) { RedisInternalFieldDescription fieldDescription = RedisInternalFieldDescription.forColumnName(columnHandle.getName()); switch (fieldDescription) { case KEY_FIELD:
private static JsonNode locateNode(JsonNode tree, DecoderColumnHandle columnHandle) { String mapping = columnHandle.getMapping(); checkState(mapping != null, "No mapping for %s", columnHandle.getName()); JsonNode currentNode = tree; for (String pathElement : Splitter.on('/').omitEmptyStrings().split(mapping)) { if (!currentNode.has(pathElement)) { return MissingNode.getInstance(); } currentNode = currentNode.path(pathElement); } return currentNode; } }
private static Map<DecoderColumnHandle, FieldDecoder<?>> buildMap(List<DecoderColumnHandle> columns) { ImmutableMap.Builder<DecoderColumnHandle, FieldDecoder<?>> map = ImmutableMap.builder(); for (DecoderColumnHandle column : columns) { map.put(column, DECODERS.get(column.getDataFormat())); } return map.build(); }
@Override public Optional<Map<DecoderColumnHandle, FieldValueProvider>> decodeRow(byte[] data, Map<String, String> dataMap) { if (dataMap == null) { return Optional.of(emptyMap()); } Map<DecoderColumnHandle, FieldValueProvider> decodedRow = new HashMap<>(); for (Map.Entry<DecoderColumnHandle, RedisFieldDecoder<String>> entry : fieldDecoders.entrySet()) { DecoderColumnHandle columnHandle = entry.getKey(); String mapping = columnHandle.getMapping(); checkState(mapping != null, "No mapping for column handle %s!", columnHandle); String valueField = dataMap.get(mapping); RedisFieldDecoder<String> decoder = entry.getValue(); decodedRow.put(columnHandle, decoder.decode(valueField, columnHandle)); } return Optional.of(decodedRow); } }
@Override protected long getMillis() { if (!value.isValueNode()) { throw new PrestoException( DECODER_CONVERSION_NOT_SUPPORTED, format("could not parse non-value node as '%s' for column '%s'", columnHandle.getType(), columnHandle.getName())); } try { return formatter.parseMillis(value.asText()); } catch (IllegalArgumentException e) { throw new PrestoException( DECODER_CONVERSION_NOT_SUPPORTED, format("could not parse value '%s' as '%s' for column '%s'", value.asText(), columnHandle.getType(), columnHandle.getName())); } } }
public static JsonFieldDecoder throwUnsupportedColumnType(DecoderColumnHandle column) { if (column.getDataFormat() == null) { throw new IllegalArgumentException(format("unsupported column type '%s' for column '%s'", column.getType().getDisplayName(), column.getName())); } throw new IllegalArgumentException(format("unsupported column type '%s' for column '%s' with data format '%s'", column.getType(), column.getName(), column.getDataFormat())); } }
private JsonFieldDecoder chooseFieldDecoder(DecoderColumnHandle column) { try { requireNonNull(column); checkArgument(!column.isInternal(), "unexpected internal column '%s'", column.getName()); String dataFormat = Optional.ofNullable(column.getDataFormat()).orElse(""); switch (dataFormat) { case "custom-date-time": return new CustomDateTimeJsonFieldDecoder(column); case "iso8601": return new ISO8601JsonFieldDecoder(column); case "seconds-since-epoch": return new SecondsSinceEpochJsonFieldDecoder(column); case "milliseconds-since-epoch": return new MillisecondsSinceEpochJsonFieldDecoder(column); case "rfc2822": return new RFC2822JsonFieldDecoder(column); case "": return new DefaultJsonFieldDecoder(column); default: throw new IllegalArgumentException(format("unknown data format '%s' used for column '%s'", column.getDataFormat(), column.getName())); } } catch (IllegalArgumentException e) { throw new PrestoException(GENERIC_USER_ERROR, e); } }
public DefaultJsonFieldDecoder(DecoderColumnHandle columnHandle) { this.columnHandle = requireNonNull(columnHandle, "columnHandle is null"); if (!isSupportedType(columnHandle.getType())) { JsonRowDecoderFactory.throwUnsupportedColumnType(columnHandle); } if (columnHandle.getType() == TINYINT) { minValue = Byte.MIN_VALUE; maxValue = Byte.MAX_VALUE; } else if (columnHandle.getType() == SMALLINT) { minValue = Short.MIN_VALUE; maxValue = Short.MAX_VALUE; } else if (columnHandle.getType() == INTEGER) { minValue = Integer.MIN_VALUE; maxValue = Integer.MAX_VALUE; } else if (columnHandle.getType() == BIGINT) { minValue = Long.MIN_VALUE; maxValue = Long.MAX_VALUE; } else { // those values will not be used if column type is not one of mentioned above minValue = Long.MAX_VALUE; maxValue = Long.MIN_VALUE; } }
public CustomDateTimeJsonFieldDecoder(DecoderColumnHandle columnHandle) { this.columnHandle = requireNonNull(columnHandle, "columnHandle is null"); if (!SUPPORTED_TYPES.contains(columnHandle.getType())) { throwUnsupportedColumnType(columnHandle); } checkArgument(columnHandle.getFormatHint() != null, "format hint not defined for column '%s'", columnHandle.getName()); try { formatter = DateTimeFormat.forPattern(columnHandle.getFormatHint()).withLocale(Locale.ENGLISH).withZoneUTC(); } catch (IllegalArgumentException e) { throw new PrestoException( GENERIC_USER_ERROR, format("invalid joda pattern '%s' passed as format hint for column '%s'", columnHandle.getFormatHint(), columnHandle.getName())); } }
if (columnHandle.isInternal()) { KafkaInternalFieldDescription fieldDescription = KafkaInternalFieldDescription.forColumnName(columnHandle.getName()); switch (fieldDescription) { case SEGMENT_COUNT_FIELD:
private static JsonNode locateNode(JsonNode tree, DecoderColumnHandle columnHandle) { String mapping = columnHandle.getMapping(); checkState(mapping != null, "No mapping for %s", columnHandle.getName()); JsonNode currentNode = tree; for (String pathElement : Splitter.on('/').omitEmptyStrings().split(mapping)) { if (!currentNode.has(pathElement)) { return MissingNode.getInstance(); } currentNode = currentNode.path(pathElement); } return currentNode; } }
private static Map<DecoderColumnHandle, FieldDecoder<?>> map(List<DecoderColumnHandle> columns) { ImmutableMap.Builder<DecoderColumnHandle, FieldDecoder<?>> map = ImmutableMap.builder(); for (DecoderColumnHandle column : columns) { map.put(column, DECODERS.get(column.getDataFormat())); } return map.build(); }
public CsvColumnDecoder(DecoderColumnHandle columnHandle) { try { requireNonNull(columnHandle, "columnHandle is null"); checkArgument(!columnHandle.isInternal(), "unexpected internal column '%s'", columnHandle.getName()); columnName = columnHandle.getName(); checkArgument(columnHandle.getFormatHint() == null, "unexpected format hint '%s' defined for column '%s'", columnHandle.getFormatHint(), columnName); checkArgument(columnHandle.getDataFormat() == null, "unexpected data format '%s' defined for column '%s'", columnHandle.getDataFormat(), columnName); columnType = columnHandle.getType(); checkArgument(columnHandle.getMapping() != null, "mapping not defined for column '%s'", columnName); try { columnIndex = Integer.parseInt(columnHandle.getMapping()); } catch (NumberFormatException e) { throw new IllegalArgumentException(format("invalid mapping '%s' for column '%s'", columnHandle.getMapping(), columnName)); } checkArgument(columnIndex >= 0, "invalid mapping '%s' for column '%s'", columnHandle.getMapping(), columnName); checkArgument(isSupportedType(columnType), "Unsupported column type '%s' for column '%s'", columnType.getDisplayName(), columnName); } catch (IllegalArgumentException e) { throw new PrestoException(GENERIC_USER_ERROR, e); } }