AMashenkov commented on code in PR #2595:
URL: https://github.com/apache/ignite-3/pull/2595#discussion_r1334010491
##########
modules/schema/src/main/java/org/apache/ignite/internal/schema/marshaller/MarshallerUtil.java:
##########
@@ -193,4 +130,75 @@ public static int sizeInBytes(BigInteger val) {
public static int sizeInBytes(BigDecimal val) {
return sizeInBytes(val.unscaledValue());
}
+
+ /**
+ * Converts a given {@link Column} into a {@link MarshallerColumn}.
+ */
+ public static MarshallerColumn toMarshallerColumn(Column column) {
+ NativeType columnType = column.type();
+
+ return new MarshallerColumn(
+ column.name(),
+ mode(columnType),
+ column.defaultValueProvider()::get,
+ columnType instanceof DecimalNativeType ? ((DecimalNativeType)
columnType).scale() : 0
+ );
+ }
+
+ /**
+ * Converts an array of {@link Column}s into an array of {@link
MarshallerColumn}s.
+ */
+ public static MarshallerColumn[] toMarshallerColumns(Column[] columns) {
+ var result = new MarshallerColumn[columns.length];
+
+ for (int i = 0; i < columns.length; i++) {
+ result[i] = toMarshallerColumn(columns[i]);
+ }
+
+ return result;
+ }
+
+ /**
+ * Converts a given {@link NativeType} into a {@link BinaryMode}.
+ */
+ private static BinaryMode mode(NativeType type) {
+ switch (type.spec()) {
+ case INT8:
+ return BinaryMode.BYTE;
+ case INT16:
+ return BinaryMode.SHORT;
+ case INT32:
+ return BinaryMode.INT;
+ case INT64:
+ return BinaryMode.LONG;
+ case FLOAT:
+ return BinaryMode.FLOAT;
+ case DOUBLE:
+ return BinaryMode.DOUBLE;
+ case DECIMAL:
+ return BinaryMode.DECIMAL;
+ case UUID:
+ return BinaryMode.UUID;
+ case STRING:
+ return BinaryMode.STRING;
+ case BYTES:
+ return BinaryMode.BYTE_ARR;
+ case BITMASK:
+ return BinaryMode.BITSET;
+ case NUMBER:
+ return BinaryMode.NUMBER;
+ case DATE:
+ return BinaryMode.DATE;
+ case TIME:
+ return BinaryMode.TIME;
+ case DATETIME:
+ return BinaryMode.DATETIME;
+ case TIMESTAMP:
+ return BinaryMode.TIMESTAMP;
+ case BOOLEAN:
+ return BinaryMode.BOOLEAN;
+ default:
+ throw new IllegalArgumentException();
Review Comment:
Let's add meaningful message.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]