Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Flink]fix nested row type convert to serializer loop #3484

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,58 @@ static ValueSetter createValueSetter(DataType elementType) {
}
}

static ValueSetter createValueSetter(DataType elementType, Serializer<?> serializer) {
// ordered by type root definition
switch (elementType.getTypeRoot()) {
case CHAR:
case VARCHAR:
return (writer, pos, value) -> writer.writeString(pos, (BinaryString) value);
case BOOLEAN:
return (writer, pos, value) -> writer.writeBoolean(pos, (boolean) value);
case BINARY:
case VARBINARY:
return (writer, pos, value) -> writer.writeBinary(pos, (byte[]) value);
case DECIMAL:
final int decimalPrecision = getPrecision(elementType);
return (writer, pos, value) ->
writer.writeDecimal(pos, (Decimal) value, decimalPrecision);
case TINYINT:
return (writer, pos, value) -> writer.writeByte(pos, (byte) value);
case SMALLINT:
return (writer, pos, value) -> writer.writeShort(pos, (short) value);
case INTEGER:
case DATE:
case TIME_WITHOUT_TIME_ZONE:
return (writer, pos, value) -> writer.writeInt(pos, (int) value);
case BIGINT:
return (writer, pos, value) -> writer.writeLong(pos, (long) value);
case FLOAT:
return (writer, pos, value) -> writer.writeFloat(pos, (float) value);
case DOUBLE:
return (writer, pos, value) -> writer.writeDouble(pos, (double) value);
case TIMESTAMP_WITHOUT_TIME_ZONE:
case TIMESTAMP_WITH_LOCAL_TIME_ZONE:
final int timestampPrecision = getPrecision(elementType);
return (writer, pos, value) ->
writer.writeTimestamp(pos, (Timestamp) value, timestampPrecision);
case ARRAY:
return (writer, pos, value) ->
writer.writeArray(
pos, (InternalArray) value, (InternalArraySerializer) serializer);
case MULTISET:
case MAP:
return (writer, pos, value) ->
writer.writeMap(
pos, (InternalMap) value, (InternalMapSerializer) serializer);
case ROW:
return (writer, pos, value) ->
writer.writeRow(
pos, (InternalRow) value, (InternalRowSerializer) serializer);
default:
throw new IllegalArgumentException();
}
}

/** Accessor for setting the elements of a binary writer during runtime. */
interface ValueSetter extends Serializable {
void setValue(BinaryWriter writer, int pos, Object value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public InternalRowSerializer(DataType[] types, Serializer<?>[] fieldSerializers)
for (int i = 0; i < types.length; i++) {
DataType type = types[i];
fieldGetters[i] = InternalRow.createFieldGetter(type, i);
valueSetters[i] = BinaryWriter.createValueSetter(type);
valueSetters[i] = BinaryWriter.createValueSetter(type, this);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should be fieldSerializers?

}
}

Expand Down
Loading
Loading