diff --git a/java/timebase/pub/src/main/java/com/epam/deltix/qsrv/hf/codec/cg/QBFloatType.java b/java/timebase/pub/src/main/java/com/epam/deltix/qsrv/hf/codec/cg/QBFloatType.java index e331eb2b..4cc28427 100644 --- a/java/timebase/pub/src/main/java/com/epam/deltix/qsrv/hf/codec/cg/QBFloatType.java +++ b/java/timebase/pub/src/main/java/com/epam/deltix/qsrv/hf/codec/cg/QBFloatType.java @@ -42,7 +42,7 @@ protected JExpr readIsNullImpl(boolean eq) { else if (javaBaseType == double.class) checkNull = CTXT.staticCall (Double.class, "isNaN", value); else if (javaBaseType == long.class) - checkNull = CTXT.staticCall (Decimal64Utils.class, "isNaN", value); + checkNull = CTXT.staticCall (Decimal64Utils.class, "isNull", value); else if (javaBaseType == Decimal64.class) //checkNull = CTXT.binExpr(CTXT.binExpr(value, " == ", getNullLiteral()), " || ", value.call("isNaN")); checkNull = CTXT.binExpr(value, " == ", getNullLiteral()); @@ -74,12 +74,11 @@ public JExpr getNullLiteral () { else if (javaBaseType == double.class) return (CTXT.staticVarRef (Double.class, "NaN")); else if (javaBaseType == long.class) - return (CTXT.staticVarRef (Decimal64Utils.class, "NaN")); + return (CTXT.staticVarRef (Decimal64Utils.class, "NULL")); else if (javaBaseType == Decimal64.class) return CTXT.nullLiteral(); throw new RuntimeException ("unknown bound type = " + javaBaseType); - } @Override diff --git a/java/timebase/pub/src/main/java/com/epam/deltix/qsrv/hf/pub/codec/intp/DoubleFieldDecoder.java b/java/timebase/pub/src/main/java/com/epam/deltix/qsrv/hf/pub/codec/intp/DoubleFieldDecoder.java index bdba2cc2..1b6b6a43 100644 --- a/java/timebase/pub/src/main/java/com/epam/deltix/qsrv/hf/pub/codec/intp/DoubleFieldDecoder.java +++ b/java/timebase/pub/src/main/java/com/epam/deltix/qsrv/hf/pub/codec/intp/DoubleFieldDecoder.java @@ -89,7 +89,7 @@ final protected void copy (DecodingContext ctxt, Object obj) @Override protected void setNull(Object obj) throws IllegalAccessException, InvocationTargetException { if (fieldType == long.class) { // special case for decimals - setter.setLong(obj, IntegerDataType.INT64_NULL); + setter.setLong(obj, Decimal64Utils.NULL); } else if (fieldType == Decimal64.class) { // special case for decimals setter.set(obj, Decimal64.NULL); } else { diff --git a/java/timebase/test/src/test/java/com/epam/deltix/test/qsrv/hf/pub/Test_RecordCodecDecimals.java b/java/timebase/test/src/test/java/com/epam/deltix/test/qsrv/hf/pub/Test_RecordCodecDecimals.java index d60eb7e9..57607c9a 100644 --- a/java/timebase/test/src/test/java/com/epam/deltix/test/qsrv/hf/pub/Test_RecordCodecDecimals.java +++ b/java/timebase/test/src/test/java/com/epam/deltix/test/qsrv/hf/pub/Test_RecordCodecDecimals.java @@ -30,7 +30,6 @@ import com.epam.deltix.util.memory.MemoryDataOutput; import org.junit.Assert; import org.junit.BeforeClass; -import org.junit.Ignore; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -107,11 +106,16 @@ public void setSize(long value) { public boolean equals(Object obj) { boolean superEquals = super.equals(obj); - if (!superEquals) return false; - if (!(obj instanceof LongPriceTestMessage)) return false; - LongPriceTestMessage other =(LongPriceTestMessage)obj; - if (getPrice() != other.getPrice()) return false; - if (getSize() != other.getSize()) return false; + if (!superEquals) + return false; + if (!(obj instanceof LongPriceTestMessage)) + return false; + + LongPriceTestMessage other = (LongPriceTestMessage)obj; + if (getPrice() != other.getPrice()) + return false; + if (getSize() != other.getSize()) + return false; return true; } @@ -214,7 +218,6 @@ public String toString() { public static class DoublePriceTestMessage extends InstrumentMessage { protected double price = TypeConstants.IEEE64_NULL; - protected double size = TypeConstants.IEEE64_NULL; @SchemaElement(title = "Price") @@ -242,7 +245,6 @@ public double getSize() { public void setSize(double value) { this.size = value; } - public boolean hasSize() { return size != TypeConstants.IEEE64_NULL; } @@ -257,9 +259,18 @@ public boolean equals(Object obj) { if (!superEquals) return false; if (!(obj instanceof DoublePriceTestMessage)) return false; - DoublePriceTestMessage other =(DoublePriceTestMessage)obj; - if (getPrice() != other.getPrice()) return false; - if (getSize() != other.getSize()) return false; + DoublePriceTestMessage other = (DoublePriceTestMessage)obj; + if (hasPrice() && other.hasPrice()) { + if (getPrice() != other.getPrice()) return false; + } else { + if (hasPrice() || other.hasPrice()) return false; + } + + if (hasSize() && other.hasSize()) { + if (getSize() != other.getSize()) return false; + } else { + if (hasSize() || other.hasSize()) return false; + } return true; } @@ -438,12 +449,12 @@ public void test1Int() throws Exception { void testCodecs1() throws Exception { double price = 0.12345; double size = 123.456789; + test2(new LongFlatPriceTestMessage(Decimal64Utils.fromDouble(price), Decimal64Utils.fromDouble(size)), price, size); test2(new LongFlatPriceTestMessage(Decimal64Utils.NaN, Decimal64Utils.NaN), Double.NaN, Double.NaN); } - @Ignore("Fails because of incorrect processing Decimal64Utils.NULL") //TODO: @Test public void testCodecsNulls() throws Exception { @@ -520,8 +531,15 @@ private void test2(LongFlatPriceTestMessage msg, double price, double size) thro DoublePriceTestMessage d = (DoublePriceTestMessage) factory.createFixedBoundDecoder( cd -> DoublePriceTestMessage.class, LONG_RCD).decode(in); - Assert.assertEquals(price, d.getPrice(), 1E-16); - Assert.assertEquals(size, d.getSize(), 1E-16); + if (Double.isNaN(price)) + Assert.assertTrue(Double.isNaN(d.getPrice())); + else + Assert.assertEquals(price, d.getPrice(), 1E-16); + + if (Double.isNaN(size)) + Assert.assertTrue(Double.isNaN(d.getSize())); + else + Assert.assertEquals(size, d.getSize(), 1E-16); } private void test2(double price, double size) throws Exception { diff --git a/java/timebase/test/src/test/java/com/epam/deltix/test/qsrv/hf/tickdb/qql/Test_QqlObjects.java b/java/timebase/test/src/test/java/com/epam/deltix/test/qsrv/hf/tickdb/qql/Test_QqlObjects.java index 29b0888a..8a09e615 100644 --- a/java/timebase/test/src/test/java/com/epam/deltix/test/qsrv/hf/tickdb/qql/Test_QqlObjects.java +++ b/java/timebase/test/src/test/java/com/epam/deltix/test/qsrv/hf/tickdb/qql/Test_QqlObjects.java @@ -1411,7 +1411,7 @@ private static void loadAllData() throws Exception { importStream(db, "KRAKEN", "KRAKEN.30s.qsmsg.gz"); } - private static void importStream(DXTickDB db, String streamKey, String file) throws IOException { + public static void importStream(DXTickDB db, String streamKey, String file) throws IOException { DXTickStream stream = db.getStream(streamKey); if (stream != null) { stream.delete();