Skip to content

Commit 76f6c75

Browse files
author
chengyitian
committed
AJ-655: modify when send event, not serialize decimal scale;
1 parent f75364d commit 76f6c75

File tree

4 files changed

+44
-3
lines changed

4 files changed

+44
-3
lines changed

src/com/xxdb/data/BasicDecimal128.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,30 @@ public void writeScalarToOutputStream(ExtendedDataOutput out) throws IOException
8686
out.writeBigIntArray(newArray, 0, newArray.length);
8787
}
8888

89+
public void writeScalarRawDataToOutputStream(ExtendedDataOutput out) throws IOException {
90+
// not write scale
91+
92+
byte[] newArray = new byte[16];
93+
byte[] originalArray = unscaledValue.toByteArray();
94+
95+
if(originalArray.length == 0 || originalArray.length > 16){
96+
throw new RuntimeException("byte length of Decimal128 "+originalArray.length+" cannot be less than 0 or exceed 16.");
97+
}
98+
99+
if (originalArray[0] >= 0) {
100+
// if first bit is 0, represent non-negative.
101+
System.arraycopy(originalArray, 0, newArray, 16 - originalArray.length, originalArray.length);
102+
} else {
103+
// if first bit is 1, represent negative.
104+
System.arraycopy(originalArray, 0, newArray, 16 - originalArray.length, originalArray.length);
105+
for (int i = 0; i < 16 - originalArray.length; i++) {
106+
newArray[i] = -1;
107+
}
108+
}
109+
110+
out.writeBigIntArray(newArray, 0, newArray.length);
111+
}
112+
89113
public static void reverseByteArray(byte[] array) {
90114
int left = 0;
91115
int right = array.length - 1;

src/com/xxdb/data/BasicDecimal32.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ public void writeScalarToOutputStream(ExtendedDataOutput out) throws IOException
7575
out.writeInt(value_);
7676
}
7777

78+
public void writeScalarRawDataToOutputStream(ExtendedDataOutput out) throws IOException {
79+
// not write scale
80+
out.writeInt(value_);
81+
}
82+
7883
@Override
7984
public DATA_CATEGORY getDataCategory() {
8085
return DATA_CATEGORY.DENARY;

src/com/xxdb/data/BasicDecimal64.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ public void writeScalarToOutputStream(ExtendedDataOutput out) throws IOException
7676
out.writeLong(value_);
7777
}
7878

79+
public void writeScalarRawDataToOutputStream(ExtendedDataOutput out) throws IOException {
80+
// not write scale
81+
out.writeLong(value_);
82+
}
83+
7984
@Override
8085
public DATA_CATEGORY getDataCategory() {
8186
return DATA_CATEGORY.DENARY;

src/com/xxdb/streaming/client/cep/ScalarAttributeSerializer.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.xxdb.streaming.client.cep;
22

3-
import com.xxdb.data.AbstractScalar;
4-
import com.xxdb.data.Entity;
3+
import com.xxdb.data.*;
54
import com.xxdb.io.ExtendedDataOutput;
65
import java.io.IOException;
76

@@ -16,7 +15,15 @@ public ScalarAttributeSerializer(int unitLen) {
1615

1716
@Override
1817
public void serialize(Entity attribute, ExtendedDataOutput out) throws IOException {
19-
((AbstractScalar)attribute).writeScalarToOutputStream(out);
18+
if (attribute.getDataType() == Entity.DATA_TYPE.DT_DECIMAL32)
19+
((BasicDecimal32) attribute).writeScalarRawDataToOutputStream(out);
20+
else if (attribute.getDataType() == Entity.DATA_TYPE.DT_DECIMAL64) {
21+
((BasicDecimal64) attribute).writeScalarRawDataToOutputStream(out);
22+
} else if (attribute.getDataType() == Entity.DATA_TYPE.DT_DECIMAL128) {
23+
((BasicDecimal128) attribute).writeScalarRawDataToOutputStream(out);
24+
} else {
25+
((AbstractScalar)attribute).writeScalarToOutputStream(out);
26+
}
2027
}
2128

2229
}

0 commit comments

Comments
 (0)