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; } }
@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); } }
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); } }
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); } }
String mapping = Optional.ofNullable(columnHandle.getMapping()).orElse("0"); Matcher mappingMatcher = MAPPING_PATTERN.matcher(mapping); if (!mappingMatcher.matches()) {
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; } }
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); } }
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); } }
String mapping = Optional.ofNullable(columnHandle.getMapping()).orElse("0"); Matcher mappingMatcher = MAPPING_PATTERN.matcher(mapping); if (!mappingMatcher.matches()) {