private static Object extractSingleValue(JsonNode jsonValue, FieldSpec.DataType dataType) { Preconditions.checkArgument(jsonValue.isValueNode()); switch (dataType) { case INT: return jsonValue.asInt(); case LONG: return jsonValue.asLong(); case FLOAT: return (float) jsonValue.asDouble(); case DOUBLE: return jsonValue.asDouble(); case STRING: return jsonValue.asText(); default: throw new IllegalArgumentException(); } } }
@Override public boolean getBoolean() { if (value.isValueNode()) { return value.asBoolean(); } throw new PrestoException( DECODER_CONVERSION_NOT_SUPPORTED, format("could not parse non-value node as '%s' for column '%s'", columnHandle.getType(), columnHandle.getName())); }
public static boolean hasValueOf(String value, JsonNode jsonNode) { if (jsonNode.isArray()) { Iterator<JsonNode> iterator = jsonNode.elements(); while (iterator.hasNext()) { JsonNode entryJsonNode = iterator.next(); String entry = entryJsonNode.asText(); if (entry.equals(value)) { return true; } } } else if (jsonNode.isValueNode()) { String entry = jsonNode.asText(); if (entry.equals(value)) { return true; } } return false; }
@Deprecated public ToString(com.google.common.base.Optional<JsonNode> option) throws JsonMappingException { JsonNode node = option.or(NullNode.getInstance()); if (node.isTextual()) { this.string = node.textValue(); } else if (node.isValueNode()) { this.string = node.toString(); } else { throw new JsonMappingException(String.format("Arrays and objects are invalid: '%s'", node)); } }
@JsonCreator public ToString(final Optional<JsonNode> option) throws JsonMappingException { final JsonNode node = option.orElse(NullNode.getInstance()); if (node.isTextual()) { this.string = node.textValue(); } else if (node.isValueNode()) { this.string = node.toString(); } else { throw new JsonMappingException(String.format("Arrays and objects are invalid: '%s'", node)); } }
private void addFlattened(Message message, String currentPath, JsonNode jsonNode) { if (jsonNode.isObject()) { final Iterator<Map.Entry<String, JsonNode>> it = jsonNode.fields(); final String pathPrefix = currentPath.isEmpty() ? "" : currentPath + MAP_KEY_SEPARATOR; while (it.hasNext()) { final Map.Entry<String, JsonNode> entry = it.next(); addFlattened(message, pathPrefix + entry.getKey(), entry.getValue()); } } else if (jsonNode.isArray()) { final List<Object> values = new ArrayList<>(jsonNode.size()); for (int i = 0; i < jsonNode.size(); i++) { final JsonNode currentNode = jsonNode.get(i); if (currentNode.isObject()) { final String pathPrefix = currentPath.isEmpty() ? "" : currentPath + MAP_KEY_SEPARATOR + i; addFlattened(message, pathPrefix, currentNode); } else if (currentNode.isValueNode()) { values.add(valueNode(currentNode)); } } message.addField(currentPath, values); } else if (jsonNode.isValueNode()) { message.addField(currentPath, valueNode(jsonNode)); } }
@Override public Slice getSlice() { String textValue = value.isValueNode() ? value.asText() : value.toString(); Slice slice = utf8Slice(textValue); if (isVarcharType(columnHandle.getType())) { slice = truncateToLength(slice, columnHandle.getType()); } return slice; } }
@Override public double getDouble() { try { if (value.isNumber()) { return value.doubleValue(); } if (value.isValueNode()) { return parseDouble(value.asText()); } } catch (NumberFormatException ignore) { // ignore } throw new PrestoException( DECODER_CONVERSION_NOT_SUPPORTED, format("could not parse value '%s' as '%s' for column '%s'", value.asText(), columnHandle.getType(), columnHandle.getName())); }
if (timestampNode.isValueNode() && !timestampNode.isNumber()) { log.warn(prefix + "has invalid \"timestamp\": {} (type: {})", timestampNode.asText(), timestampNode.getNodeType().name());
.collect(Collectors.joining(".")); if (obj.has(remainingPath) && !remainingPath.equals(key)) { if (obj.get(remainingPath).isValueNode()) { obj.put(remainingPath, value); return;
@Override protected long getMillis() { if (value.isValueNode()) { 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())); } } throw new PrestoException( DECODER_CONVERSION_NOT_SUPPORTED, format("could not parse non-value node as '%s' for column '%s'", columnHandle.getType(), columnHandle.getName())); } }
@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())); } } }
@Override public long getLong() { try { long longValue; if (value.isIntegralNumber() && !value.isBigInteger()) { longValue = value.longValue(); if (longValue >= minValue && longValue <= maxValue) { return longValue; } } else if (value.isValueNode()) { longValue = parseLong(value.asText()); if (longValue >= minValue && longValue <= maxValue) { return longValue; } } } catch (NumberFormatException ignore) { // ignore } throw new PrestoException( DECODER_CONVERSION_NOT_SUPPORTED, format("could not parse value '%s' as '%s' for column '%s'", value.asText(), columnHandle.getType(), columnHandle.getName())); }
private Object convert(final JsonNode value) { if (value == null || value.isNull()) return null; if (value.isBoolean()) { return value.booleanValue(); } else if (value.isValueNode()) { return value.asText(); } else if (value.isArray()) { return (Iterable) () -> new Iterator() { private Iterator<JsonNode> iterator = value.iterator(); @Override public boolean hasNext() { return iterator.hasNext(); } @Override public Object next() { return convert(iterator.next()); } @Override public void remove() { } }; } else { return new JsonMap(value); } } }
if (objectNode.isValueNode() && StringUtils.isNotEmpty(objectNode.asText())) { try { objectNode = objectMapper.readTree(objectNode.asText());
@Override protected long getMillis() { if (value.isIntegralNumber() && !value.isBigInteger()) { return value.longValue(); } if (value.isValueNode()) { try { return parseLong(value.asText()); } catch (NumberFormatException 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())); } } throw new PrestoException( DECODER_CONVERSION_NOT_SUPPORTED, format("could not parse non-value node as '%s' for column '%s'", columnHandle.getType(), columnHandle.getName())); } }
private void readDataInto(RowMap dest, JsonNode data, boolean isOld) throws IOException { if (!(data instanceof ObjectNode)) { throw new ParseException("`" + (isOld ? "oldData" : "data") + "` cannot be parsed."); } Iterator keys = data.fieldNames(); if (keys != null) { while (keys.hasNext()) { String key = (String) keys.next(); JsonNode value = data.get(key); if (value.isValueNode()) { ValueNode valueNode = (ValueNode) value; if(isOld) { dest.putOldData(key, getValue(valueNode)); } else { dest.putData(key, getValue(valueNode)); } } } } }
@Override protected long getMillis() { try { if (value.isIntegralNumber() && !value.isBigInteger()) { return multiplyExact(value.longValue(), 1000); } if (value.isValueNode()) { return multiplyExact(parseLong(value.asText()), 1000); } throw new PrestoException( DECODER_CONVERSION_NOT_SUPPORTED, format("could not parse non-value node as '%s' for column '%s'", columnHandle.getType(), columnHandle.getName())); } catch (NumberFormatException | ArithmeticException 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())); } } }
if (e.isValueNode()) {
if (!value.isValueNode()) { throw new PrestoException( DECODER_CONVERSION_NOT_SUPPORTED,