Skip to content

Commit

Permalink
ESQL: Improve some casting code (elastic#109309)
Browse files Browse the repository at this point in the history
If we're going to need it then it should be less ugly.
  • Loading branch information
nik9000 committed Jun 5, 2024
1 parent fbe2b1a commit 32dfd18
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,24 @@ public FieldAttribute(
}

@SuppressWarnings("unchecked")
public <S extends StreamInput & PlanStreamInput> FieldAttribute(StreamInput in) throws IOException {
public FieldAttribute(StreamInput in) throws IOException {
/*
* The funny casting dance with `<S extends...>` and `(S) in` is required
* The funny casting dance with `(StreamInput & PlanStreamInput) in` is required
* because we're in esql-core here and the real PlanStreamInput is in
* esql-proper. And because NamedWriteableRegistry.Entry needs StreamInput,
* not a PlanStreamInput. And we need PlanStreamInput to handle Source
* and NameId. This should become a hard cast when we move everything out
* of esql-core.
*/
this(
Source.readFrom((S) in),
Source.readFrom((StreamInput & PlanStreamInput) in),
in.readOptionalWriteable(FieldAttribute::new),
in.readString(),
DataType.readFrom(in),
in.readNamedWriteable(EsField.class),
in.readOptionalString(),
in.readEnum(Nullability.class),
NameId.readFrom((S) in),
NameId.readFrom((StreamInput & PlanStreamInput) in),
in.readBoolean()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,22 @@ public MetadataAttribute(Source source, String name, DataType dataType, boolean
}

@SuppressWarnings("unchecked")
public <S extends StreamInput & PlanStreamInput> MetadataAttribute(StreamInput in) throws IOException {
public MetadataAttribute(StreamInput in) throws IOException {
/*
* The funny casting dance with `<S extends...>` and `(S) in` is required
* The funny casting dance with `(StreamInput & PlanStreamInput) in` is required
* because we're in esql-core here and the real PlanStreamInput is in
* esql-proper. And because NamedWriteableRegistry.Entry needs StreamInput,
* not a PlanStreamInput. And we need PlanStreamInput to handle Source
* and NameId. This should become a hard cast when we move everything out
* of esql-core.
*/
this(
Source.readFrom((S) in),
Source.readFrom((StreamInput & PlanStreamInput) in),
in.readString(),
DataType.readFrom(in),
in.readOptionalString(),
in.readEnum(Nullability.class),
NameId.readFrom((S) in),
NameId.readFrom((StreamInput & PlanStreamInput) in),
in.readBoolean(),
in.readBoolean()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,22 @@ public ReferenceAttribute(
}

@SuppressWarnings("unchecked")
public <S extends StreamInput & PlanStreamInput> ReferenceAttribute(StreamInput in) throws IOException {
public ReferenceAttribute(StreamInput in) throws IOException {
/*
* The funny casting dance with `<S extends...>` and `(S) in` is required
* The funny casting dance with `(StreamInput & PlanStreamInput) in` is required
* because we're in esql-core here and the real PlanStreamInput is in
* esql-proper. And because NamedWriteableRegistry.Entry needs StreamInput,
* not a PlanStreamInput. And we need PlanStreamInput to handle Source
* and NameId. This should become a hard cast when we move everything out
* of esql-core.
*/
this(
Source.readFrom((S) in),
Source.readFrom((StreamInput & PlanStreamInput) in),
in.readString(),
DataType.readFrom(in),
in.readOptionalString(),
in.readEnum(Nullability.class),
NameId.readFrom((S) in),
NameId.readFrom((StreamInput & PlanStreamInput) in),
in.readBoolean()
);
}
Expand Down

0 comments on commit 32dfd18

Please sign in to comment.