Skip to content

Commit 00a18d1

Browse files
committed
fixed same type conversion
1 parent 66d47f4 commit 00a18d1

File tree

3 files changed

+37
-10
lines changed

3 files changed

+37
-10
lines changed

client-v2/src/main/java/com/clickhouse/client/api/internal/SerializerUtils.java

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -417,17 +417,41 @@ public static POJOSetter compilePOJOSetter(Method setterMethod, ClickHouseColumn
417417
false);
418418
} else if (!targetPrimitiveType.isPrimitive()) {
419419
// boxing
420+
String sourceInternalClassName;
421+
if (column.getDataType().isSigned()) {
422+
sourceInternalClassName = Type.getInternalName(sourceType);
423+
} else if (column.getDataType() == ClickHouseDataType.UInt64) {
424+
sourceInternalClassName = Type.getInternalName(BigInteger.class);
425+
} else if (column.getDataType() == ClickHouseDataType.Enum8) {
426+
sourceInternalClassName = Type.getInternalName(Byte.class);
427+
} else if (column.getDataType() == ClickHouseDataType.Enum16) {
428+
sourceInternalClassName = Type.getInternalName(Short.class);
429+
} else {
430+
sourceInternalClassName = Type.getInternalName(
431+
ClickHouseDataType.toObjectType(ClickHouseDataType.toWiderPrimitiveType(
432+
ClickHouseDataType.toPrimitiveType(sourceType))));
433+
System.out.println("sourceInternalClassName: " + sourceInternalClassName + " " + column.getColumnName());
434+
}
420435
mv.visitVarInsn(ALOAD, 2); // load object
421-
mv.visitMethodInsn(INVOKEVIRTUAL,
422-
Type.getInternalName(sourceType),
423-
targetPrimitiveType.getSimpleName() + "Value",
424-
"()" + Type.getDescriptor(targetPrimitiveType),
425-
false);
426-
mv.visitMethodInsn(INVOKESTATIC,
427-
Type.getInternalName(targetType),
428-
"valueOf",
429-
"(" + Type.getDescriptor(targetPrimitiveType) + ")" + Type.getDescriptor(targetType),
430-
false);
436+
mv.visitTypeInsn(CHECKCAST, sourceInternalClassName);
437+
try {
438+
if (!targetType.isAssignableFrom(Class.forName(sourceInternalClassName
439+
.replaceAll("/", ".")))) {
440+
mv.visitMethodInsn(INVOKEVIRTUAL,
441+
sourceInternalClassName,
442+
targetPrimitiveType.getSimpleName() + "Value",
443+
"()" + Type.getDescriptor(targetPrimitiveType),
444+
false);
445+
mv.visitMethodInsn(INVOKESTATIC,
446+
Type.getInternalName(targetType),
447+
"valueOf",
448+
"(" + Type.getDescriptor(targetPrimitiveType) + ")" + Type.getDescriptor(targetType),
449+
false);
450+
}
451+
} catch (ClassNotFoundException e) {
452+
throw new ClientException("Cannot find class " + sourceInternalClassName + " to compile deserializer for "
453+
+ column.getColumnName(), e);
454+
}
431455
} else {
432456
throw new ClientException("Unsupported conversion from " + sourceType + " to " + targetType);
433457
}

examples/demo-service/src/main/java/com/clickhouse/demo_service/DatasetController.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ public CalculationResult directDatasetFetchCached(@RequestParam(name = "limit",
193193
for (VirtualDatasetRecord record : result) {
194194
p1Sum += record.getP1();
195195
}
196+
log.info(result.toString());
196197
objectsPool.reset(); // reset pool to for next use
197198
return new CalculationResult(p1Sum);
198199
} catch (Exception e) {

examples/demo-service/src/main/java/com/clickhouse/demo_service/data/VirtualDatasetRecord.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
import lombok.AllArgsConstructor;
44
import lombok.Data;
55
import lombok.NoArgsConstructor;
6+
import lombok.ToString;
67

78
import java.math.BigInteger;
89
import java.util.UUID;
910

1011
@Data
1112
@AllArgsConstructor
1213
@NoArgsConstructor
14+
@ToString
1315
public class VirtualDatasetRecord {
1416

1517
private UUID id;

0 commit comments

Comments
 (0)