/** * Get a Long field from the JSON. * * @param json JSON document. * @param fieldName Field name to get. * @return Long value of field or null if not present. */ private Long getLongField(JsonNode json, String fieldName) { if (!json.has(fieldName)) { return null; } return json.get(fieldName).longValue(); }
@Override public long getLongValue() throws IOException, JsonParseException { return currentNumericNode().longValue(); }
private long getReplyId(JsonNode replyJson) throws IOException { JsonNode idField = replyJson.get("id"); if (idField == null) { throw new IOException("'id' field is missing in the reply"); } if (!idField.isIntegralNumber()) { throw new IOException( String.format("'id' expected to be long, but it is: '%s'", idField.asText())); } return idField.longValue(); }
for (JsonNode node : tasks) { if (node.get("type").textValue().equals("MAP")) { if (node.get("elapsedTime").longValue() >= maxMapElapsedTime) { maxMapElapsedTime = node.get("elapsedTime").longValue(); maxMapId = node.get("id").textValue(); if (node.get("elapsedTime").longValue() <= minMapElapsedTime) { minMapElapsedTime = node.get("elapsedTime").longValue(); minMapId = node.get("id").textValue(); if (node.get("startTime").longValue() <= firstStartMapTime) { firstStartMapTime = node.get("startTime").longValue(); firstStartMapId = node.get("id").textValue(); if (node.get("startTime").longValue() >= lastStartMapTime) { lastStartMapTime = node.get("startTime").longValue(); lastStartMapId = node.get("id").textValue(); if (node.get("finishTime").longValue() <= firstEndMapTime) { firstEndMapTime = node.get("finishTime").longValue(); firstEndMapId = node.get("id").textValue(); if (node.get("finishTime").longValue() >= lastEndMapTime) { lastEndMapTime = node.get("finishTime").longValue(); lastEndMapId = node.get("id").textValue(); if (node.get("elapsedTime").longValue() >= maxReduceElapsedTime) { maxReduceElapsedTime = node.get("elapsedTime").longValue(); maxReduceId = node.get("id").textValue();
@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())); }
@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())); } }
protected final ObjectNode digestedNumberNode(final JsonNode schema) { final ObjectNode ret = FACTORY.objectNode(); final JsonNode node = schema.get(keyword); final boolean isLong = valueIsLong(node); ret.put("valueIsLong", isLong); if (isLong) { ret.put(keyword, node.canConvertToInt() ? FACTORY.numberNode(node.intValue()) : FACTORY.numberNode(node.longValue())); return ret; } final BigDecimal decimal = node.decimalValue(); ret.put(keyword, decimal.scale() == 0 ? FACTORY.numberNode(decimal.toBigIntegerExact()) : node); return ret; } }
@Override protected final void validateLong(final ProcessingReport report, final MessageBundle bundle, final FullData data) throws ProcessingException { final JsonNode node = data.getInstance().getNode(); final long instanceValue = node.longValue(); final long longValue = number.longValue(); final long remainder = instanceValue % longValue; if (remainder == 0L) return; report.error(newMsg(data, bundle, "err.common.divisor.nonZeroRemainder") .putArgument("value", node).putArgument("divisor", number)); }
@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())); } } }
return (D) Long.valueOf(jsonNode.longValue());
return ValueReference.of(value.longValue()); } else if (valueType == ValueType.STRING && value.isTextual()) { return ValueReference.of(value.textValue());
@Override protected void validateLong(final ProcessingReport report, final MessageBundle bundle, final FullData data) throws ProcessingException { final JsonNode instance = data.getInstance().getNode(); final long instanceValue = instance.longValue(); final long longValue = number.longValue(); if (instanceValue > longValue) return; if (instanceValue < longValue) { report.error(newMsg(data, bundle, "err.common.minimum.tooSmall") .putArgument(keyword, number).putArgument("found", instance)); return; } if (!exclusive) return; report.error(newMsg(data, bundle, "err.common.minimum.notExclusive") .putArgument(keyword, number) .put("exclusiveMinimum", BooleanNode.TRUE)); }
@Override protected void validateLong(final ProcessingReport report, final MessageBundle bundle, final FullData data) throws ProcessingException { final JsonNode instance = data.getInstance().getNode(); final long instanceValue = instance.longValue(); final long longValue = number.longValue(); if (instanceValue < longValue) return; if (instanceValue > longValue) { report.error(newMsg(data, bundle, "err.common.maximum.tooLarge") .putArgument(keyword, number).putArgument("found", instance)); return; } if (!exclusive) return; report.error(newMsg(data, bundle, "err.common.maximum.notExclusive") .putArgument(keyword, number) .put("exclusiveMaximum", BooleanNode.TRUE)); }
return new IntWritable(value.intValue()); case LONG: return (new LongWritable((value.longValue()))); case FLOAT: return (new FloatWritable(value.floatValue()));
if (!n.isNumber()) throw new AvroTypeException("Non-numeric default value for long: "+n); e.writeLong(n.longValue()); break; case FLOAT:
case VALUE_NUMBER_INT: out.writeIndex(JsonType.LONG.ordinal()); out.writeLong(node.longValue()); break; case VALUE_NUMBER_FLOAT:
public static DateTime getEventDateTimeFromJson(final JsonNode node) { final JsonNode eventDateTimeNode = node.get(SMILE_EVENT_DATETIME_TOKEN_NAME); return (eventDateTimeNode == null) ? new DateTime() : new DateTime(eventDateTimeNode.longValue()); }
private Long getLongField(final JsonNode pNode, final String pFieldName) { Preconditions.checkNotNull(pNode); Preconditions.checkNotNull(pFieldName); return (pNode.get(pFieldName) != null && pNode.get(pFieldName).isLong()) ? pNode.get(pFieldName).longValue() : null; }
public long getEventId(ObjectNode eventNode) { JsonNode got = eventNode.get(ReservedFields.EVENT_ID); if (got == null || got.isNull()) { return 0L; } try { return got.longValue(); } catch (Exception ex) { LOG.debug("Failed to get eventId: " + eventNode, ex); return 0L; } }
private Object convertJsonNodeToObject(JsonNode node) { if(node == null) return null; if(node instanceof NullNode) return null; if(node instanceof TextNode) return node.textValue(); if(node instanceof IntNode) return node.intValue(); if(node instanceof LongNode) return node.longValue(); if(node instanceof BooleanNode) return node.booleanValue(); if(node instanceof ArrayNode) return getListFromArrayNode((ArrayNode) node); if(node instanceof ObjectNode) return getMapFromObjectNode((ObjectNode) node); throw new RuntimeException("Unknown node type: " + node.getNodeType()); }