@Override public Object getField(String fieldName) { JsonNode fn = jn.get(fieldName); if (fn.isContainerNode()) { AtomicInteger idx = new AtomicInteger(0); List<Field> fields = Lists.newArrayList(fn.fieldNames()) .stream() .map(f -> new Field(f, idx.getAndIncrement())) .collect(Collectors.toList()); return new GenericJsonRecord(fields, fn); } else if (fn.isBoolean()) { return fn.asBoolean(); } else if (fn.isInt()) { return fn.asInt(); } else if (fn.isFloatingPointNumber()) { return fn.asDouble(); } else if (fn.isDouble()) { return fn.asDouble(); } else { return fn.asText(); } } }
} else if (resultNode.isLong()) { result = resultNode.asLong(); } else if (resultNode.isBigDecimal() || resultNode.isDouble()) { result = resultNode.asDouble(); } else if (resultNode.isTextual()) {
if (valueType == ValueType.BOOLEAN && value.isBoolean()) { return ValueReference.of(value.booleanValue()); } else if (valueType == ValueType.DOUBLE && value.isDouble()) { return ValueReference.of(value.doubleValue()); } else if (valueType == ValueType.FLOAT && value.isFloat()) {
@Override public PathDetail deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { JsonNode pathDetail = jp.readValueAsTree(); if (pathDetail.size() != 3) throw new JsonParseException(jp, "PathDetail array must have exactly 3 entries but was " + pathDetail.size()); JsonNode from = pathDetail.get(0); JsonNode to = pathDetail.get(1); JsonNode val = pathDetail.get(2); PathDetail pd; if (val.isBoolean()) pd = new PathDetail(val.asBoolean()); else if (val.isLong()) pd = new PathDetail(val.asLong()); else if (val.isInt()) pd = new PathDetail(val.asInt()); else if (val.isDouble()) pd = new PathDetail(val.asDouble()); else if (val.isTextual()) pd = new PathDetail(val.asText()); else throw new JsonParseException(jp, "Unsupported type of PathDetail value " + pathDetail.getNodeType().name()); pd.setFirst(from.asInt()); pd.setLast(to.asInt()); return pd; } }
} else if (jsonNode.isDouble() || jsonNode.isFloat()) { if (schema == null || schema.getType().equals(Schema.Type.DOUBLE)) { return jsonNode.asDouble();
} else if (e.isBigDecimal()) { return e.decimalValue(); } else if (e.isDouble()) { return e.doubleValue(); } else if (e.isFloat()) {
private Object parseId(JsonNode node) { if (isNullNodeOrValue(node)) { return null; } if (node.isDouble()) { return node.asDouble(); } if (node.isFloatingPointNumber()) { return node.asDouble(); } if (node.isInt()) { return node.asInt(); } if (node.isLong()) { return node.asLong(); } //TODO(donequis): consider parsing bigints if (node.isIntegralNumber()) { return node.asInt(); } if (node.isTextual()) { return node.asText(); } throw new IllegalArgumentException("Unknown id type"); }
private String getPostgresqlType(JsonNode clazz) { if (clazz.isTextual()) { try { DateTimeUtils.parseDate(clazz.asText()); return "date"; } catch (Exception e) { } try { DateTimeUtils.parseTimestamp(clazz.asText()); return "timestamp"; } catch (Exception e) { } return "text"; } else if (clazz.isFloat() || clazz.isDouble()) { return "float8"; } else if (clazz.isNumber()) { return "int8"; } else if (clazz.isBoolean()) { return "bool"; } else if (clazz.isArray()) { if(clazz.get(0).isObject()){ return "jsonb"; } return getPostgresqlType(clazz.get(0)) + "[]"; } else if (clazz.isObject()) { return "jsonb"; } else { throw new IllegalArgumentException(); } }
} else if (e.isBigDecimal()) { return e.decimalValue(); } else if (e.isDouble()) { return e.doubleValue(); } else if (e.isFloat()) {
@JsonIgnore @Deprecated public boolean isDoubleTo() { return to.isDouble(); }
@JsonIgnore @Deprecated public boolean isDoubleFrom() { return from.isDouble(); }
@Override public Optional<Double> getParameterAsDouble(String key) { JsonNode value = this.config.get(key); if (value != null && value.isDouble()) { return Optional.of(value.asDouble()); } return Optional.empty(); }
private static boolean test(final JsonNode value) { if ((value.isDouble() || value.isFloat()) && Double.isNaN(value.asDouble())) return true; return false; } }
private static boolean test(final JsonNode value) { if ((value.isDouble() || value.isFloat()) && Double.isInfinite(value.asDouble())) return true; return false; } }
private static boolean test(final JsonNode value) { if ((value.isDouble() || value.isFloat()) && Double.isInfinite(value.asDouble())) return true; return false; } }
private static boolean test(final JsonNode value) { if ((value.isDouble() || value.isFloat()) && Double.isNaN(value.asDouble())) return true; return false; } }
@Override public Object parseJsonNode(JsonNode input, Schema schema) { Preconditions.checkState(input.isFloat() || input.isDouble(), "'%s' is not a '%s'", input.asText(), expectedClass().getSimpleName()); return input.decimalValue().floatValue(); } }
@Override public Object parseJsonNode(JsonNode input, Schema schema) { Preconditions.checkState(input.isFloat() || input.isDouble(), "'%s' is not a '%s'", input.asText(), expectedClass().getSimpleName()); return input.decimalValue().doubleValue(); } }
private EdmPrimitiveTypeKind guessPrimitiveTypeKind(final JsonNode node) { return node.isShort() ? EdmPrimitiveTypeKind.Int16 : node.isInt() ? EdmPrimitiveTypeKind.Int32 : node.isLong() ? EdmPrimitiveTypeKind.Int64 : node.isBoolean() ? EdmPrimitiveTypeKind.Boolean : node.isFloat() ? EdmPrimitiveTypeKind.Single : node.isDouble() ? EdmPrimitiveTypeKind.Double : node.isBigDecimal() ? EdmPrimitiveTypeKind.Decimal : EdmPrimitiveTypeKind.String; }
@Test public void testNowFunction() { JsonNode now1 = execute("{}", "now()"); double now2 = System.currentTimeMillis(); long delta = 1000; // milliseconds of wriggle-room assertTrue(now1.isDouble()); assertTrue("now1 (" + now1 + ") << now2 (" + now2 + ")", (now1.asDouble() * 1000) < (now2 + delta)); assertTrue("now1 (" + now1 + ") >> now2 (" + now2 + ")", (now1.asDouble() * 1000) > (now2 - delta)); }