@@ -84,7 +84,6 @@ protected TransportRequest transportRequest(LookupFromIndexService.Request reque
8484 request .sessionId ,
8585 shardId ,
8686 request .indexPattern ,
87- request .inputDataType ,
8887 request .inputPage ,
8988 null ,
9089 request .extractFields ,
@@ -149,18 +148,21 @@ public static class Request extends AbstractLookupService.Request {
149148 protected static class TransportRequest extends AbstractLookupService .TransportRequest {
150149 private final List <LookupFromIndexOperator .MatchConfig > matchFields ;
151150
151+ // Right now we assume that the page contains the same number of blocks as matchFields and that the blocks are in the same order
152+ // so we are not passing any explicit channel information for now
153+ // In the future it might be possible to include channel information in the matchFields, or expressions, or both,
154+ // so that the same channel can be reused for multiple match fields or multiple times inside the same expression
152155 TransportRequest (
153156 String sessionId ,
154157 ShardId shardId ,
155158 String indexPattern ,
156- DataType inputDataType ,
157159 Page inputPage ,
158160 Page toRelease ,
159161 List <NamedExpression > extractFields ,
160162 List <LookupFromIndexOperator .MatchConfig > matchFields ,
161163 Source source
162164 ) {
163- super (sessionId , shardId , indexPattern , inputDataType , inputPage , toRelease , extractFields , source );
165+ super (sessionId , shardId , indexPattern , inputPage , toRelease , extractFields , source );
164166 this .matchFields = matchFields ;
165167 }
166168
@@ -177,14 +179,26 @@ static TransportRequest readFrom(StreamInput in, BlockFactory blockFactory) thro
177179 indexPattern = shardId .getIndexName ();
178180 }
179181
180- DataType inputDataType = DataType .fromTypeName (in .readString ());
182+ DataType inputDataType = null ;
183+ if (in .getTransportVersion ().onOrAfter (TransportVersions .ESQL_LOOKUP_JOIN_ON_MANY_FIELDS ) == false ) {
184+ inputDataType = DataType .fromTypeName (in .readString ());
185+ }
186+
181187 Page inputPage ;
182188 try (BlockStreamInput bsi = new BlockStreamInput (in , blockFactory )) {
183189 inputPage = new Page (bsi );
184190 }
185191 PlanStreamInput planIn = new PlanStreamInput (in , in .namedWriteableRegistry (), null );
186192 List <NamedExpression > extractFields = planIn .readNamedWriteableCollectionAsList (NamedExpression .class );
187- String matchField = in .readString ();
193+ List <LookupFromIndexOperator .MatchConfig > matchFields = null ;
194+ if (in .getTransportVersion ().onOrAfter (TransportVersions .ESQL_LOOKUP_JOIN_ON_MANY_FIELDS )) {
195+ matchFields = planIn .readCollectionAsList (LookupFromIndexOperator .MatchConfig ::new );
196+ } else {
197+ String matchField = in .readString ();
198+ // For older versions, we only support a single match field.
199+ matchFields = new ArrayList <>(1 );
200+ matchFields .add (new LookupFromIndexOperator .MatchConfig (new FieldAttribute .FieldName (matchField ), 0 , inputDataType ));
201+ }
188202 var source = Source .EMPTY ;
189203 if (in .getTransportVersion ().onOrAfter (TransportVersions .V_8_17_0 )) {
190204 source = Source .readFrom (planIn );
@@ -195,19 +209,10 @@ static TransportRequest readFrom(StreamInput in, BlockFactory blockFactory) thro
195209 String sourceText = in .readString ();
196210 source = new Source (source .source (), sourceText );
197211 }
198- List <LookupFromIndexOperator .MatchConfig > matchFields = null ;
199- if (in .getTransportVersion ().onOrAfter (TransportVersions .ESQL_LOOKUP_JOIN_ON_MANY_FIELDS )) {
200- matchFields = planIn .readCollectionAsList (LookupFromIndexOperator .MatchConfig ::new );
201- } else {
202- // For older versions, we only support a single match field.
203- matchFields = new ArrayList <>(1 );
204- matchFields .add (new LookupFromIndexOperator .MatchConfig (new FieldAttribute .FieldName (matchField ), 0 , inputDataType ));
205- }
206212 TransportRequest result = new TransportRequest (
207213 sessionId ,
208214 shardId ,
209215 indexPattern ,
210- inputDataType ,
211216 inputPage ,
212217 inputPage ,
213218 extractFields ,
@@ -230,22 +235,31 @@ public void writeTo(StreamOutput out) throws IOException {
230235 } else if (indexPattern .equals (shardId .getIndexName ()) == false ) {
231236 throw new EsqlIllegalArgumentException ("Aliases and index patterns are not allowed for LOOKUP JOIN [{}]" , indexPattern );
232237 }
233- out .writeString (inputDataType .typeName ());
238+ if (out .getTransportVersion ().onOrAfter (TransportVersions .ESQL_LOOKUP_JOIN_ON_MANY_FIELDS ) == false ) {
239+ // only write this for old versions
240+ // older versions only support a single match field
241+ if (matchFields .size () > 1 ) {
242+ throw new EsqlIllegalArgumentException ("LOOKUP JOIN on multiple fields is not supported on remote node" );
243+ }
244+ out .writeString (matchFields .get (0 ).type ().typeName ());
245+ }
234246 out .writeWriteable (inputPage );
235247 PlanStreamOutput planOut = new PlanStreamOutput (out , null );
236248 planOut .writeNamedWriteableCollection (extractFields );
237- out .writeString (matchFields .get (0 ).fieldName ().string ());
249+ if (out .getTransportVersion ().onOrAfter (TransportVersions .ESQL_LOOKUP_JOIN_ON_MANY_FIELDS )) {
250+ // serialize all match fields for new versions
251+ planOut .writeCollection (matchFields , (o , matchConfig ) -> matchConfig .writeTo (o ));
252+ } else {
253+ // older versions only support a single match field, we already checked this above when writing the datatype
254+ // send the field name of the first and only match field here
255+ out .writeString (matchFields .get (0 ).fieldName ().string ());
256+ }
238257 if (out .getTransportVersion ().onOrAfter (TransportVersions .V_8_17_0 )) {
239258 source .writeTo (planOut );
240259 }
241260 if (out .getTransportVersion ().onOrAfter (TransportVersions .ESQL_LOOKUP_JOIN_SOURCE_TEXT )) {
242261 out .writeString (source .text ());
243262 }
244- if (out .getTransportVersion ().onOrAfter (TransportVersions .ESQL_LOOKUP_JOIN_ON_MANY_FIELDS )) {
245- planOut .writeCollection (matchFields , (o , matchConfig ) -> matchConfig .writeTo (o ));
246- } else if (matchFields .size () > 1 ) {
247- throw new EsqlIllegalArgumentException ("LOOKUP JOIN on multiple fields is not supported on remote node" );
248- }
249263 }
250264
251265 @ Override
0 commit comments