Skip to content

Commit

Permalink
feat: json type support (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengjiachun authored Nov 4, 2024
1 parent 8949630 commit b0cfed4
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ingester-protocol/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<artifactId>ingester-protocol</artifactId>

<properties>
<greptimedb.proto.version>0.7.0</greptimedb.proto.version>
<greptimedb.proto.version>0.9.0</greptimedb.proto.version>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public enum DataType {
IntervalDayTime,
IntervalMonthDayNano,
Decimal128,
Json,
;

public boolean isTimestamp() {
Expand Down Expand Up @@ -115,6 +116,8 @@ public Common.ColumnDataType toProtoValue() {
return Common.ColumnDataType.INTERVAL_MONTH_DAY_NANO;
case Decimal128:
return Common.ColumnDataType.DECIMAL128;
case Json:
return Common.ColumnDataType.JSON;
default:
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public static void addValue(
valueBuilder.setBinaryValue(UnsafeByteOperations.unsafeWrap((byte[]) value));
break;
case STRING:
case JSON:
valueBuilder.setStringValue((String) value);
break;
case DATE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,15 @@ public void testWriteSuccess() throws ExecutionException, InterruptedException {
.addField("field24", DataType.IntervalDayTime)
.addField("field25", DataType.IntervalMonthDayNano)
.addField("field26", DataType.Decimal128)
.addField("field27", DataType.Json)
.build();
Table table = Table.from(schema);
long ts = System.currentTimeMillis();

// spotless:off
Object[] row1 = new Object[]{"tag1", ts, 1, 2, 3, 4L, 5, 6, 7, 8L, 0.9F, 0.10D, true, new byte[0], 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23, 24L, new IntervalMonthDayNano(1, 2, 3), BigDecimal.valueOf(123.456)};
Object[] row2 = new Object[]{"tag2", ts, 1, 2, 3, 4L, 5, 6, 7, 8L, 0.9F, 0.10D, true, new byte[0], 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23, 24L, new IntervalMonthDayNano(4, 5, 6), BigDecimal.valueOf(123.456)};
Object[] row3 = new Object[]{"tag3", ts, 1, 2, 3, 4L, 5, 6, 7, 8L, 0.9F, 0.10D, true, new byte[0], 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23, 24L, new IntervalMonthDayNano(7, 8, 9), BigDecimal.valueOf(123.456)};
Object[] row1 = new Object[]{"tag1", ts, 1, 2, 3, 4L, 5, 6, 7, 8L, 0.9F, 0.10D, true, new byte[0], 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23, 24L, new IntervalMonthDayNano(1, 2, 3), BigDecimal.valueOf(123.456), "{\"a\": 1}"};
Object[] row2 = new Object[]{"tag2", ts, 1, 2, 3, 4L, 5, 6, 7, 8L, 0.9F, 0.10D, true, new byte[0], 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23, 24L, new IntervalMonthDayNano(4, 5, 6), BigDecimal.valueOf(123.456), "{\"b\": 2}"};
Object[] row3 = new Object[]{"tag3", ts, 1, 2, 3, 4L, 5, 6, 7, 8L, 0.9F, 0.10D, true, new byte[0], 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23, 24L, new IntervalMonthDayNano(7, 8, 9), BigDecimal.valueOf(123.456), "{\"c\": 3}"};
// spotless:on

table.addRow(row1);
Expand Down

0 comments on commit b0cfed4

Please sign in to comment.